Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

More like Solr Query filtering

I was trying to use the MLT (more like this) feature of SOLR but was stuck on how to use the filtering of related content. For e.g My documents in solr have following different categories sports, entertainment, funny, busiseness etc

I want related stuff (based on user query) for each category. Thus I would like to filter the MLT results of solr cased on category type. Can I somehow filter results?

If not possible, can I somehow use solr function query to make sure related stuff are grouped by category?

Thanks.

like image 345
Global Warrior Avatar asked Dec 07 '25 06:12

Global Warrior


2 Answers

Need to define a /mlt request handler and then use fq= for filterting the query for MLT

like image 175
Global Warrior Avatar answered Dec 09 '25 01:12

Global Warrior


In the solrconfig.xml definition, you should define a request handler as follows:

<requestHandler name="/mlt" class="solr.MoreLikeThisHandler">
</requestHandler>

Then you need to make a request to this handler where you specify the "fq" parameter. This will filter your MoreLikeThis (MLT) results. See the following example where documentid is the ID of the document on which you want to find similar results and searchtext is the field that you use to compare whether two documents are similar or not. "rows" is the number of MLT results that the request should return.

'http://solrserver.local:4562/solr/mlt?rows=2&fl=id&mlt.fl=searchtext&fq=category:<category>&q=id:<documentid>',

See the Filter Query documentation: https://cwiki.apache.org/confluence/display/solr/Common+Query+Parameters#CommonQueryParameters-Thefq(FilterQuery)Parameter

like image 45
Thorkil Værge Avatar answered Dec 09 '25 02:12

Thorkil Værge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!