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

merlinofchaos’s picture

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

chud’s picture

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

merlinofchaos’s picture

You could try using an exposed filter, which actually could accomplish that, I think.

chud’s picture

that almost works... but the user would still need to actually type in '%something%' (with the % signs)

chud’s picture

Here'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:

<form name="postalcodesearch" action="/book-an-evaluation" method="get">
  <input type="hidden" name="filter0" value=""/><br />
  <input type="hidden" name="lang" value="en"/><br />
  <input type="text" name="pcode" value=""/><input type="button" name="searchbutton" value="Search" onClick="document.postalcodesearch.filter0.value = '%' + document.postalcodesearch.pcode.value.substring(0,3) + '%'; document.postalcodesearch.submit();"/><br />
  </form>

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.

merlinofchaos’s picture

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

merlinofchaos’s picture

Status: Active » Fixed

Marking fixed; what's described should be possible using the Contains operator.

Anonymous’s picture

Status: Fixed » Closed (fixed)
davidwhthomas’s picture

I 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

pol’s picture

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

9802008’s picture

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

   $this->query->add_where($this->options['group'], $this->search_query[2], $this->search_query[3]);

add this code

// Rename the view name (in my case usersearch) to the name of your view so that
// the change only affects the one view
if ($this->view->name == 'usersearch') {
                // old value of $this->query->where[0]['clauses'][0] is: "search_index.word = '%s'";
                // Change to new value
	  	$this->query->where[0]['clauses'][0] = "search_index.word LIKE '%%%s%%'";
	  }