How to differentiate between positive and negative numbers in search I discovered today that searching a custom field for a number will return results containing either the positive or negative versions of the number, even if I do an exact search. For example: fieldName::"-2" will give me entries where that field contains either "2" or "-2". Same result if I search for fieldName::"2". The field in question is a "number" field.

Is there any workaround for this?
The reason it's happening:

When Craft's SearchService indexes the keywords for a field, they go though a normalization process that specifically removes punctuation and diacritics before being saved to the craft_searchindex table in the database.

In the case of numeric values, that's going to include things like decimals, grouping separators and negation symbols.

A workaround if you're doing this on a front-end search form, is to query the field's value directly, bypassing the SearchService. So...

{% set results = craft.entries.fieldName('-2').find() %}


Which is going to try and do a direct match against that field's actual value in the craft_content table.

There are a few feature requests you might want to add your voice to that would make your situation better as well:

https://github.com/craftcms/cms/issues/1630

https://github.com/craftcms/cms/issues/833