Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Boost a Field In Lucene.Net 3

I want to boost a field in Lucene.Net 3.0.3. However the SetBoost Method doesnt appear to be defined anymore in Lucene. How do I boost a field, say, I want the "Title" of a document to carry more weight that the rest of the fields?

like image 978
Sleek Avatar asked Feb 17 '23 19:02

Sleek


1 Answers

You can boost a field in index time or in search time. To boost a field in index time you can set:

 Field titleField = new Field("title", strTitle, Field.Store.NO, Field.Index.ANALYZED);
 titleField.Boost = 2;

 doc.Add(titleField);

remember that OmitNorms must be set to false.

To boost a field in search time you can set:

  TermQuery q = new TermQuery(new Term("title", "cat"));
  q.Boost = 2;

  _searcher.Search(q, 100);
like image 85
Omri Avatar answered Feb 22 '23 02:02

Omri