craftcms / cms

Build bespoke content experiences with Craft.
https://craftcms.com
Other
3.28k stars 634 forks source link

Unexpted search results when looking for exact match #3474

Closed 3dgroup closed 6 years ago

3dgroup commented 6 years ago

Description

When doing an exact search unexpected results appear. EG if i have a field with OSCA3 but search 'sku::"OSCA"' i shouldn't expect the entry with OSCA3 to appear but it does. Having looked at the DB query craft adds a % to the end of the string resulting in the search returning anything starting with OSCA. But the double quotes should return only fields that have an exact match.

Steps to reproduce

  1. Add text field called sku and add to section
  2. Create multiple entries with data such as OSCA1, OSCA2, OSCA3
  3. PHP Query: \craft\elements\Entry::find()->search('sku::"osca"')->all()
  4. Should return nothing, but instead it will return all 3 entries due to resulting query: SELECT elementId FROM searchindex WHERE ((fieldId = '35') AND (keywords LIKE ' osca%')) AND (siteId=1)

Additional info

Possible Cause

Setting subRight to false resolves the issue but that might cause an issue for non-quoted searches, so the bug is probably "subLeft and subRight should be ignored for exact match searches"

angrybrad commented 6 years ago

Guessing the issue is that subLeft and subRight should be ignored in exact match tokens.

brandonkelly commented 6 years ago

Fixed for tomorrow’s release. Thanks for reporting!