asp.net - Lucene.net multi field searches -


in attempt more contextually relevant search results i've decided have play lucene.net although i'm new , i've found not intuitive library i've come across. isn't helped lack of relevant examples out there me figure out.

i'm using simple lucene build index , seems working perfectly:

field f = null; document document = new document();  document.add(new field("id", dl.id.tostring(), field.store.yes, field.index.not_analyzed));  f = new field("category", dl.categoryname.tolowerinvariant(), field.store.yes, field.index.analyzed, field.termvector.with_positions_offsets); f.setboost(5); document.add(f);  f = new field("company_name", dl.companyname.tolowerinvariant(), field.store.yes, field.index.analyzed, field.termvector.with_positions_offsets); f.setboost(2); document.add(f);  document.add(new field("description", dl.description.tolowerinvariant(), field.store.yes, field.index.analyzed, field.termvector.with_positions_offsets)); document.add(new field("meta_keywords", dl.meta_keywords.tolowerinvariant(), field.store.yes, field.index.analyzed, field.termvector.with_positions_offsets)); document.add(new field("meta_description", dl.meta_description.tolowerinvariant(), field.store.yes, field.index.analyzed, field.termvector.with_positions_offsets));  //and few more fields 

based on index first tried query along these lines:

var whatparser = new multifieldqueryparser(     global::lucene.net.util.version.lucene_29,     new string[] { "company_name", "description", "meta_keywords", "meta_description", "category" },     analyzer);  whatquery = whatparser.parse("search".tolowerinvariant()); 

this worked great until search term became more 1 word. next phrase query.

whatquery = new phrasequery(); whatquery.add(new term("company_name", what)); whatquery.add(new term("description", what)); whatquery.add(new term("meta_keywords", what)); whatquery.add(new term("meta_description", what)); whatquery.add(new term("category", what)); 

which found threw error: all phrase terms must in same field

so, going wrong? have suggestions on how fix it? i'm open changing search technology entirely if there better suggestions out there.

some additional information may useful

  • all results sorted in end via new sort(new sortfield[] {new sortfield("is_featured", sortfield.string, true),sortfield.field_score})
  • there additional search criteria each query added boolean query occur set should

thanks help.

i think booleanclause.occur.should issue. use this:

string[] fieldlist = { "field1", "field2", "field3";   //for field list varies .. there other ways create array of course list<booleanclause.occur> occurs = new list<booleanclause.occur>(); foreach (string field in fieldlist)     occurs.add(booleanclause.occur.should);  if(!string.isnullorempty(multiwordphrase)) {     query q = multifieldqueryparser.parse(multiwordphrase, fieldlist, occurs.toarray(), new standardanalyzer());     return q; } 

Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -