How best to support Search Syntax

139 views
Skip to first unread message

Vignesh Sarma

unread,
Apr 26, 2012, 5:24:50 AM4/26/12
to django-...@googlegroups.com
Hi,

I have to support the search function like,
AND, OR, etc..

Right now since haystack conjuncts with either AND or OR I can not support the other.My back-end is solr, which supports these function all by default. I just need haystack to move out the way. I am trying to use raw_search().

Is this my best option, is it safe?
Is there a problem with adding other filters on top of raw_search()?

Thanks,
Vignesh

Danny Adair

unread,
Apr 26, 2012, 5:36:13 AM4/26/12
to django-...@googlegroups.com
Hi Vignesh,

On Thu, Apr 26, 2012 at 21:24, Vignesh Sarma <vig...@recruiterbox.com> wrote:
>[...]
> I have to support the search function like,
> AND, OR, etc..
>
> Right now since haystack conjuncts with either AND or OR I can not support
> the other.My back-end is solr, which supports these function all by default.

Maybe I'm misunderstanding the issue but have you seen SQ objects
http://django-haystack.readthedocs.org/en/latest/searchquery_api.html#sq-objects

"For expressing more complex queries, especially involving AND/OR/NOT
in different combinations, you should use SQ objects. Like
django.db.models.Q objects, SQ objects can be passed to
SearchQuerySet.filter and use the familiar unary operators (&, | and
~) to generate complex parts of the query."

Cheers,
Danny

Vignesh Sarma

unread,
Apr 26, 2012, 9:22:00 AM4/26/12
to django-...@googlegroups.com
Hi Denny,

I have to support an even more complex syntax like, 
author:name
quotes like "firstname lastname"
also brackets, I am planning to extend the search engine query parser in http://pyparsing.wikispaces.com/file/view/searchparser.py,
Is this the best way to proceed, 

Thanks,
Vignesh

Danny Adair

unread,
Apr 26, 2012, 9:59:26 AM4/26/12
to django-...@googlegroups.com
On Fri, Apr 27, 2012 at 01:22, Vignesh Sarma <vig...@recruiterbox.com> wrote:
>[...]
> I have to support an even more complex syntax like,
> author:name
> quotes like "firstname lastname"
> also brackets, I am planning to extend the search engine query parser
> in http://pyparsing.wikispaces.com/file/view/searchparser.py,
> Is this the best way to proceed,

Looks good to me.
You're parsing the user input into a Python object and then build the
haystack query with SQ objects from that.
I assume prefixes like "author:" go against their own index field,
everything else against a fulltext index.
Can't see an issue - all the best!

Cheers,
Danny

Andrei

unread,
Apr 4, 2013, 11:53:45 AM4/4/13
to django-...@googlegroups.com, danny...@unfold.co.nz
Thanks, Danny!

Andrei


On Wed, Apr 3, 2013 at 12:07 PM, Danny Adair wrote:
Hi Andrei,
Two weeks after that message, Vignesh sent this
https://groups.google.com/forum/#!msg/django-haystack/TjvAd7I9YSo/BFZ9vksHx60J

announcing https://github.com/recruiterbox/haystack-queryparser
which was last updated... this year!

Cheers,
Danny


On Wednesday, April 3, 2013 11:57:31 AM UTC+2, Andrei wrote:
Hi guys,

Have you managed to implement what you needed? Is this open sourced somewhere?
This could be a really, really nice pull request to haystack.

Are there any other available packages to solve this problem?

Thanks,
Andrei
Reply all
Reply to author
Forward
0 new messages