craftcms / cms

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

[5.x]: Default title field not being indexed for entry types #15025

Closed pascalminator closed 3 months ago

pascalminator commented 4 months ago

What happened?

Description

The default title field is being indexed correctly for sections, and I can search and get results appropriately. However, the same default title field is not being indexed when used inside an entry type for a Matrix block (see attached screenshot below for better context).

Steps to reproduce

  1. Add an entry type to a section and keep the default title field.
  2. Save any value in the title field.
  3. Try to search for the value saved in the title field.
  4. No results are found for the title field within the Matrix block entry type.

Expected behavior

All "title" fields should be indexed, no matter where they are used. Ideally, the system should index the title fields within Matrix blocks just as it does for sections. Alternatively, there should be an option to control this indexing behavior with a checkbox, similar to custom fields.

Actual behavior

The default title field within Matrix block entry types is not being indexed, preventing searches from returning results for values in these title fields.

index-issue-title

Craft CMS version

5.1.3

PHP version

8.2

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

No response

i-just commented 4 months ago

Hi, thanks for reaching out. The title field is always indexed, even for the entries inside a matrix field.

For example, I have a top-level entry titled “vegetables” with a CKEditor and Matrix fields in it (both have “Use this field’s values as search keywords” off). CKEditor has a nested entry titled “carrots”, and the matrix field has two nested entries titled “broccoli” and “okra”; all 4 keywords are showing in the searchindex table.

Screenshot 2024-05-20 at 10 31 31

In the control panel > Entries > All, I can search for “vegetables” and get one entry as a result, but searching for “broccoli” returns zero results. This is expected behaviour as the control panel search will search for the entries in the specified sections, and the nested entries don’t belong to a section.

There’s also this discussion, which you might find helpful. It clarifies the opposite of the behaviour you’re describing: https://github.com/craftcms/cms/discussions/14978.

I hope this helps!

I’ll close this now, but feel free to reply if you run into any further problems.

pascalminator commented 4 months ago

This situation is problematic for the search feature on the front-end in my eyes. The only workaround I've found is to disable the default title field and create a custom title field with the "Use this field’s values as search keywords" checkbox checked.

For example, I created a matrix to manage the content of my "about" page. However, I can't get search results for "Christine Tremblay" (because it's using the default title field), while I can get results for "Directrice générale" (because it's a custom field with "Use this field’s values as search keywords" enabled).

This discrepancy means that default title fields within Matrix blocks are not behaving as expected in search functionality, leading to incomplete search results.

image image image

This problem makes the default title field pointless for many user cases IMHO. Replacing it with a custom title field fixes my problem, but I'd rather use the default field because, well, it's already there.

Thank you for your time and sorry if I don't get it maybe?

brandonkelly commented 3 months ago

I was able to reproduce this, and fixed for the next release.

Realized there’s a related bug, where entries’ search indexes don’t get updated automatically for nested entries within Matrix fields, when the nested entries are edited directly. That’s fixed as well, but for Craft 5.2+ since the fix was a bit involved (a7d1780075100d6073f2c1a323bb32a4c91ed331).

brandonkelly commented 3 months ago

Craft 5.1.8 is out with that fix. Thanks again!

pascalminator commented 3 months ago

I can confirm the problem is fixed now, after updating Craft to 5.1.8. Right in time to deploy this site in production!