Hi there,
I'm trying to be able to build apachesolr queries through the URL, and have checked the setting 'Allow user input using the URL' on this particular search page.
The description on this setting reads "Allow users to use the URL (mysite.com?q=test&fq=userinput) for manual facetting. This will only work after a search term is searched. Recommended is to leave this unchecked"
I am able to successfully create accurate searches with the fq parameter programmatically, but cannot get it to work by passing term filters through the URL. The example with the checkbox isn't very helpful, since it just says 'fq=userinput'. Also, the example says that I can put my key terms in the q parameter, but that doesn't work for me. If I include a 'q=test' parameter as stated, it generates a 'page not found' error each time. I have to keep using mysite.com/[search path]/[keyword] and only that works.
In terms of the fq parameter, however, is the following the correct syntax:
mysite.com/[search path]/[search keyword]?fq=tid:49
is the 'userinput' part supposed to be something like tid:49 or im_field_tag_support_cat:49? Or something else altogether?
I can't even get the above simple example to work, but would ideally love to be able to AND and OR terms in my searches.
If anyone can provide an example or two of using the fq parameter (perhaps even with ANDing or ORing terms) please share! I've also seen a few examples using 'filters' in the URL, but can't get those to work either.
If I get any examples, I'd be happy to provide a simple, tiny patch improving the examples under this setting!
Thanks!
Comment | File | Size | Author |
---|---|---|---|
#10 | 1592860-7.patch | 924 bytes | pwolanin |
#7 | 1592860-6.patch | 897 bytes | pwolanin |
Comments
Comment #1
wonder95 CreditAttribution: wonder95 commentedOut of curiosity and slightly off-topic), how are you creating accurate searches with the fq parameter programmatically? Are you using the prepare and/or alter hooks, or something like calling the apachesolr_search_search_execute function directly? I've been trying the latter without any luck.
Comment #2
ditcheva CreditAttribution: ditcheva commentedYou know, I actually got it working (kind of) though I can't quite get it to do ORs and ANDs in a way that makes sense to me.
I can now do stuff like mysite.com/search_url?fq=tid:(144 OR 241), where 144 and 241 are just term ids.
To get it to work though I did do some extra work:
And all I do is grab that from the url in my hook_apachesolr_query_alter(&$query) hook and set it in the params of the current query:
Does that work for you too? I'm in Drupal 7.
Comment #3
pwolanin CreditAttribution: pwolanin commentedIf the module is working right, that extra code should not be needed.
Comment #4
ditcheva CreditAttribution: ditcheva commentedI agree, pwolanin. As an additional piece of info: before I opened this ticket, I was already implementing hook_apachesolr_query_alter(&$query), however, I was *not* setting any query parameters in it.
The fq parameter, when placed in the URL, even after I checked the setting in the admin form to accept fq parameters, was never picked up. That's why I added that piece of code in my hook. Now everything works well.
I just wanted folks to know, in case the fact that I was implementing the hook may have changed something, but, like I said, I was not setting or replacing parameters for the query in it. Certainly sounds like a bug.
I opened this ticket because at first I thought my syntax for the fq parameter was wrong, so I hope we can also add a more useful example in the admin form, such as the one from my previous comment:
mysite.com/search_url?fq=tid:(144 OR 241), where 144 and 241 are just term ids.
Should help folks who are trying to use it!
Comment #5
pwolanin CreditAttribution: pwolanin commentedOk, it's working for me locally, but you need fq as an array in the URL like:
?fq[]=tid:10
Comment #6
ditcheva CreditAttribution: ditcheva commentedAh ok. So this was a syntax issue after all! I'll submit a patch that includes a good example with the checkbox setting then...
Comment #7
pwolanin CreditAttribution: pwolanin commentedHere's a patch to clarify the admin page help text.
Comment #8
Nick_vhLooks good to me
Apologies for the created confusion :-)
Comment #9
ditcheva CreditAttribution: ditcheva commentedThank you, both. Clear and concise!
Comment #10
pwolanin CreditAttribution: pwolanin commentedbetter?
Comment #11
ditcheva CreditAttribution: ditcheva commentedYes. I like this version better!
Comment #12
pwolanin CreditAttribution: pwolanin commentedfixed in 7.x-1.x and 6.x-3.x
Comment #13
Nick_vh