3

My client's Craft 2 site includes several templates which use search functions to return a product entry by an ID, like so:

{% set product = craft.entries.section('Product')
    .search('externalidentifier::' ~ craft.request.getParam('eid'))
    .one() %}

This has been working without issue.

They just upgraded to Craft 3 however, and now these search functions don't work. As a troubleshooting step, it works for me if I manually loop through all entries and grab the matching item as shown here:

              {% set eid = craft.request.getParam('eid') %}
              {% for prod in craft.entries.section('Product').all() %}
                  {% if prod.extenralidentifier == eid %}
                  {%     set product = prod %}
                  {% endif %}
              {% endfor %}

...but that only illustrates that the matching entries do exist and should be found with the search function. Any ideas why the search function would stop working after an upgrade to Craft 3?

2 Answers 2

2

The search parameter relies on the internal search index (whereas your other approach does not).

It's possible that something got tripped up during a migration to Craft 3, perhaps when the new drafts & revisions system was introduced.

Try rebuilding your search index. It might take a long time to run, but should hopefully solve your problem.

1
  • Thank you, that worked, more info below. Note that I upvoted, but I just joined so it's not showing.
    – Dan Madoni
    Commented Oct 30, 2020 at 10:28
2

Lindsey D's answer above worked for me, the stumper for me was that the Rebuild Search Indexes feature that used to be in the Settings menu in Craft 2 is no longer there in Craft 3, (there is an Asset Indexes page in the Utilities menu, but that's not what we need here).

So to rebuild the search index in Craft 3, I needed to do this:

  1. In a command window, move to your Craft root, i.e. (Windows)
cd \inetpub\wwwroot\mycraftsite
  1. Run the following command
php craft resave/entries --update-search-index

References:

If there actually is a way to do this without resorting to console commands in Craft 3, please comment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.