c# - Lucene.Net Query with two MUST Clauses Returning Incorrect Results -


i've created query 2 must clauses (and 0 should clauses) returning results satisfy 1 of clauses. far can tell, incorrect behavior.

an example of such query before searching

{+(text:wba) +(attribute:10)} 

the incorrect results being returned have 'wba' term in 'text' field, not have '10' term in 'attribute' field.

when @ index in luke, go search tab, , run search

+text:wba +attribute:10 

i no results, expect.

here's simplified version of code run search:

public static scoredoc[] search( string searchphrase, int maxresults, ienumerable<string> attributes ) {      var topquery = new booleanquery();      var textquery = new booleanquery();     using( var nganalyzer = new ngramanalyzer( version.lucene_30, 3, 9 ) ) {         using( var stanalyzer = new standardanalyzer( version.lucene_30, new hashset<string>() ) ) {              var ngparser = new queryparser( version.lucene_30, indexmanager.textfieldname, nganalyzer );             var stparser = new queryparser( version.lucene_30, indexmanager.textfieldname, stanalyzer );              var terms = autocompleter.querytoterms( searchphrase );              foreach( var word in terms ) {                 if( string.isnullorwhitespace( word ) ) {                     continue;                 }                  if( word.length < 3 ) {                     textquery.add( stparser.parse( word ), occur.must );                 } else {                     var parsed = ngparser.parse( word );                      var extractedterms = new hashset<term>();                     parsed.extractterms( extractedterms );                     foreach( var term in extractedterms ) {                         textquery.add( new termquery( term ), occur.should );                     }                 }             }         }     }     topquery.add( textquery, occur.must );      if( attributes != null && attributes.any() ) {         var attrquery = new booleanquery();         foreach( var attr in attributes ) {             attrquery.add( new termquery( new term( indexmanager.attributefieldname, attr ) ), occur.should );         }         topquery.add( attrquery, occur.must );     }      // conduct search     var searcher = autocompleter.indexmanager.getorcreatesearcher( autocompleter.tableid );      var resultdocs = searcher.search( textquery, maxresults ).scoredocs;      return resultdocs; } 

here's excerpt code produces index:

// add new document var doc = new document(); var field = new field( indexmanager.textfieldname, term.text, field.store.yes, field.index.analyzed ); doc.add( field ); if( !string.isnullorwhitespace( term.id ) ) {     field = new field( indexmanager.idfieldname, term.id, field.store.yes, field.index.no );     doc.add( field ); } foreach( var attr in term.attributes ) {     if( !string.isnullorwhitespace( attr ) ) {         field = new field( indexmanager.attributefieldname, attr, field.store.yes, field.index.not_analyzed );         doc.add( field );     } } writer.adddocument( doc ); 

so, clear, i'm expecting results match text clause inside textquery , @ least 1 of attribute clauses held in attrquery. why isn't working way expect?

this line wrong:

var resultdocs = searcher.search( textquery, maxresults ).scoredocs; 

should be:

var resultdocs = searcher.search( topquery, maxresults ).scoredocs; 

whoops.


Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -