Keyword search doesn't account for matches in different fields
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 3.6k
- Forks
- 705
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 134
Description
Description
I'm torn between calling this a bug and a FR but this behviour seems unexpected to me: When inputting a keyword search for entries from the front end, matches are only found where the keywords are all within a single field.
Steps to reproduce
- Create an entry with two searchable text fields and populate the first with 'Toyota' and the second with 'Corolla'
- Put this in a template and see that it does not output the entry:
<p>{{ craft.entries.search('Toyota Corolla').one().title ?? 'nope' }}</p>
Most people(?) would probably expect this entry to be successfully returned in such a search. Unfortunately the solution is not as simple as inserting an "OR" in between each keyword, as the search should still be scoped to an individual entry. My workaround is to use a Preparse field that sums together all searchable fields (including relationship fields) into a single hidden field on save, but obviously a first-party solution would be preferable.
Additional info
- Craft version: 3.5.15.1
- PHP version: 7.2
- Database driver & version: MySQL
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the craft.entries.search() entry point and reproduce the query using two searchable text fields containing “Toyota” and “Corolla.” Trace how the search scopes keyword matches to fields, then verify that an entry matching across fields is returned without broadening results beyond the individual entry.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mysql, php
- Domain
- databases, search
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100