FileDocCategorySizeDatePackage
GDataSearchService.javaAPI DocApache Lucene 2.1.04770Wed Feb 14 10:46:06 GMT 2007org.apache.lucene.gdata.server

GDataSearchService

public class GDataSearchService extends GDataService
author
Simon Willnauer

Fields Summary
private static final Log
LOG
private static org.apache.lucene.gdata.search.SearchComponent
SEARCHCOMPONENT
private org.apache.lucene.gdata.search.GDataSearcher
searcher
Constructors Summary
protected GDataSearchService()

        
        if(SEARCHCOMPONENT == null)
            SEARCHCOMPONENT = GDataServerRegistry.getRegistry().lookup(SearchComponent.class,ComponentType.SEARCHCONTROLLER);
        
       
    
Methods Summary
public com.google.gdata.data.BaseFeedgetFeed(GDataRequest request, GDataResponse response)

see
org.apache.lucene.gdata.server.GDataService#getFeed(org.apache.lucene.gdata.server.GDataRequest, org.apache.lucene.gdata.server.GDataResponse)

        String translatedQuery = request.getTranslatedQuery();
        ProvidedService service = request.getConfigurator();
        
        QueryParser parser = new GDataQueryParser(service.getIndexSchema());
        Query query;
        try {
            query = parser.parse(translatedQuery);
           
        } catch (ParseException e1) {
            throw new ServiceException("Search Failed -- Can not parse query",e1,GDataResponse.BAD_REQUEST);
        }
        if(LOG.isInfoEnabled())
            LOG.info("Fire search for user query  query: "+query.toString());
        this.searcher = SEARCHCOMPONENT.getServiceSearcher(service);
        List<String> result;
        try {
            result = this.searcher.search(query,request.getItemsPerPage(),request.getStartIndex(),request.getFeedId());
        } catch (IOException e) {
           throw new ServiceException("Search Failed -- Searcher throws IOException",e,GDataResponse.SERVER_ERROR); 
           
        }
        if(LOG.isInfoEnabled())
            LOG.info("Fetching results for user query result size: "+result.size());
        ServerBaseFeed requestFeed = new ServerBaseFeed();
        requestFeed.setServiceConfig(service);
        requestFeed.setStartIndex(0);
        requestFeed.setItemsPerPage(0);
        requestFeed.setId(request.getFeedId());
        BaseFeed feed = null;
        try{
         feed = this.storage.getFeed(requestFeed);
        }catch (StorageException e) {
            throw new ServiceException("Search Failed -- can not get feed, feed not stored ",e,GDataResponse.NOT_FOUND);
        }
        for (String entryId : result) {
            ServerBaseEntry requestEntry = new ServerBaseEntry();
            requestEntry.setId(entryId);
            requestEntry.setServiceConfig(service);
            try{
            BaseEntry entry = this.storage.getEntry(requestEntry);
            feed.getEntries().add(entry);
            }catch (StorageException e) {
                
                LOG.error("StorageException caught while fetching query results -- skip entry -- "+e.getMessage(),e);
            }
        }
        dynamicElementFeedStragey(feed,request);
        return feed;