SOLR - Tagging and Excluding filters

596 views
Skip to first unread message

Alex

unread,
Nov 14, 2013, 12:03:52 AM11/14/13
to django-...@googlegroups.com
Hi everyone!

I have a working installation of Django 1.5.4 and Haystack 2.1.0.

I am currently trying to achieve what is explained at the following page: http://wiki.apache.org/solr/SimpleFacetParameters#Tagging_and_excluding_Filters

Basically I need to prepend a special string beofre the facet name, in both the fq field and the facet.field.

Any ideas on how to implement this? As far as I understand there is no way to pass raw searches with custom parameters to SearchQuerySet.

Any help would be really appreciated.


Thanks!
Alex

Alex

unread,
Nov 14, 2013, 1:13:55 PM11/14/13
to django-...@googlegroups.com
It looks like I've found a workaround.

Basically I am adding the tag information directly to the facet name. Something like this:

sqs = SearchQuerySet().facet('{!ex=dt}store_exact')

and then I am manually building a filter to use with narrow option like the following one:

final_filter = '{!tag=dt}(store_exact:"STORE A") OR (store_exact:"STORE B")'
sqs.narrow(final_filter)

Luckily the query that is passed to Solr is exactly the one I was looking for, i.e. facet.field={!ex=dt}store_exact&fq={!tag=dt}(store_exact:"STORE+A")+OR+(store_exact:"STORE+B")

the only thing that is not working is the mincount option for the facet as the tag value within the name causes a wrong parameter to be built (f.{!ex=dt}store_exact.mincount which obviously doesn't work)

For now I am using the "facet.mincount=1" as an "inverted value" in the solrconfig.xml

Please let me know if you have any comments or feedbacks on this. I have found similar questions and everyone is proposing to run the query multiple times and store the original facets value somewhere (ad-hoc class / session).
I believe this is a much more efficient way to achieve the same result as it only requires one query (at least for Solr, I have no idea if a similar feature is supported by other backends).

It would be great to have a "exclude facet from filter" option directly built in haystack.

Thanks!
Reply all
Reply to author
Forward
0 new messages