0

Hi Im trying to build a query in c# using solr:

Query.Append($"&fq={{frange l=3}}termfreq(Description,'keyword') OR {{frange l=1}}termfreq(title, 'keyword'")"

While this one below works :

Query.Append($"&fq={{frange l=3}}termfreq(Description,'keyword')")

The occurrence should be 3 times in the description OR 1 time in title. But executing the query gives a syntax error. Using termfreq once works but with conditions, it's failing.

Any help? Thanks.

Suman Baul
  • 133
  • 1
  • 11
  • There's quite a few things going on here; you have duplicate `{{`'s (one set should be enough) and you have placed the `OR` inside the `termfreq` function call; you also say that they should be three times in the description _and_ one time in the title, but you use `OR` in your query. Possible solutions will depend on exactly what you're looking for. – MatsLindh Jun 24 '22 at 15:58
  • Thanks for the response MatsLindh. I have updated the query and also the description. {{}} I have used this as an escape character for {} – Suman Baul Jun 24 '22 at 17:49
  • I'm guessing you can do this by collapsing it into one single frange: `{!frange l=3}add(termfreq(Description,'keyword'),mul(termfreq(Title,'keyword'), 3))` - since that would give you 3 as a value if it's three times in Description, or if its at least once in Title. – MatsLindh Jun 24 '22 at 18:13
  • The query returns results that also include docs that don't have the keyword. – Suman Baul Jun 26 '22 at 16:53
  • Hi Mats, please do the honour of posting this as the answer. It worked. – Suman Baul Jul 04 '22 at 22:53

1 Answers1

1

You can solve this by collapsing it into one single frange:

{!frange l=3}add(termfreq(Description,'keyword'),mul(termfreq(Title,'keyword'), 3))

This will give you 3 as a value if it's three times in Description, or if it's at least once in Title (being the sum of occurences of keyword in Description and occurences of keyword in Title - multiplied by three. So if it occurs once in the title, you get 1 * 3 => 3, but for the description field you don't multiply at all - meaning you'll have to have it occur three times to get to three.

MatsLindh
  • 49,529
  • 4
  • 53
  • 84