Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#16 | search-api-exclude-contextual-filter.patch | 2.69 KB | nbucknor |
#13 | 1141488--multiple-views-arguments-13.patch | 3 KB | drunken monkey |
#9 | search_api-multiple_numeric_argument.patch | 3.51 KB | moonray |
Comments
Comment #1
drunken monkeyMore 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.
Comment #2
floleft CreditAttribution: floleft commentedI tried views php as a filter as well and it didn't return a result. I'm still trying other ways.
Comment #3
floleft CreditAttribution: floleft commentedAny 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.
Comment #4
drunken monkeyWhile 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.
Comment #5
floleft CreditAttribution: floleft commentedThank you for your response.
Comment #6
amitaibuSorry, subscribe.
Comment #7
amitaibuThe problem with exposing the filter for e.g. node ID, is that if I try to pass multiple values (1,2,...) I get
Comment #8
moonray CreditAttribution: moonray commentedNeed this as well... same problem as #7.
Comment #9
moonray CreditAttribution: moonray commentedAttached 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.
Comment #10
moonray CreditAttribution: moonray commentedOK, 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:
EDIT: this was while using apache solr. Perhaps it works for non solr searches.
Comment #11
moonray CreditAttribution: moonray commentedJust confirmed, this is a search_api_solr issue. My patch does work. :)
Solr issue: #1276970: Large queries break solr search
Comment #12
drunken monkeyThanks 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!
Comment #13
drunken monkeyFinally 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!
Comment #14
dasjonice, applying the patch enabled me to use multiple terms ("id1+id2") as contextual filter with search api.
Comment #15
drunken monkeySeems to work fine, and since no-one complained in the last eight months, I'm committing it.
Comment #16
nbucknor CreditAttribution: nbucknor commentedI've added a patch to this patch to allow an exclude option on contextual filters. Related to #1407844: Allow exclude for contextual filters
Comment #17
drunken monkeyPlease post that in the other issue, where it belongs.
And remove the spaces from empty lines.
Comment #18
nbucknor CreditAttribution: nbucknor commentedMy apologies. Patch posted here: http://drupal.org/node/1407844#comment-5994260
Comment #20
l0calh0rst CreditAttribution: l0calh0rst commentedTiny 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?
Comment #21
gouthamraon CreditAttribution: gouthamraon commentedYou 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