formmailer Posted December 22, 2011 Share Posted December 22, 2011 I am using the following find query for the search box on my site: <?php $matches = $pages->find("title|body|summary|headline|fakta~=$q, limit=50, template!=admin, template!=redirect-overview, template!=, template!=redirect-url"); But I would like to have pages with a certain template to have a lower priority. Example: I have a few pages with a template called "links". When searching I want all the results from from all other templates and finally (if I haven't reached the limit of 50) the results with the links template. Would this be possible? /Jasper Link to comment Share on other sites More sharing options...
ryan Posted December 22, 2011 Share Posted December 22, 2011 You could sort by templates_id or parent_id, but so long as you want the results to be keyword relevancy sorted, I think you'd want to exclude a sort parameter and break it into two queries: <?php $limit = 50; $searchFields = "title|body|summary|headline|fakta"; $matches = $pages->find("$searchFields~=$q, limit=$limit, template!=links|admin|redirect-overview|redirect-url"); if(count($matches) < $limit) { $matches->import($pages->find("$searchFields~=$q, template=links, limit=$limit")); } You may also want to create a new field of type 'Cache' to combine your title, body, summary, headline and fakta fields. Call it 'keywords' and add it to your templates being searched. Then you can just search "keywords~=$q", and it may offer some performance benefit (at the cost of database size). I didn't understand the "template!=," part of your query. I'm not sure that does anything since a page can't exist without a template. Also, the "template!=admin" is not necessary unless the user has access to edit pages in the admin. What I mean by that is that the admin pages may show up for you because you are logged in, but those pages won't show up for other users of the site. You may already know this and just don't want those pages to show up even for you, but just wanted to mention it just in case. Link to comment Share on other sites More sharing options...
formmailer Posted December 22, 2011 Author Share Posted December 22, 2011 You could sort by templates_id or parent_id, but so long as you want the results to be keyword relevancy sorted, I think you'd want to exclude a sort parameter and break it into two queries. That's a great idea, Ryan. I'll break it in two like you suggested queries. You may also want to create a new field of type 'Cache' to combine your title, body, summary, headline and fakta fields. Call it 'keywords' and add it to your templates being searched. Then you can just search "keywords~=$q", and it may offer some performance benefit (at the cost of database size). I have never looked at the cache fieldtype, but it seams very usefull here. Going to try that out. I didn't understand the "template!=," part of your query. Haha, that makes two of us... I don't know how it came in there... i suppose it was a "copy 'n paste" error. Also, the "template!=admin" is not necessary unless the user has access to edit pages in the admin. What I mean by that is that the admin pages may show up for you because you are logged in, but those pages won't show up for other users of the site. You may already know this and just don't want those pages to show up even for you, but just wanted to mention it just in case. Yeah, I knew that, but my test searches gave so many admin results that I wanted to excluded them even for me, at least for the time being. /Jasper Link to comment Share on other sites More sharing options...
formmailer Posted December 22, 2011 Author Share Posted December 22, 2011 I just tried the cache field and it works fine, but there seems to be an encoding problem. One of the included fields contains the text "Stöllet, Värmland". In the cache field it's written: St\u00f6llet, V\u00e4rmland. When searching for Värmland there are no results. Searching for V\u00e4rmland, works, but it's very unlikely that a user searches for this. /Jasper Link to comment Share on other sites More sharing options...
ryan Posted December 22, 2011 Share Posted December 22, 2011 I see what you mean. Well the good news is, they've fixed this in PHP 5.4 and given us the JSON_UNESCAPED_UNICODE option. But nobody's running 5.4 yet (it's in RC3). Sorry to send you on a wild goose chase, but I'm thinking it may be best to hold off on the cache field in your situation. Meanwhile, I'll keep an eye on alternate encoding methods to see if there's any other approaches we might use, at least until PHP 5.4 is mainstream. Link to comment Share on other sites More sharing options...
formmailer Posted December 22, 2011 Author Share Posted December 22, 2011 Hi Ryan, Thanks for the quick reply. It's good to know that it will be solved in PHP 5.4, although it will take some time before it becomes mainstream. Until that time I'll running without the cache field. /Jasper 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