Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit result with SQL if property 'sortBy' is used #66

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

halftrainedharry
Copy link

The way the search is currently implemented can be very inefficient.
By default, all matching resources are returned by SQL and then array_slice() is used in PHP for the paging.
This makes sense, if the matching resources are sorted by relevance in PHP (which is the default), but is unnecessary if the &sortBy property is used (and the results are already sorted in SQL).


If "SimpleSearch" is used on a bigger site in combination with a commonly used word as the search term, the amount of matching resources can create a "memory limit error".
https://community.modx.com/t/diagnosing-simplesearch-memory-limit-error/5700

This PR adds a way to avoid this (while still allowing the use of the relevance sorting in PHP for smaller search results).

[[!SimpleSearch?
    ...
    &maxCountPhpSort=`200`
    &fallbackSortBy=`createdon`
]]

With a snippet tag like this, the relevance sorting in PHP is used, if the total amount of matching resources is less than 200.
For a larger amount of matching resources, the result is sorted and limited with SQL (using the value from the property &fallbackSortBy for the sorting).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant