We have a job inventory where the jobs are being saved as entries. When searching against jobs by keyword we search against two fields: the title and a job description field.

However we are experiencing some unusual results when using the search parameter to search against the term ".net". For example:

{% set results = craft.entries()
.search('title:".net" OR description:".net"')
.all() %}

Is there a way to use search() to specifically only return entries where the title or description contains .net as at present it is returning partial matches (eg jobs where the title or description features 'networking').

The description field is a redactor/rich text field. Would this affect it?


I don't think it will be possible using the native Craft search engine as part of the search keyword normalization process involves removing all punctuation from the keywords: https://github.com/craftcms/cms/blob/develop/src/helpers/Search.php#L62

It might be possible on front-end searching using something like Algolia, though: https://plugins.craftcms.com/algolia


Many thanks for clarifying Brad - have worked out a solution at a plugin level basically querying the craft content table directly via a database query then passing the corresponding element IDs into my craft.entries call:

$query = (new Query())

    $entryIds = [];
    foreach ($query->all() AS $item) {
        $entryIds[] = (int)$item['elementId'];
    $criteria['id'] = $entryIds
  • PS if you are aware of a way to pass parameters eg [':keywords' => $keywords] into a like DB query then do let me know! Aug 22 '19 at 11:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.