Search terms as args
Chris Herberte - September 6, 2007 - 23:13
| Project: | Views Fast Search |
| Version: | 5.x-2.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | patch (code needs work) |
Description
Is there an reason why search terms and conditions could not be supplies as a views argument, provided the code was there. Or is this in some other module and or out of the scope of VFS. The reason is that after looking for a solution to custom search module which would allow me to create a form, from which arguments like arg(1) = node type and arg(2) = search terms.
I know that I can use advanced search and parse conditions to the search input text, although having "type:joke" within the search conditions text is somewhat undesirable (for some);
If this is a possibility, I might have a crack at coding this but need a straight-up answer before getting too involved.

#1
I think it can be done. If you succeed, please contribute it back. An argument handler would be a handy addition.
#2
In addition, this could -- in theory provide an RSS feed for search results, yes? This, i'm sure would also be a welcome addition.
#3
Using the built in Views RSS selector argument you can already get an RSS feed for results.
#4
ahh, true.
#5
I created a patch to allow this, it works after some quick testing, but all i did really was duplicate some of the filtering code into the new argument functions.
It would probably be a better idea to refactor some of that block of code into smaller function(s) that could be reused rather than just duplicated, but for now i wanted to keep the patching simple.
This patch was created from the September dev version.
Hope its of use, and that it could be the start of adding this useful feature to the module.
Ben
#6
hell yea.... was just about to try usnig this with filters when args would be sooo much easier.. always check the issues page.. :)
#7
ok, well perhaps i was a wee premature in my excitement - any test this patch?
I applied to dev version and patch ran ok; but i dont see anything listed under arguments when i try to add to my view.
#8
ok, apparently views caches the argument options... that seems like a bad idea... even after re-saving module lineup it isnt cleared... hmmm???
#9
Patch seems to work and should be a huge help to me - but; anyone have tips on how to pass arguments?
i think if my view is at "find" then:
- find/green - finds things with "green"
- find/green+blue - only finds things with exact phrase "green blue"
- find/green/blue - only finds things with "green" AND "blue"
is there a "green" OR "blue" solution here?
#10
I believe it works as follows
- find/green - finds things with "green"
- find/green+blue - only finds things with "green" AND "blue"
I'm not sure if this works with the current patch but should be able to handle it
- find/green+OR+blue - finds things with "green" OR "blue"
I'm not sure if the arguments allow phrase search or not, but it would be something like
- find/%22green+blue%22
This doesn't work as you expect
- find/green/blue - only finds things with "green" - blue is ignored as its another argument.
You could always use an argument handler to allow you to format the arg as you prefer, like join multiple arguments together into a single one.
For instance you could make it so
- find/green/blue/red
is converted into
- find/green+OR+blue+OR+red
hth
Ben
#11
hmmm.. yup.. has a few bugs:
lorem+amet - does AND case
lorem+or+amet - throws errors
lorem+or - throws errors
darn, this would have been so usefull... but i gues go with this for now and try to fix.. code doesnt look too complex.
#12
pretty sure that having the word OR anywhere in your search terms causes errors. For now i am just usnig your patch; but filtering the word OR out.
Originally i thought i wanted defaults to be OR but now i think AND is the right choice - so just getting rid of the word OR isnt that big a deal.
#13
I had a quick look at this today, and tried using OR in the query with the filter too and that had the same result.
The problem i believe lies in the _views_fastsearch_query function rather than in the argument patch.
It simply isn't creating the where clause correctly. I had a quick go at it and it now works much better for me but i'm not totally happy with how it deals with the OR (since there is no parenthesis system)
I changed the code around line 605 to the following:
function _views_fastsearch_query(&$query, $values, $extra) {
// add the AND terms
if (isset($values['AND'])) {
if (isset($extra['AND'])) {
$conditions[] = '('. implode(' AND ', $extra['AND']) .')';
}
$arguments = $values['AND'];
}
// add the OR terms
if (isset($values['OR'])) {
foreach ($values['OR'] as $value) {
$conditions[] = '('. implode(' AND ', $extra['AND']) .')';
$arguments[] = $value;
}
}
if (isset($conditions)) {
$query->add_where(implode(' OR ', $conditions), $arguments);
}
#14
Yea, i had one of my guys take a go at it and i think he came to same conclusion which is that it wasn't really in the patch but that the module itself wasnt doing the right thing. I think he had a solution but then i decided we would just go with an AND case so we did the "simple but stupid" solution of just filtering OR out of the passed args/
I am sure ill get around to trying your solution at some point.
BTW - did i mention .. fastsearch, views and args is a major lifesaver.
thanks,
peter...
#15
radiantsouls, I applied your patch. It works excellently after changing the module code to fix the OR problem. +1 for addition to dev. Thanks to everyone, this is an awesome addition to Drupal and to Views Fast Search and yes a real lifesaver!
#16
Did anyone get phrase / parenthesis searches working with this? ie: "beer nuts" OR peanuts
#17
subscribing
#18
subscribing