Webrocker Posted August 20, 2016 Share Posted August 20, 2016 Hi, is it possible to have the result of an "search" selector like this one $matches = $pages->find('template=basic-page|journal__item|link__item,title|heading|subheading|excerpt|body%=' . $sq,limit=50); ordered by the number of matches, so that the pages where the searched term was found more often will be the first in the listing? (I don't think so, since the "%=......" looks for an occurance, and that's it, and since the fields are coupled with an "or", no info on how many times the searched term was found is available, right? -- but too often ProcessWire surprised me with its cleverness, so I thought I ask :-)) cheers, Tom Link to comment Share on other sites More sharing options...
Juergen Posted September 9, 2016 Share Posted September 9, 2016 It would be great if this kind of search would be possible (like in Joomla Search engines). Fe check first in headlines, second in introtext, third in body. Result order depending on the matches found in the fields. Matches in headlines are higher ranked than in introtext than in body field. Unfortunately I have also no idea how to realize such a search ranking. Maybe someone has found a working solution and will post it here. Link to comment Share on other sites More sharing options...
Soma Posted September 9, 2016 Share Posted September 9, 2016 As far as I know a fulltext search with ~= or *= will return results by relevance/score that's built in mysql. But %= is wildcard like search not fulltext. I'm not sure that's by relevance in order of search fields. For far more powerful search that's also fast on very large scale can do fuzzy searches etc, one would have to consider using a tool like apache lucene or elastic search or alike. 1 Link to comment Share on other sites More sharing options...
Robin S Posted September 9, 2016 Share Posted September 9, 2016 @Juergen: At the cost of a couple of extra DB queries, you can use my new favourite tool Paginator: (thanks @LostKobrakai) include 'src/Paginator.php'; include 'src/PagesPaginator.php'; $paginator = new PagesPaginator(); $result = $paginator(array( "headline~=$q", "introtext~=$q", "body|whatever~=$q" ), $input->pageNum, 25); 3 Link to comment Share on other sites More sharing options...
LostKobrakai Posted September 10, 2016 Share Posted September 10, 2016 It's not even running all supplied queries if it doesn't need to. So it's should actually be quite performant in that regard. 3 Link to comment Share on other sites More sharing options...
Juergen Posted September 10, 2016 Share Posted September 10, 2016 9 hours ago, Robin S said: $result = $paginator(array( "headline~=$q", "introtext~=$q", "body|whatever~=$q" ), $input->pageNum, 25); How can I disable some templates from the search? Is this the right way to exclude the template "profile" from the search results? $result = $paginator(array("template!='profile'", "headline~=$q", "introtext~=$q", "body|whatever~=$q" ), $input->pageNum, 25); Link to comment Share on other sites More sharing options...
Robin S Posted September 10, 2016 Share Posted September 10, 2016 Each item in the paginator array is a separate selector for a $pages->find() operation - the results are concatenated together for pagination. So just include or exclude templates for any selector in the array like you would normally for $pages->find($selector). So for your example: $result = $paginator(array( "headline~=$q, template!=profile", "introtext~=$q, template!=profile", "body|whatever~=$q, template!=profile" ), $input->pageNum, 25); 2 Link to comment Share on other sites More sharing options...
Juergen Posted September 10, 2016 Share Posted September 10, 2016 Oh I understand the functionality behind the scenes ! Thanks for the explanation. Link to comment Share on other sites More sharing options...
Juergen Posted September 10, 2016 Share Posted September 10, 2016 I have tried to include a repeater field called "downloadrepeater" with the included fields "downloadtitle" and "downloaddesc", but including these fields leads to an error: Exception: Unknown Selector operator: '' -- was your selector value properly escaped? (in /home/.sites/24/site1275/web/wire/core/Selectors.php line 307) I have included these fields like that: "downloadrepeater.downloadfieldtitle|downloadrepeater.downloadfiledesc~=$q" After removing these fields from the search query everthing works fine again. Link to comment Share on other sites More sharing options...
Robin S Posted September 10, 2016 Share Posted September 10, 2016 1 hour ago, Juergen said: I have included these fields like that: "downloadrepeater.downloadfieldtitle|downloadrepeater.downloadfiledesc~=$q" That kind of syntax works fine for me. Try the same selector outside of Paginator to isolate where the problem lies. Link to comment Share on other sites More sharing options...
Juergen Posted September 10, 2016 Share Posted September 10, 2016 Maybe the reason was that I have put the search fields into a string. $downloadfields = "downloadrepeater.downloadfiledesc|downloadrepeater.downloadfieldtitle"; After that I have added this variable to the search tag and then I got the errors. "$downloadfields~=$q" Now I have added it manually to the search string and now everything works fine. "downloadrepeater.downloadfiledesc|downloadrepeater.downloadfieldtitle~=$q" 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