C# / .NETDevOpsMisc
C# / .NET
RavenDB Optional Queries and Boosting
Alexandru Puiu
Alexandru Puiu
October 08, 2013
1 min

Table Of Contents

01
Optional Queries
02
Query-time

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:

Optional Queries

// "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);

Query-time

var parser = new MultiFieldQueryParser(
    Lcn.Util.Version.LUCENE_29,
    new[] { "Title", "Description" }, _analyzer);
var query = parser.Parse(jobTitle.ToString());
query.SetBoost(boostValue);

Tags

utils
Alexandru Puiu

Alexandru Puiu

Engineer / Security Architect

Systems Engineering advocate, Software Engineer, Security Architect / Researcher, SQL/NoSQL DBA, and Certified Scrum Master with a passion for Distributed Systems, AI and IoT..

Expertise

.NET
RavenDB
Kubernetes

Social Media

githubtwitterwebsite

Related Posts

RavenDB Integration Testing
Using RavenDB in Integration Testing
December 24, 2022
2 min

Subscribe To My Newsletter

I'll only send worthwhile content I think you'll want, less than once a month, and promise to never spam or sell your information!
© 2023, All Rights Reserved.

Quick Links

Get In TouchAbout Me

Social Media