How to constrain/filter More Like This results in Solr?

4.4k Views Asked by At

In Solr, I am wondering if it's possible to constrain/filter the "More Like This" result set from a standard (dismax) query - e.g., without having to use the specific MoreLikeThis request handler? For example, I have a Solr index which has documents for two countries. When I do my original (dismax) query, I use a field query operator (fq) to filter the results for the country of interest. But the MLT results that get returned are for both countries. I tried using the mlt.fl=country,name to indicate "show me more results that are similar in country and name" but it doesn't seem to obey the country criteria (or at least the name parameter far outweighs the country parameter).

I can't seem to find any Solr documentation that indicates there is an option for this, but I'm hoping one of you Solr experts out there may have some nifty tricks/hacks for this.

Thanks in advance!

1

There are 1 best solutions below

2
On

Solr mlt.fl is supposed to find Related Documents based on these fields. However, it is not obligated to do so like the NOT clause of fq. A workaround could be to exclude the country using fq param. So, your mlt query could become something like

/mlt?q=id:ID&fq=-country:COUNTRY&mlt.boost=true

ID: The document ID for which MLT needs to be calculated. COUNTRY: The country which you want to exclude.