// Build location index
 private com.google.appengine.api.search.Index getLocationIndex() {
   IndexSpec indexSpec =
       IndexSpec.newBuilder()
           .setName(LOCATION_INDEX)
           .setConsistency(Consistency.PER_DOCUMENT)
           .build();
   return SearchServiceFactory.getSearchService().getIndex(indexSpec);
 }
예제 #2
0
  @Override
  public SearchResults call() throws ParseException {
    IndexSearcher searcher = null;
    try {
      boolean debug = log.isDebug();

      if (!searchService.existIndex()) {
        log.warn("Index does not exist, can't search for queryString: " + queryString);
        throw new ServiceNotAvailableException("Index does not exist");
      }

      if (debug) log.debug("queryString=" + queryString);
      searcher = searchService.getIndexSearcher();
      BooleanQuery query = searchService.createQuery(queryString, condQueries);
      if (debug) log.debug("query=" + query);

      long startTime = System.currentTimeMillis();
      int n = SearchServiceFactory.getService().getSearchModuleConfig().getMaxHits();

      TopDocs docs = searcher.search(query, n);
      long queryTime = System.currentTimeMillis() - startTime;
      if (debug) log.debug("hits.length()=" + docs.totalHits);
      SearchResultsImpl searchResult =
          new SearchResultsImpl(
              searchService.getMainIndexer(),
              searcher,
              docs,
              query,
              searchService.getAnalyzer(),
              identity,
              roles,
              firstResult,
              maxResults,
              doHighlighting,
              false);
      searchResult.setQueryTime(queryTime);
      searchResult.setNumberOfIndexDocuments(docs.totalHits);
      if (debug) log.debug("found=" + docs.totalHits);

      return searchResult;
    } catch (ParseException pex) {
      throw pex;
    } catch (Exception naex) {
      log.error("", naex);
      return null;
    } finally {
      searchService.releaseIndexSearcher(searcher);
      DBFactory.getInstance().commitAndCloseSession();
    }
  }
예제 #3
0
 /** Extension point allowing the Index implementation to be modified */
 protected Index getIndex() {
   SearchService searchService = SearchServiceFactory.getSearchService();
   return searchService.getIndex(IndexSpec.newBuilder().setName(indexName));
 }