lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul J. Lucas" <p...@lucasmail.org>
Subject Re: Migrating from Hit/Hits to TopDocs/TopDocCollector
Date Wed, 10 Jun 2009 15:25:41 GMT
On Jun 10, 2009, at 3:17 AM, Uwe Schindler wrote:

> A HitCollector is the correct way to do this (especially because the  
> order of hits is mostly not interesting when retrieving all hits).

OK, here's what I came up with:

     Term t = /* ... */
     Collection<File> files = new LinkedList<File>();
     FieldSelector fieldSelector = new FieldSelector() {
         public FieldSelectorResult accept( String fieldName ) {
             if ( fieldName.equals( "FILE" ) )
                 return FieldSelectorResult.LOAD_AND_BREAK;
             return FieldSelectorResult.NO_LOAD;
         }
     };
     HitCollector hitCollector = new HitCollector() {
         public void collect( int docID, float score ) {
             try {
                 Document doc = searcher.doc( docID, fieldSelector );
                 files.add( new File( doc.get( "FILE" ) ) );
             }
             catch ( Exception e ) {
                 // ignore
             }
         }
     };
     searcher.search( new TermQuery( t ), hitCollector );

How's that?

- Paul

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message