1

If my search keyword is 'test,' then my document is 'testtesttest.' How can I get the result to show that the number of occurrences is 3 in Solr?"

Unfortunately, the result I am getting shows a term frequency of 0 in Solr when I use the query q= test with the term function termfreq(section_title_t,test').

Please help. Thank you

2
  • have you tried writing your query like this q=*test* ?
    – Richard Seal
    Aug 7 at 18:36
  • Hello Alexng, did you find the solution to this ? We are in a same situation, let us know, if you found a way around.
    – D J
    Nov 14 at 9:24

1 Answer 1

0

In order to show the result of termfreq() in the solr dashboard as a separate field, you can use the fl= syntax as specified here: https://solr.apache.org/guide/8_3/function-queries.html

You can use the controls available in the SOLR dashboard to generate the URL for you.

Query

First of all you need to add a standard query. Look for the box on the dashboard that has the q above and add something similar to:

section_title:'test'

Fields to return

Look for the box with fl and add something similar to below:

_uniqueid, termfreq(section_title,'test')

Note I added a uniqueid to differentiate, but you would most likely change to title field or something.

Sort

This might not be strictly be necessary in your situation, but if you are using a broader search query, then you need to ensure the results with higher matches are displayed. In this situation, look for the sort box and add something similar to:

termfreq(section_title,'test') desc

Execute Query

Now when you hit the Execute Query button, it will generate the correct URL with query specified. Yours should look something like this:

https://localhost:8983/solr/#/your_index/query?fl=_uniqueid%2C%20termfreq(section_title%2C%27test%27)&q=section_title%3A%27test%27&sort=termfreq(section_title%2C%27test%27)%20desc

Working Example:

Please see screenshot below demonstrating this working as per above.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.