Package org.apache.lucene.search

Examples of org.apache.lucene.search.Hits


        {
            // Create a multi-searcher for looking up the information.
            searcher = new MultiSearcher( searchables );

            // Perform the search.
            Hits hits = null;
            if ( filter != null )
            {
                hits = searcher.search( specificQuery, filter );
            }
            else
            {
                hits = searcher.search( specificQuery );
            }

            int hitCount = hits.length();    
           
            // Now process the limits.
            results.setLimits( limits );
            results.setTotalHits( hitCount );

            int fetchCount = limits.getPageSize();
            int offset = ( limits.getSelectedPage() * limits.getPageSize() );

            if ( limits.getSelectedPage() == SearchResultLimits.ALL_PAGES )
            {
                fetchCount = hitCount;
                offset = 0;
            }

            // Goto offset.
            if ( offset < hitCount )
            {
                // only process if the offset is within the hit count.
                for ( int i = 0; i < fetchCount; i++ )
                {
                    // Stop fetching if we are past the total # of available hits.
                    if ( offset + i >= hitCount )
                    {
                        break;
                    }

                    try
                    {
                        Document doc = hits.doc( offset + i );
                        LuceneRepositoryContentRecord record = converter.convert( doc );
                        results.addHit( record );
                    }
                    catch ( java.text.ParseException e )
                    {
View Full Code Here


                                            (CachingMultiReader) parentReader};
            reader = new CombinedIndexReader(readers);
        }

        IndexSearcher searcher = new IndexSearcher(reader);
        Hits hits;
        if (sortFields.length > 0) {
            hits = searcher.search(query, new Sort(sortFields));
        } else {
            hits = searcher.search(query);
        }
View Full Code Here

   * @return the search results
   */
  private List doSearch(Query query,HitExtractor extractor,Filter filter,Sort sort) {
    Searcher searcher=SearcherFactoryUtils.getSearcher(getSearcherFactory());
    try {
      Hits hits=null;
      if( filter!=null && sort!=null ) {
        hits=searcher.search(query,filter,sort);
      } else if( filter!=null ) {
        hits=searcher.search(query,filter);
      } else if( sort!=null ) {
View Full Code Here

    IndexReader reader=IndexReaderFactoryUtils.getIndexReader(indexFactory);
    IndexSearcher searcher=new IndexSearcher(reader);
    Term identifierTerm=identifier.getIdentifier();
    Document updatedDocument=null;
    try {
      Hits hits=searcher.search(new TermQuery(identifierTerm));
      checkHitsForUpdate(hits);
      updatedDocument=documentModifier.updateDocument(hits.doc(0));
    } catch(IOException ex) {
      throw new LuceneIndexAccessException("Error during updating a document.",ex);
    } finally {
      SearcherFactoryUtils.releaseSearcher(searcher);
      IndexReaderFactoryUtils.releaseIndexReader(indexFactory,reader);
View Full Code Here

    IndexReader reader=IndexReaderFactoryUtils.getIndexReader(indexFactory);
    IndexSearcher searcher=new IndexSearcher(reader);
    Term identifierTerm=identifier.getIdentifier();
    List updatedDocuments=null;
    try {
      Hits hits=searcher.search(new TermQuery(identifierTerm));
      updatedDocuments=documentsModifier.updateDocuments(hits);
    } catch(IOException ex) {
      throw new LuceneIndexAccessException("Error during updating a document.",ex);
    } finally {
      SearcherFactoryUtils.releaseSearcher(searcher);
View Full Code Here

  public Query rewrite(Query query) throws IOException {
    return searcher.rewrite(query);
  }

  public LuceneHits search(Query query) throws IOException {
    Hits hits = searcher.search(query);
    return new SimpleLuceneHits(hits);
  }
View Full Code Here

    Hits hits = searcher.search(query);
    return new SimpleLuceneHits(hits);
  }

  public LuceneHits search(Query query, Filter filter) throws IOException {
    Hits hits = searcher.search(query, filter);
    return new SimpleLuceneHits(hits);
  }
View Full Code Here

  public TopFieldDocs search(Query query, Filter filter, int n, Sort sort) throws IOException {
    return searcher.search(query, filter, n, sort);
  }

  public LuceneHits search(Query query, Filter filter, Sort sort) throws IOException {
    Hits hits = searcher.search(query, filter, sort);
    return new SimpleLuceneHits(hits);
  }
View Full Code Here

  public void search(Query query, HitCollector results) throws IOException {
    searcher.search(query, results);
  }

  public LuceneHits search(Query query, Sort sort) throws IOException {
    Hits hits = searcher.search(query, sort);
    return new SimpleLuceneHits(hits);
  }
View Full Code Here

        QueryParser parser = new QueryParser(FIELD_NAME, analyzer);
        Query query = parser.parse("JF? or Kenned*");
        System.out.println("Searching with primitive query");
        // forget to set this and...
        // query=query.rewrite(reader);
        Hits hits = searcher.search(query);

        // create an instance of the highlighter with the tags used to surround
        // highlighted text
        // QueryHighlightExtractor highlighter = new
        // QueryHighlightExtractor(this,
        // query, new StandardAnalyzer());

        int maxNumFragmentsRequired = 3;

        for (int i = 0; i < hits.length(); i++) {
          String text = hits.doc(i).get(FIELD_NAME);
          TokenStream tokenStream = analyzer.tokenStream(FIELD_NAME, new StringReader(text));
          Highlighter highlighter = getHighlighter(query, FIELD_NAME, tokenStream, HighlighterTest.this, false);

          highlighter.setTextFragmenter(new SimpleFragmenter(40));

View Full Code Here

TOP

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

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.