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!

CommentFileSizeAuthor
#10 1592860-7.patch924 bytespwolanin
#7 1592860-6.patch897 bytespwolanin
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wonder95’s picture

Out 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.

ditcheva’s picture

You 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:

  if(isset($_GET['fq'])) {
      $params['fq'] = $_GET['fq'];
      $query->addParams($params);
  }

Does that work for you too? I'm in Drupal 7.

pwolanin’s picture

Category: support » bug

If the module is working right, that extra code should not be needed.

ditcheva’s picture

I 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!

pwolanin’s picture

Ok, it's working for me locally, but you need fq as an array in the URL like:

?fq[]=tid:10

ditcheva’s picture

Ah ok. So this was a syntax issue after all! I'll submit a patch that includes a good example with the checkbox setting then...

pwolanin’s picture

Version: 7.x-1.0-beta19 » 7.x-1.x-dev
Status: Active » Needs review
FileSize
897 bytes

Here's a patch to clarify the admin page help text.

Nick_vh’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me

Apologies for the created confusion :-)

ditcheva’s picture

Version: 7.x-1.x-dev » 7.x-1.0-beta19
Status: Reviewed & tested by the community » Active

Thank you, both. Clear and concise!

pwolanin’s picture

Version: 7.x-1.0-beta19 » 7.x-1.x-dev
Status: Active » Needs review
FileSize
924 bytes

better?

ditcheva’s picture

Yes. I like this version better!

pwolanin’s picture

Status: Needs review » Fixed

fixed in 7.x-1.x and 6.x-3.x

Nick_vh’s picture

Status: Fixed » Closed (fixed)