heldercervantes Posted May 1, 2015 Share Posted May 1, 2015 Hi guys. I'm trying to build a complex search and so far it seems over my head. Can't find an answer digging through the docs or the forum so here goes. Basically I have a bunch of fields (textfields, textareas and selects) and I want the search keywords to be compared to values in all of them. I'm having trouble with the selects: $selector = "ref|title|type|version|state%=$q"; Since 'state' is a select, I get... Error: Exception: Operator '%=' is not implemented in FieldtypeSelect Oh and since I'm here, there's another problem. I need this search to look for each word without regard for sequence. For example, if I have a page called "this and that" and search "this that" doesn't find it. I have tried using *tilde* instead of %, but that doesn't find keywords shorter than 4 chars and I need that as well. Link to comment Share on other sites More sharing options...
LostKobrakai Posted May 1, 2015 Share Posted May 1, 2015 To circumvent the operator issue use or groups. $selector = "(ref|title|type|version%=$q), (state=$q)" https://processwire.com/api/selectors/#or-groups Edit: To search for each word independent you need to define it that way: $qs = explode(" ", $q); $fields = explode("|", "ref|title|type|version|state"); foreach($fields as $f){ $group = array(); foreach($qs as $q){ $group[] = "$f%=$q"; } $selector .= ", (".implode(", ", $group).")"; } resulting in (ref%=this, ref%=that), (title%=this, title%=that), … 5 Link to comment Share on other sites More sharing options...
heldercervantes Posted May 1, 2015 Author Share Posted May 1, 2015 Awesome! Thanks for the code. Am I limited to searching for exact matches on FieldtypeSelects? Let's say an option such as "brand new", checked against only "new" as the keyword. Is it possible? Link to comment Share on other sites More sharing options...
LostKobrakai Posted May 1, 2015 Share Posted May 1, 2015 Depends on how which Select you're using. The 3rd party module FieldtypeSelect or FieldtypeOptions or by pages? Link to comment Share on other sites More sharing options...
heldercervantes Posted May 1, 2015 Author Share Posted May 1, 2015 I'm using FieldtypeSelect Link to comment Share on other sites More sharing options...
LostKobrakai Posted May 1, 2015 Share Posted May 1, 2015 Than yes you're limited to this ooperator. I'd suggest using FieldtypeOptions or pages, which are the more powerful options. Link to comment Share on other sites More sharing options...
heldercervantes Posted May 1, 2015 Author Share Posted May 1, 2015 Thanks LostKobrakai, I'll look into those. Link to comment Share on other sites More sharing options...
diogo Posted May 2, 2015 Share Posted May 2, 2015 Hélder, before you choose FieldtypeOptions over pages (and may be the best option, depending on how simple is your task), make sure you understand the full potencial and flexibility that pages provide even when used for a simple dropdown select. You'll get it as soon as the weird factor goes away Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now