Is it possible to exclude some fields when using search?
Getting the q parameter from the URL and searching the products section including all fields:
{% set query = craft.request.getParam('q') %}
{% set results = craft.entries.section('products').search(query) %}
This searches all fields, included those for "related articles" and "related products". I need to exclude those from the search.
Some experiments
Works to exclude hits in relatedProducts but limits the fields being searched to the productName field:
craft.entries.section('products').search('productName:'~ query ~' -relatedProducts:'~ query)
Does not work - also returns the product with a related product matching the query:
craft.entries.section('products').search(query ~' -relatedProducts:'~ query)
and the same when trying to include several fields before excluding relatedProducts:
craft.entries.section('products').search('productName:'~ query ~' OR productDescription:'~ query ~' -relatedProducts:'~ query)
Also tried searching just in the relatedProducts, confirming that it returns only the product with a related entry matching the query:
craft.entries.section('products').search('relatedProducts:'~ query)