I need to reduce results even further than the fulltext and facet searching allows. In normal views I would write a SQL query in the Contextual Filter and send the view a comma separated list. I would then select "Allow multiple values" so the list would be handled correctly. After writing the query I noticed in the Search API views, there is no Allow multiple values. Is there a reason for this? If so, is there another way to reduce results without creating a module?

This is set as a bug, but it might need to be changed to a feature request.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drunken monkey’s picture

Title: No "Contextual Filter: Allow multiple values" field in search api views » Allow multiple values for contextual filters
Category: bug » feature

More a feature request, maybe I'll do it together with #1119594: Fix Views argument handlers. Contextual filters are currently lagging a bit behind, as filters are used more often.
And no, I don't think there is another way. Or maybe you could use an exposed filter, and pass the correct filter values directly in the URL? Then you'd just have to hide the exposed form element.
But, of course, just allowing multiple values is a lot cleaner and probably even easier.

floleft’s picture

I tried views php as a filter as well and it didn't return a result. I'm still trying other ways.

floleft’s picture

Any word on if this is a feature we can expect in the near future? Just curious; as I'll need to find a way around this if it's not a priority.

drunken monkey’s picture

While I see this is an important feature request, I sadly won't have the time to work on this in the near future. You are free to come up with a patch yourself, though, I'd surely review and (when acceptable, of course) commit it.

floleft’s picture

Thank you for your response.

amitaibu’s picture

Sorry, subscribe.

amitaibu’s picture

The problem with exposing the filter for e.g. node ID, is that if I try to pass multiple values (1,2,...) I get

HTTP ERROR: 500

For input string: "1,2"

java.lang.NumberFormatException: For input string: "1,2"
...
moonray’s picture

Need this as well... same problem as #7.

moonray’s picture

Status: Active » Needs review
FileSize
3.51 KB

Attached is a patch that makes numeric arguments allow multiple values. It probably needs some work to make it consistent across search_api, but this fulfills my needs. Posting to give whomever will write the patch a headstart.

moonray’s picture

Status: Needs review » Needs work

OK, definitely needs work.
If you pass too many parameters to the argument (see below), it'll break. A better way to do it would be to use the 'IN' operator, but that's not currently supported by search_api's query interface.

Passing this parameter (which results in more than 100 filter conditions) breaks the query interface:

3+5+9+16+56+64+69+2+6+84+2371+2403+2424+2490+3133+4193+5848+7022+7023+16960+16961+87+88+98+2335+2412+2471+2505+2506+2562+3550+3835+3901+3929+3997+4486+4501+5214+5680+6060+6154+6155+6357+6692+7005+7024+7025+7032+7033+7034+7115+7118+7120+7124+7131+7132+7140+7287+7306+7308+7309+7395+7437+7442+7513+7525+7528+7529+7530+7624+7657+7833+8030+8086+8094+8100+8101+8106+8107+8172+8186+8189+8365+8366+8401+8542+8607+8720+8740+8771+9059+9107+9108+9439+9440+9559+9710+9956+9960+10066+10397+10559+10656+10724+10769+10794+11345+11404+13639+13841+14615+16059+82

EDIT: this was while using apache solr. Perhaps it works for non solr searches.

moonray’s picture

Status: Needs work » Needs review

Just confirmed, this is a search_api_solr issue. My patch does work. :)
Solr issue: #1276970: Large queries break solr search

drunken monkey’s picture

Thanks a lot for the patch! I'm sorry I took so long to respond, but I'm currently completely buried in work. Will review the patch once I get the time, but sounds very promising!

drunken monkey’s picture

Finally managed to look into this – sorry it took me so long!
I wonder a bit, why did you only use this for numeric arguments, and not just for all? I don't really see a reason for that (except, of course, for fulltext and MLT arguments). I therefore moved the functionality to the main argument handler.
Other than that: Bravo! An excellent patch, even with my usual nit-picky way I hardly had to change anything.

Please someone test and/or review, then I think we can commit this!

dasjo’s picture

nice, applying the patch enabled me to use multiple terms ("id1+id2") as contextual filter with search api.

drunken monkey’s picture

Status: Needs review » Fixed

Seems to work fine, and since no-one complained in the last eight months, I'm committing it.

nbucknor’s picture

Status: Fixed » Needs review
FileSize
2.69 KB

I've added a patch to this patch to allow an exclude option on contextual filters. Related to #1407844: Allow exclude for contextual filters

drunken monkey’s picture

Status: Needs review » Fixed

Please post that in the other issue, where it belongs.
And remove the spaces from empty lines.

nbucknor’s picture

My apologies. Patch posted here: http://drupal.org/node/1407844#comment-5994260

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

l0calh0rst’s picture

Tiny question concerning this: this post is ~1.5 years old but it seems this patch is not part of the current stable release (7.x-1.8) which is from sept 1st 2013. It only works in the latest dev.

Any particular reason?

gouthamraon’s picture

Issue summary: View changes

You can pass multiple values using contextual filter,

Select Raw Value from Url and select PathComponent/arugument.

Below we have More section from that you can check Allow multiple values in the form of 1+2+3 (for OR) or 1,2,3 (for AND).

http://example.com/some-path/24+25

or

http://example.com/some-path/24,25