<p>The <code>search</code> parameter relies on the internal search index (whereas your other approach does not).</p>
<p>It's possible that something got tripped up during a migration to Craft 3, perhaps when the new drafts &amp; revisions system was introduced.</p>
<p><strong>Try rebuilding your search index.</strong> It might take a long time to run, but should hopefully solve your problem.</p>

CC BY-SA 4.0
2020-10-30T10:28:48.677Z
Thank you, that worked, more info below. Note that I upvoted, but I just joined so it's not showing.
Dan Madoni
CC BY-SA 4.0
2020-10-29T23:41:56.247Z
2020-10-29T23:41:56.247Z
Lindsey D
<p>Lindsey D's answer above worked for me, the stumper for me was that the <strong>Rebuild Search Indexes</strong> 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).</p>
<p>So to rebuild the search index in Craft 3, I needed to do this:</p>
<ol>
<li>In a command window, move to your Craft root, i.e. (Windows)</li>
</ol>
<pre><code>cd \inetpub\wwwroot\mycraftsite
</code></pre>
<ol start="2">
<li>Run the following command</li>
</ol>
<pre><code>php craft resave/entries --update-search-index
</code></pre>
<p>References:</p>
<ul>
<li><a href="https://craftcms.com/docs/3.x/console-commands.html" rel="nofollow noreferrer">https://craftcms.com/docs/3.x/console-commands.html</a></li>
<li><a href="https://craftcms.com/docs/3.x/searching.html#templating" rel="nofollow noreferrer">https://craftcms.com/docs/3.x/searching.html#templating</a></li>
</ul>
<p>If there actually is a way to do this without resorting to console commands in Craft 3, please comment.</p>

CC BY-SA 4.0
2020-10-30T10:35:41.150Z
2020-10-30T11:47:38.927Z
2020-10-30T11:47:38.927Z
Dan Madoni
<p>My client's Craft 2 site includes several templates which use search functions to return a product entry by an ID, like so:</p>
<pre><code>{% set product = craft.entries.section('Product')
    .search('externalidentifier::' ~ craft.request.getParam('eid'))
    .one() %}
</code></pre>
<p>This has been working without issue.</p>
<p>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:</p>
<pre><code>              {% set eid = craft.request.getParam('eid') %}
              {% for prod in craft.entries.section('Product').all() %}
                  {% if prod.extenralidentifier == eid %}
                  {%     set product = prod %}
                  {% endif %}
              {% endfor %}
</code></pre>
<p>...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?</p>

<craft3><templating><search>
Twig search function doesn't work after upgrading to Craft 3
# Twig search function doesn't work after upgrading to Craft 3

(Asked by: username_0 on 2020-10-29)

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?

**Tags:** craft3, templating, search


---

## 2 answers

### Answer by username_1 on 2020-10-29. Score: 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.

> **Comments:**
> **username_0**: Thank you, that worked, more info below. Note that I upvoted, but I just joined so it's not showing.  

---

### Answer by username_0 on 2020-10-30. Score: 2

username_1'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:

In a command window, move to your Craft root, i.e. (Windows)

cd \inetpub\wwwroot\mycraftsite


Run the following command

php craft resave/entries --update-search-index

References:

https://craftcms.com/docs/3.x/console-commands.html
https://craftcms.com/docs/3.x/searching.html#templating

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


---

