Package org.apache.lucene.search

Examples of org.apache.lucene.search.IndexSearcher


  }
 
  //*-- return IndexSearcher if zero sub-directories
  if (idirs.size() == 0)
   { Directory directory = FSDirectory.getDirectory( dirs[0], create);
     return( new IndexSearcher(directory) );
   }
 
  //*-- otherwise return MultiSearcher
  IndexSearcher[] searchers = new IndexSearcher[ idirs.size() ];
  for (int i = 0; i < idirs.size(); i++)
  { Directory directory = FSDirectory.getDirectory( idirs.get(i), create);
    searchers[i] = new IndexSearcher(directory);
  }
 
  return (new MultiSearcher(searchers));
}
View Full Code Here


        fIndexer = new Indexer(this, fDirectory);
      else
        fIndexer.initIfNecessary();

      if (fSearcher == null)
        fSearcher = new IndexSearcher(fDirectory);
    } catch (IOException e) {
      Activator.getDefault().getLog().log(Activator.getDefault().createErrorStatus(e.getMessage(), e));
    }
  }
View Full Code Here

    try {
      boolean flushed = fIndexer.flushIfNecessary();

      /* Create searcher if not yet done */
      if (fSearcher == null)
        fSearcher = new IndexSearcher(fDirectory);

      /* Re-Create searcher if no longer current */
      else if (flushed) {
        fSearcher.close();
        fSearcher = new IndexSearcher(fDirectory);
      }
    } catch (IOException e) {
      throw new PersistenceException(e.getMessage(), e);
    }
  }
View Full Code Here

   * @return a List of {@link NewsReference} matching the given search and
   * grouped by {@link IGuid}.
   */
  public Map<IGuid, List<NewsReference>> searchNewsByGuids(List<IGuid> guids, boolean copy, IProgressMonitor monitor) {
    Map<IGuid, List<NewsReference>> linkToRefs = new HashMap<IGuid, List<NewsReference>>(guids.size());
    IndexSearcher currentSearcher = getCurrentSearcher();
    try {
      for (IGuid guid : guids) {

        /* Return early on cancellation */
        if (monitor.isCanceled())
View Full Code Here

   * @return a List of {@link NewsReference} matching the given search and
   * grouped by the {@link URI}.
   */
  public Map<URI, List<NewsReference>> searchNewsByLinks(List<URI> links, boolean copy, IProgressMonitor monitor) {
    Map<URI, List<NewsReference>> linkToRefs = new HashMap<URI, List<NewsReference>>(links.size());
    IndexSearcher currentSearcher = getCurrentSearcher();
    try {
      for (URI link : links) {

        /* Return early on cancellation */
        if (monitor.isCanceled())
View Full Code Here

    return query;
  }

  private List<NewsReference> simpleSearch(BooleanQuery query) {
    /* Make sure the searcher is in sync */
    IndexSearcher currentSearcher = getCurrentSearcher();
    try {
      List<NewsReference> newsRefs = simpleSearch(currentSearcher, query);
      return newsRefs;
    } finally {
      disposeIfNecessary(currentSearcher);
View Full Code Here

    /* Perform the search */
    try {
      Query bQuery = ModelSearchQueries.createQuery(conditions, matchAllConditions);

      /* Make sure the searcher is in sync */
      final IndexSearcher currentSearcher = getCurrentSearcher();
      final List<SearchHit<NewsReference>> resultList = new ArrayList<SearchHit<NewsReference>>();
      final Map<Long, Long> searchResultNewsIds = new HashMap<Long, Long>();

      /* Use custom hit collector for performance reasons */
      HitCollector collector = new HitCollector() {
        @Override
        public void collect(int doc, float score) {
          try {
            Document document = currentSearcher.doc(doc);

            /* Receive Stored Fields */
            long newsId = Long.parseLong(document.get(SearchDocument.ENTITY_ID_TEXT));
            INews.State newsState = NEWS_STATES[Integer.parseInt(document.get(NewsDocument.STATE_ID_TEXT))];

            Map<Integer, INews.State> data = new HashMap<Integer, INews.State>(1);
            data.put(INews.STATE, newsState);

            /*
             * Under some circumstances the index might contain the same news
             * twice. This can happen in situations where RSSOwl is quitting in
             * an emergent way (e.g. the OS shutting down while RSSOwl is
             * running). To avoid issues, we filter out duplicate results from
             * the search. See http://dev.rssowl.org/show_bug.cgi?id=1264
             */
            if (!searchResultNewsIds.containsKey(newsId)) {
              resultList.add(new SearchHit<NewsReference>(new NewsReference(newsId), score, data));
              searchResultNewsIds.put(newsId, newsId);
            }
          } catch (IOException e) {
            Activator.safeLogError(e.getMessage(), e);
          }
        }
      };

      /* Perform the Search */
      try {
        currentSearcher.search(bQuery, collector);
        return resultList;
      } finally {
        disposeIfNecessary(currentSearcher);
      }
    } catch (IOException e) {
View Full Code Here

      throw new PersistenceException(Messages.ModelSearchImpl_ERROR_SEARCH, e);
    }
  }

  private IndexSearcher createIndexSearcher() throws CorruptIndexException, IOException {
    IndexSearcher searcher = new IndexSearcher(IndexReader.open(fDirectory));
    fSearchers.put(searcher, new AtomicInteger(0));
    return searcher;
  }
View Full Code Here

  private IndexSearcher getCurrentSearcher() throws PersistenceException {
    try {
      boolean flushed = fIndexer.flushIfNecessary();

      /* Get the current searcher before acquiring lock in case we block */
      IndexSearcher currentSearcher = fSearcher;

      synchronized (this) {
        /*
         * If there are changes and currentSearcher == fSearcher, it means we
         * won the race for the lock, so we reopen the searcher. If flushed is
         * true, but currentSearcher != fSearcher it means that another thread
         * has reopened the reader while we were blocked waiting for the lock.
         */
        if (flushed && currentSearcher == fSearcher) {
          IndexReader currentReader = fSearcher.getIndexReader();
          IndexReader newReader = currentReader.reopen();
          if (newReader != currentReader) {

            IndexSearcher newSearcher = new IndexSearcher(newReader);
            fSearchers.put(newSearcher, new AtomicInteger(1));

            /*
             * Assign to field before we check the referenceCount to ensure that
             * disposeIfNecessary will dispose the searcher if it has the last
View Full Code Here

   * @see org.rssowl.core.model.search.IModelSearch#clearIndex()
   */
  public void clearIndex() throws PersistenceException {
    try {
      synchronized (this) {
        IndexSearcher currentSearcher = fSearcher;
        fIndexer.clearIndex();
        fSearcher = createIndexSearcher();

        /*
         * We block until the current reader has been closed or can be closed.
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.IndexSearcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.