Jump to content

Selector Functionality for search


Alex CA
 Share

Recommended Posts

In my search.php template, I am using 

$selector = "title|body%=$search_term, limit=50"; to find the top 50 search results for the page.

I implemented this following this link https://processwire.com/api/selectors/

My question is how does the selector sort its results? Does it look at the number of time the $search_term has occurred in the page or does it start searching from the root page to all the children.

Also, will this change if I do not put any limits to the search results?

 

Link to comment
Share on other sites

26 minutes ago, Alex CA said:

My question is how does the selector sort its results?

From the documentation you linked to:

Quote

How results are sorted if you don't specify a "sort" in your selector
In $page->children() and $page->siblings() the results are automatically sorted by the page's default sort field that you specify in the admin. If not specified in the admin, the pages will be sorted by the order they are placed in the admin. This behavior can be overridden by specifying your own "sort=[property]". With $pages->find() and $page->find(), if you don't specify your own "sort=[property]", the results are sorted according to MySQL's text searching relevance. If no text searches are performed in your find(), the results are unsorted. As a result, it is generally a good idea to include a "sort=[property]" when using $pages->find(), especially if you care about the order and your find() operation is not text/relevance related.

https://processwire.com/api/selectors/#sort

Edited by Robin S
@Zeka, snap!
  • Like 1
  • Thanks 1
  • Haha 1
Link to comment
Share on other sites

How results are sorted if you don't specify a "sort" in your selector

In $page->children() and $page->siblings() the results are automatically sorted by the page's default sort field that you specify in the admin. If not specified in the admin, the pages will be sorted by the order they are placed in the admin. This behavior can be overridden by specifying your own "sort=[property]". With $pages->find() and $page->find(), if you don't specify your own "sort=[property]", the results are sorted according to MySQL's text searching relevance. If no text searches are performed in your find(), the results are unsorted. As a result, it is generally a good idea to include a "sort=[property]" when using $pages->find(), especially if you care about the order and your find() operation is not text/relevance related.

  • Like 2
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...