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)
craft.entries.section('products').search('productName:'~ query ~' OR productDescription:'~ queryand it also returns the product matching on relatedProducts. In fact it seems adding anyORin there makes it search every field. In the documentation, theORexamples searches for two different words, but always within the same field, likebody:salty OR body:dogandbody:salty -body:dog. So maybe this approach is not even supported. – oyvind-redrabbits Aug 28 '14 at 05:59