Robin S Posted March 1, 2015 Share Posted March 1, 2015 The selector operator ~= matches words in any position, but it doesn't match partial words (e.g. search for "crab" does not match "crabapple"). The selector operator %= matches partial words, but if there are two or more words in the search query then the words need to be next to each other and in that order (i.e. search for "crab red" does not match "red crabapple"). Is there a selector operator or technique that allows matches for partial words in any position/order? Also, the search should match all words rather than any word. My aim is for a search such that searching for "crab red" in the title field... matches a page with title "red shiny crabapple" does not match a page with title "crab" (all words must be present) Link to comment Share on other sites More sharing options...
WillyC Posted March 1, 2015 Share Posted March 1, 2015 u uses title 2 time like.this title%=red, title%=crap If.u no want crap buts do.want reddish crapapples do this title%=red, title%=crap, !title~=crap 10 Link to comment Share on other sites More sharing options...
Robin S Posted March 2, 2015 Author Share Posted March 2, 2015 Great, thanks. I used explode to get the individual words from the search query and then a foreach to build the selector. $selector = ''; if($input->get->general_search) { $value = $sanitizer->selectorValue($input->get->general_search); $terms = explode(" ", $value); foreach($terms as $term) { $selector .= "title|author|source|keywords|bibliography_type%=$term, "; } $input->whitelist('general_search', $value); } 4 Link to comment Share on other sites More sharing options...
sarah_hue Posted March 21, 2015 Share Posted March 21, 2015 Hi, thanks for giving the example you used, Cerulean! I realised an unwanted behaviour and don't know how to solve this: If you search for "test", also "latest" or "contest" will be among the results. So I'd like to make sure the search term ("test") is prepended or followed by a space: $selector .= "title%=' $term', "; $selector .= "title%='$term ', "; However, this does not have any effect on the SQL query and the results. (Same if you put "title%= $term, " without the ' ' quotation marks.) Any ideas? Link to comment Share on other sites More sharing options...
diogo Posted March 21, 2015 Share Posted March 21, 2015 Sarah, in your case, the selector ~= should work title~=$term 1 Link to comment Share on other sites More sharing options...
Robin S Posted March 21, 2015 Author Share Posted March 21, 2015 @sarah_hue Also, if you're not wanting to match partial words you don't need to do the explode/foreach. The ~= operator will match multiple whole words in any order. 1 Link to comment Share on other sites More sharing options...
sarah_hue Posted April 8, 2015 Share Posted April 8, 2015 Oh well, I just read my last post again. Looks I got really confused with word beginnings and endings, that one doesn't really make sense. But somehow you got exactly what I wanted to say (and didn't manage to)! Sarah, in your case, the selector ~= should work Also, if you're not wanting to match partial words you don't need to do the explode/foreach. The ~= operator will match multiple whole words in any order. Excellent, thanks a lot! 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