Closed (fixed)
Project:
Views (for Drupal 7)
Version:
6.x-2.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
18 Jul 2006 at 05:51 UTC
Updated:
2 Jun 2013 at 10:44 UTC
Perhaps this is already possible somehow... but what I would like to be able to do is use wildcards in the arguments so that I can do a query for %apple% to return results for (similar to a standard sql LIKE operator):
apples
apple pie
fuji apple
special apple pie
etc etc
So, my URL would be something like /myview/*apple* and would return all of the above examples.
Can this be done? I know I can do this with a filter using "%" as a wildcard, but how can I do it for a dynamic argument? Can I reference an argument in the filter??
Many thanks!
c.h.u.d.
Comments
Comment #1
merlinofchaos commentedThis would likely be a new argument. Possibly it could be implemented as an option to the existing argument, I'm not entirely sure. I'll have to look into it at some point.
Comment #2
chud commentedThanks for the reply... dang- I thought maybe this would be an easy one :) Here is the real-world application I need this for:
I am creating a "branch locator" for a client site. Each branch has a specific list of Canadian postal code prefixes (although this would work exactly the same with zip codes). My plan is to create a content type using cck with a few custom fields -- one of them being 'Postal Code Prefixes'. I thought it would be much easier for the user to enter postal codes into a large textarea with one prefix on each line (rather than have a separate field for every prefix since there are hundreds).
Then I would simply create form with a single postal code field -- this form would submit to the view I created, and pass the postal code prefix (first 3 chars) as an argument to the view. Then if I could just use a LIKE operation to return all matching locations, my solution would be complete.
For example, if Location A had the following in it's postal code prefix field:
V8P
V5V
V6G
And Location B had:
902
M5R
623
V6G
Then a view with an argument of, say, "%V5V%" would only return Location A in its results.
Perhaps there is a better way to do this? I just thought using some sort of wildcard would be quick and dirty... the client only has a few hundred locations so I assume the results would still be returned fast enough.
Any thoughts on how to do this with views?
Best,
Colin
PS- unfortunately the proximity search abilities of the location module are not useful in this case, because each location is a franchise and in some cases bids for exclusive access to a postal code prefix.
Comment #3
merlinofchaos commentedYou could try using an exposed filter, which actually could accomplish that, I think.
Comment #4
chud commentedthat almost works... but the user would still need to actually type in '%something%' (with the % signs)
Comment #5
chud commentedHere's what I ended up doing:
Instead of a page view, I used a block (set to the content region of the page) -- not sure if this is a feature or a bug, but unlike the page view the block view did not display the exposed filter's form. Nice- now I don't have to hide it with CSS.
I created another block, also in the content region with the following code:
As you can see there's a bit of javascript in there to append the % signs to the search string (and trim it to the first 3 chars in this case)...
Ultimately all that matters is that you append &filter0=%something% to your URL -- which the exposed filter then reads.
Comment #6
merlinofchaos commentedthat almost works... but the user would still need to actually type in '%something%' (with the % signs)
Actually, no, if you set the operator to 'Contains', and lock it should apply the % automatically.
Comment #7
merlinofchaos commentedMarking fixed; what's described should be possible using the Contains operator.
Comment #8
(not verified) commentedComment #9
davidwhthomas commentedI realize this is an older thread but, has this feature been enabled for free tagging vocabularies???
It would be great if you could perform a wildcard search on freetagging vocab terms.
i.e 'apple'
would match
'apple'
'apple sauce'
etc...
There is no 'contains' operator available for taxonomy filters.
DT
Comment #10
polYou might also check this thread: http://drupal.org/node/376932
I've just submitted a patch for Views 2.X and Views 3.X and also a module for Views 6.X-2.X.
Comment #11
9802008 commentedI needed to be able to search with the 'LIKE' MySql command, instead of the = that is used by default in views search filters, as well as add wildcards on either side of the search term.
Here is a hack (only use as a last resort) to achieve this for Views 6.3:
edit: views/modules/search/views_handler_filter_search.inc
in the 'query' function just after (around line 94)
add this code