Search code examples
apachesolrdrupal-7

Solr Query, Syntax trouble with drupal apache solr module


I'm working with apache solr, and the module for drupal 7 apachesolr. Some of our queries are very custom.

I have been looking in the solr documentation and at explanations on stackoverflow. I have come up with the query:

/select?q=&start=0&rows=20&fq=bundle:(message)&fq=sm_hashtags:(hashtags)&fq=(is_uid:(1 OR 2 OR 37 OR 38 OR 50 OR 166 OR 174 OR 198 OR 431 OR 499 OR 640 OR 642) AND is_privacy:(0)) AND -is_uid:(177 OR 189) AND is_status:(1)&fq=entity_id:{* TO 2666}&fl=tus_message_object,sm_hashtags,content,ts_search,is_privacy,is_status,is_uid&sort=entity_id+desc&wt=json&wt=json

but this is returning NULL, i have tried a few different things like:

/select?q=&start=0&rows=20&fq=bundle:(message)&fq=sm_hashtags:(hashtags)&fq=((is_uid:(1+OR+2+OR+37+OR+38+OR+50+OR+166+OR+174+OR+198+OR+431+OR+499+OR+640+OR+642)+is_privacy:(0))-is_uid:(177+OR+189)+is_status:(1))&fq=entity_id:{*+TO+2666}&fl=tus_message_object,sm_hashtags,content,ts_search,is_privacy,is_status,is_uid&sort=entity_id+desc&wt=json&wt=json

But I am not sure this is correct.

I need a filter that allows the users with id (is_uid) and all the ones with privacy is 0 but not the users in blocked id list -is_uid and where the status is 1.


Solution

  • You're using a lot of clauses so it is very hard to determine here what could be the cause. I can give you the following hints:

    a) Debug mode
    Copy the whole query string, go to the Solr Admin console and execute that query with and additional debug=true or debugQuery=true. In the outcoming response, Solr will append an additional section where it explains how it "sees" the query you entered

    b) Investigate each fq one by one
    If there's a problem, it is for sure in the filter queries, so I suggest you to gradually try them one by one. But before of that, see the c) point.

    c) fq design
    Filter queries are great for their caching capabilities. Here, although there are some fq that I think won't be reused so much (the is_uid filter) I suggest you to split those queries in order to have bettere reusable (i.e. cached) results; something like:

    fq=bundle:message // You already have this
    fq=sm_hashtags:hashtags // You already have this
    fq=is_privacy:0 // this will cache (for further reuse) all documents with no privacy
    fq=is_status:1 // this will cache (for further reuse) all documents with status 1
    fq=is_uid(1 OR 921 OR 9...) // Most probably these query results won't benefit so much of caching. If so, I think this query could be also part of the main query
    fq=-is_uid(8 OR 99) // Most probably these query results won't benefit so much of caching. If so, I think this query could be also part of the main query