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: [email protected]
For additional commands, e-mail: [email protected]