Posted By:
anurag_chakravarti
Posted On:
Wednesday, June 23, 2004 06:39 AM
Hi, Why does my code always return me a null field, while the hits.length is a positive integer? INDEX CODE FileInputStream is = new FileInputStream( file ); Reader reader = new BufferedReader( new InputStreamReader( is ) ); doc.add( Field.Text( "content", reader ) ); ..... --------------------- SEARCH CODE Query query = QueryParser.parse( searchText, fieldName, analyzer ); Hits hits = searcher.search( query ); System.out.println( hits.length( ) + " total matching documents" ); for( int index = 0; index < hits.length(); index++ ) { System.out.pri
More>>
Hi,
Why does my code always return me a null field, while the hits.length is a positive integer?
INDEX CODE
FileInputStream is = new FileInputStream( file );
Reader reader = new BufferedReader( new InputStreamReader( is ) );
doc.add( Field.Text( "content", reader ) );
.....
---------------------
SEARCH CODE
Query query = QueryParser.parse( searchText, fieldName, analyzer );
Hits hits = searcher.search( query );
System.out.println( hits.length( ) + " total matching documents" );
for( int index = 0; index
< hits.length(); index++ )
{
System.out.println( "In hits" );
Document doc = hits.doc( index );
Field field = doc.getField( "content" );
if( field != null )
{
String summary = fieldName + " " + field.stringValue( );
searchResultVec.add( summary );
} // if
else
{
System.out.println( "NULL" );
} // else
} // for
------------------------
OUTPUT
In hits
NULL
I get the hits.length as some value but the Field returned here is always null. I also see the parsed keyword in _1.tis while leaves me out of anu clues.
I am using the same analyser. I have already spent the entire day and still have no clue as to why this is happening. Any help would be greatly appreciated.
Thanks
-Anurag
<<Less