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

Custom indexes not used by all entry fields #11308

Open
efc opened this issue Jan 2, 2025 · 1 comment
Open

Custom indexes not used by all entry fields #11308

efc opened this issue Jan 2, 2025 · 1 comment
Labels

Comments

@efc
Copy link

efc commented Jan 2, 2025

Bug description

If I use the "select" or "typeahead" UI Mode for an Entry Field, then custom indexes don't seem to be consulted when selecting entries. Note that custom indexes are consulted when using the "stack" UI Mode.
This is probably a limitation of the kind of UI element being used for "select" and "typeahead" presentations, both of which seem to use variations of a dropdown select field. These usually only allow selection by the text shown in the field, which seems to be the "title" field.
It would be great if the custom indexes would work, or if, alternatively, a way were provided to define fields to be used for the text of these select fields so that they could be more flexible than simple titles.
At a minimum, it would help to have a warning on the UI Mode option that lets users know that only titles will be shown for anything other than "stack" presentations.

How to reproduce

For example, in my case I have Courses that are linked from Student Projects.
In /content/collections/courses.yaml I have...

search_index: courses

To keep this simple, in /config/statamic/search.php I am just trying a transform of the title field

        'courses' => [
            'driver' => 'local',
            'searchables' => 'collection:courses',
            'fields' => ['title'],
            'transformers' => [
                'title' => function ($value, $searchable) {
                    if ($course = $searchable->value('course')) {
                        $value .= ' ' . $course['title'] . ' ' . $course['identifier'];
                    }
                    return $value;
                },
            ],
        ],

And, of course, I have done php please search:update courses to update the index.
But still, when I type one of the identifiers into the a course entry field in a related student projects entry, I get no hits, it just appears to search the titles that are visible in the dropdown.
Screenshot 2025-01-02 at 1 53 04 PM
However, in the list of course entries, I think this search is working, since I can now get hits from text that is not in the course title or slug.
Screenshot 2025-01-02 at 1 53 35 PM
I'd be happy to do something similar to the index transform or to create an alternative calculated field to be used in the select dropdown, but I don't see any way to do that.

Logs

No response

Environment

Environment
Application Name: Tensegrities
Laravel Version: 11.36.1
PHP Version: 8.3.15
Composer Version: 2.8.3
Environment: local
Debug Mode: OFF
URL: mary.test
Maintenance Mode: OFF
Timezone: America/Chicago
Locale: en

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: log
Queue: sync
Session: file

Statamic
Addons: 6
Sites: 1
Stache Watcher: Enabled (auto)
Static Caching: Disabled
Version: 5.45.0 Solo

Statamic Addons
alt-design/alt-redirect: 1.3.3
heidkaemper/statamic-toolbar: 1.3.0
statamic/importer: 1.6.0
statamic/ssg: 3.1.0
stillat/relationships: 2.2.1
trendyminds/statamic-palette: 1.2.1

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

@efc
Copy link
Author

efc commented Jan 2, 2025

By the way, I found a work-around, which is to make title computed and add to it the values I need there. I've created a page_title to hold what used to be in title. I don't know if there are some hidden side effects to computing the title, but it seems to be working for me. I still think some warning in the UI Mode instructions on Entry fields would be helpful.

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

No branches or pull requests

2 participants