Question

I'm using SolrNet to access a Solr index where I have a multivalue field called "tags". I want to perform the following pseudo-code query:

(tags:stack)^10 OR (tags:over)^5 OR (tags:flow)^2

where the term "stack" is being boosted by 10, "over" is being boosted by 5 and "flow" is being boosted by 2. The result I'm after is that results with "stack" will appear higher than those with "flow", etc.

The problem I'm having is that say "flow" only appears in a couple of documents, but "stack" appears in loads, then due to a high idf value, documents with "flow" appear above those with "stack".

When this was project was implemented straight in Lucene, I used ConstantScoreQuery and these eliminated the idf based the score solely on the boost value.

How can this be achieved with Solr and SolrNet, where I'm effectivly just passing Solr a query string? If it can't, is there an alternative way I can approach this problem?

Thanks in advance!

Was it helpful?

Solution

I don't think there any way to directly express a ConstantScoreQuery in Solr, but it seems that range and prefix queries use ConstantScoreQuery under the hood, so you could try faking a range query, e.g. tags:[flow TO flow]

Alternatively, you could implement your own Solr QueryParser.

OTHER TIPS

Solr 5.1 and later has this built into the query parser syntax via the ^= operator.

So just take your original query: (tags:stack)^10 OR (tags:over)^5 OR (tags:flow)^2

And replace the ^ with ^= to change from boosted to constant: (tags:stack)^=10 OR (tags:over)^=5 OR (tags:flow)^=2

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top