After implementing query-time boosting, I found that I wasn’t getting the results I was expecting … or any at all. I discovered there was an overload when adding queries that tells the query whether it “must,” “must not,” or “should” occur in the results. Inside a query object that inherits from QueryBase, do the following:
// "query" creation elided // ... this.AddQuery(query, BooleanClause.Occur.SHOULD); return this;
This made the query optional, allowing the other matching results to be returned. But, since it’s boosted, if results are found matching this query, it will be boosted higher in the results. Problem solved. Index-time boost
var doc = new Document(); // Code to add fields elided // Set the boost doc.SetBoost(boostValue);
var parser = new MultiFieldQueryParser( Lcn.Util.Version.LUCENE_29, new[] { "Title", "Description" }, _analyzer); var query = parser.Parse(jobTitle.ToString()); query.SetBoost(boostValue);
Quick Links
Legal Stuff