cst989 Posted February 2, 2022 Share Posted February 2, 2022 I would like to sort search results so that those with a specific root parent ID (could be the immediate parent, could be one higher) are prioritised, essentially pinned to the top of the results. How can I do this please? My existing query is very straightforward (using SearchEngine module for index): $pages->find('search_index%=' . $query . ', limit=15'); Essentially what I want is something like this: $pages->find('search_index%=' . $query . ', sort=[has_parent=1234], limit=15'); Thanks. Link to comment Share on other sites More sharing options...
BillH Posted February 2, 2022 Share Posted February 2, 2022 One method would be to combining two finds, something like this: $results = $pages->find("search_index%=$query, has_parent=1234"); $moreResults = $pages->find("search_index%=$query, has_parent!=1234"); $allResults->import($moreResults); $limitedResults = $allResults->slice(0, 15); Note that setDuplicateChecking() can be useful with import() when doing this sort of thing. Perhaps someone else knows how to do this with a single selector! 1 1 Link to comment Share on other sites More sharing options...
cst989 Posted February 2, 2022 Author Share Posted February 2, 2022 Ah yes, that's something I thought of and an elegant solution. But yeah a single selector I think is something I need, as unfortunately there's one additional thing I should've mentioned in the original post, I need to render pagination! And I don't think that will play nicely with combining queries and slices. Link to comment Share on other sites More sharing options...
BillH Posted February 2, 2022 Share Posted February 2, 2022 I didn't think of pagination! You could make the last line a find() and, though I haven't tried this, you might be OK. $limitedResults = $allResults->find('limit=15'); echo $limitedResults->render(); 1 Link to comment Share on other sites More sharing options...
cst989 Posted February 3, 2022 Author Share Posted February 3, 2022 Thank you, that worked! I wanted to loop through the results to template them manually and for some reason I had to change the following, which did nothing: echo $limitedResults->renderPager(); to $pager = $modules->get("MarkupPagerNav"); echo $pager->render($limitedResults); but otherwise, got there in the end. 1 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