difference between filter and narrow.

432 views
Skip to first unread message

@@

unread,
Nov 28, 2009, 10:53:02 AM11/28/09
to django-...@googlegroups.com
Hi,
Is there any difference between filter and narrow?
It seems the default filter (filter_and) acts the some way as narrow, is there any performance benefit if i use narrow, since i notice facets use narrow instead of filter.

David Sauve

unread,
Nov 28, 2009, 11:16:41 AM11/28/09
to django-...@googlegroups.com
I can't speak about how these are used internally for Whoosh and Solr, but in my experience it doesn't make a difference for Xapian.  The difference is in the implementation, but the end result is essentially the same.

--

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.

Daniel Lindsley

unread,
Nov 30, 2009, 10:11:06 PM11/30/09
to django-...@googlegroups.com
Askfor & David,


On the Solr/Whoosh backends, ``narrow`` is used to create an subset
of all documents to search within. You can think of this like a
subselect in a SQL query. The reason ``narrow`` exists instead of just
using ``filter`` is that queries used to evaluate differently if you
shoved the narrowing bit into the query with everything else.

sqs = SearchQuerySet().narrow(sites__in=[1,3]).filter(content='hello').filter_or(content='world')
# Docs narrowed to ones with site 1 or 3, then searching "hello OR world"
# ...vs...
sqs = SearchQuerySet().filter(sites__in=[1,3]).filter(content='hello').filter_or(content='world')
# Used to be searching "sites:[1,3] AND hello OR world"

This may be different now, due to SQ and the use of parenthesis in
the query, but ``narrow`` feels safer to me when I need it, knowing
I'll be limited to the correct subset of documents and that I'll have
a simpler search query within those documents.


Daniel
Reply all
Reply to author
Forward
0 new messages