In Haystack logical operators give unexpected results - django

How to use logical operators in the solr + haystack bundle?
At the moment, the search in my system is done something like this:
I get the field from the post data
I give them to the filter(text=post[query]) function
It doesn't work, I tried additionally giving it to the Auto Query function, which also didn't work.
request example "covid OR coronavirus”
I tried additionally giving it to the Auto Query function, which also didn't work.
request example "covid OR coronavirus”

Related

Django haystack with Solr - how to specify GET parameters?

I'm using django_haystack with Solr 4.9. I've amended the /select request handler so that all requests use dismax by default.
The problem is that sometimes I would like to query specific fields, but I can't find a way to get the SearchQuerySet api to get it to play nicely with dismax. So basically I want to send the following (or equivalent) request to Solr:q=hello&qf=content_auto
I've tried the following aproaches:
Standard Api
SearchQuerySet().filter(content_auto='hello')
# understandably results in the following being sent to solr:
q=content_auto:hello
AltParser
query = AltParser('dismax', 'hello', qf="content_auto")
sqs = SearchQuerySet().filter(content=query)
# Results in
q=(_query_:"{!dismax+qf%3Dcontent_auto}hello")
Raw
query = Raw('hello&qf=content_auto')
# results in
q=hello%26qf%3Dcontent_auto
The last approach was so close, but since it escaped the = and & it doesn't seem to process the query correctly.
What is the best approach to dealing with this? I have no need for non-dismax querying so it would be preferable to keep the /select request handler the same rather than having to wrap every query in a Raw or AltParser.
In short, the answer is that it can't be done without creating a custom backend and SearchQuerySet. In the end I had to just revert back to a standard configuration and specifying dismax with an AltParser, slightly annoying because it affects your spelling suggestions.

Elastic search browser/url bar GET request

I am trying to execute an elastic search query, eventually with an angular.get call, but for the time being I cannot get it to work even in the browser URL bar. Here is my URL.
server_loc/index-1,index-2/_search?pretty=true&source=%22{query:{regexp:{col_name:BBG}}}%22&size=10&from=0
I know that at least setting the "q" variable within the URL causes me to get the correct results. For example..
server_loc/index-1,index-2/_search?pretty=true&q=col_name:BBG&size=10&from=0
This much works. However, I would like to make a query based on reg expressions. The results that DO get returned from the first URL are simply the first 10 things in my index, and a control-F for "BBG" turns up empty. So it is getting something but not what I want.
Help?

Doctrine2 apply function to query parameter

I use the doctrine query builder to build my query.
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select(array('u'))->from('Account', 'a');
-- problem here
$qb->where('lower_unaccent(u.email) LIKE :search');
$qb->setParameter('search', $search['search'] . '%');
This works fine, but I would also like to apply the lower_unaccent function to the search parameter.
Is there a way to do this with the query builder?
Because when I do LOWER_UNACCENT(u.email) LIKE LOWER_UNACCENT(:search) I get the following error:
Error: Expected Doctrine\ORM\Query\Lexer::T_STRING, got 'LOWER_UNACCENT'
Even if I change LOWER_UNACCENT TO LOWER, I get the same error message.
You have to use $qb->expr()->lower('u.email') and $qb->expr()->lower(':search'). To create the "LIKE" pass those as arguments to $qb->expr()->like().
There doesn't seem to be a unaccent method though, but maybe there is a way to customize this. Let me know how it went.
EDIT:
Looking into lower()'s code, it seems like you can use any function you want like this:
new Expr\Func('LOWER', array($x));
By default, I'm pretty sure you can't do that.
lower_unaccent is not standard SQL, and as far as I can see, not supported by Doctrine.
What you can do is extend DQL with user-defined functions, which will do whatever you want. It is not so hard to implement. Here is some documentation:
http://docs.doctrine-project.org/en/2.0.x/cookbook/dql-user-defined-functions.html
http://docs.doctrine-project.org/en/2.0.x/reference/dql-doctrine-query-language.html#adding-your-own-functions-to-the-dql-language

Graph API Search: Not matching results are returned

The Facebook post search keeps returning very strange results and everytime I try to find out rules it gets more confusing. I'm not even talking about operators and boolean logic like AND/OR.
E.g. try to search for the term "orange". My results all included "orang", but none the term I originally looked for: "orange".
Does anyone have an idea what may be the reason for this?

How do I retrieve Haystack SearchQuery parameters

I am looking for a way to serialize a Haystack search query (not the query results) so that I can reconstruct it later. Is there a way to do this without having to intercept the parameters from off of the request object?
For context, I want users to be able to subscribe to the results of a particular search, including any new results that may pop up over time.
Edit:
I settled on storing the search with:
filter = queryset.query.query_filter
and then loading this back in using:
SearchQuerySet().raw_search(filter)
Though I suspect this will tie me to whichever particular search back-end I'm using now. Is this true? Is there a better way?
You should have the query in your request.GET. Then it should be fairly easy to construct a RSS Feed using that query.