I guess I'm a little confused, as what you're describing is currently entirely doable in Haystack. I don't know what code you're using to present the facets, but drilling down with multiple makes looks like "SearchQuerySet().narrow("make_exact:(benz OR bentley)").facet("make").facet("body_style").facet_counts()". What gets put in the call to "narrow" makes the difference.
Daniel
> --
> You received this message because you are subscribed to the Google Groups "django-haystack" group.
> To post to this group, send email to django-...@googlegroups.com.
> To unsubscribe from this group, send email to django-haysta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-haystack?hl=en.
>
> urls.py (1 - why would it be views.py?):
> from haystack.query import SearchQuerySet
> from haystack.views import FacetedSearchView
> from forms import MultiFacetedSearchForm
>
> sqs =
> SearchQuerySet().facet('modalidade').facet('{!ex=categoria_exact}categoria_exact').facet('{!ex=qualidade_exact}qualidade_exact')
>
> urlpatterns = patterns('haystack.views',
> url(r'^search/$', FacetedSearchView(form_class=MultiFacetedSearchForm,
> searchqueryset=sqs), name='haystack_search'),
> )
Not sure what your question is here. Can you be more specific?
> class MultiFacetedSearchForm(FacetedSearchForm): # 2 - SearchForm doesn't
> work here. Is there any problem?
> def search(self):
> list = {}
> sqs = super(MultiFacetedSearchForm, self).search()
This call to ``super`` is needed to go to ``FacetedSearchForm``, which
has additional code beyond the standard ``SearchForm`` to do the
faceting.
> facet = facet_name+':"'+facet_value+'"' # 3 - added quotes
> to don't split it in spaces. Any problem?
This was just example code AFAIK. Production code would have to be sturdier.
> 4 - How could I order facets results alphabetically? [('apple', 2),
> (u'orange', 4)] instead of [('orange', 4), (u'apple', 2)].
The only solution here is to post-process the order of them. Perhaps
creating a template tag to do it or doing it in the view & sorting it
there.
> 5 - I just copied some things. Where could I learn what means 'tag' and
> 'ex'?
Those are function queries being passed to Solr. See
http://wiki.apache.org/solr/FunctionQuery for an overview & usage.
Daniel
if hasattr(self, 'data') and self.selected_facets:
Hi,Iam a Django,Haystack newbie...Had the same problem as mentioned in above post...Multiselect within the same facet would still not work...broke my head for couple of hours before finding the solution... Modified the MultiFacetedSearchForm to add a "OR" operator between facets of the same field.... example code below:class MultiFacetedSearchForm(SearchForm):
def __init__(self, *args, **kwargs):
self.selected_facets = kwargs.pop("selected_facets", [])
super(MultiFacetedSearchForm, self).__init__(*args, **kwargs)
def search(self):
sqs = super(MultiFacetedSearchForm, self).search()
search_facets = {}
if hasattr(self, 'data') and self.data.has_key(u'selected_facets'):
for facet in self.data.getlist('selected_facets'):
facet_name, facet_value = facet.split(':')
search_facets[facet_name] = facet_value
for facet_search in search_facets.keys():
search_query = None
for facet in self.data.getlist('selected_facets'):
facet_name, facet_value = facet.split(':')
if facet_search == facet_name:
if search_query:
search_query += u' OR '
else:
search_query = u'('
search_query += u'"'+facet_value+'"'
search_query += u')'
facet = facet_search+':'+search_query
narrow_query = u"{!tag=%s}%s" % (facet_search, facet)