0

I've got search working as expected on this site with the following code:

      {% set params = {
        section: 'inventions',
        limit: 10
      } %}

      {% if searchQueryKeywords !="" and searchQueryKeywords != null and searchQueryKeywords !="null" %}
        {% set params = params | merge({
          search:'title:' ~ searchQueryKeywords ~ ' OR summary:' ~ searchQueryKeywords ~ ' OR applications:' ~ searchQueryKeywords ~ ' OR investigators:' ~
          searchQueryKeywords ~ ' OR dbd:' ~
          searchQueryKeywords ~ ' OR caseNumber:' ~ searchQueryKeywords,  })
        %}
      {% endif %}

      {#
      // get related category
      #}
      {% if searchCategory != null and searchCategory !="" %}
        {% set searchQueryCategory = craft.categories.group('researchAreas').slug(searchCategory).one() %}
      {% endif %}

      {% if searchQueryCategory is defined %}
        {% set params = params | merge ({
          relatedTo: [
            'and',
            { targetElement: searchQueryCategory }
          ]
        }) %}
      {% endif %}


      {# set the entries with all the search/fitering params #}
          {% set entries = craft.entries(params) %}

However I now need to prioritize results to show entries that match the DBD entries field at the top. The DBD field is a relationship to a staff channel.

If I search for Grant how can I ensure that results for Grant appear at the top?

0

Your Answer

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

Browse other questions tagged or ask your own question.