dcsimg
Why does my search code always return me a null field, while the hits.length is a positive integer? I also see the parsed keywords in the index.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

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

Re: Why does my search code always return me a null field, while the hits.length is a positive integer? I also see the parsed keywords in the index.

Posted By:   Otis_Gospodnetic  
Posted On:   Wednesday, June 23, 2004 11:34 PM

The answer is in the Javadoc. Field.Text(String,Reader) does not store the field text in the index.
About | Sitemap | Contact