Narrowing Keyword Search

By default, keyword search is looking in all fields of the database.

In your GraphQL query, you can specify which fields should be searched in.

If you leave the keyword field empty, it means you are looking for everything, so narrowing by field names will not be applied.

Operator

Operator allows you to control how the query will be understood by our search engine.

For example, the query capital of hungary (subqueries: capital, of, Hungary):

  • With operator set to OR, the query will be translated to capital OR of OR Hungary and will return results that have any of those subqueries.
  • With operator set to AND, the query will be translated to capital AND of AND Hungary and will return results containing all of those subqueries.

Default value is AND.

AND Example

query get_owners {
  people(query: { keyword: "Tanya Rose", operator: AND }) {
    results {
      first_name
      last_name
    }
  }
}
{
  "data": {
    "people": {
      "results": [
        {
          "first_name": "Tanya",
          "last_name": "Rose"
        }
      ]
    }
  }
}

OR Example

query get_owners {
  people(query: { keyword: "Tanya Rose", operator: OR }) {
    results {
      first_name
      last_name
    }
  }
}
{
  "data": {
    "people": {
      "results": [
        {
          "first_name": "Rose",
          "last_name": "Smith"
        },
        {
          "first_name": "Maya-Rose",
          "last_name": "Chauhan"
        }
      ]
    }
  }
}

Filtered fields

To learn more about filtered fields see the Selecting Fields for Search topic.

OR with filtered fields example

query get_providers {
  people(
    query: {
      keyword: "Tanya Rose"
      operator: OR
      fields: [{ name: "last_name" }]
    }
  ) {
    results {
      first_name
      last_name
    }
  }
}
{
  "data": {
    "people": {
      "results": [
        {
          "first_name": "Helena",
          "last_name": "Rose"
        },
        {
          "first_name": "Tanya",
          "last_name": "Rose"
        },
        {
          "first_name": "Annette",
          "last_name": "Rose"
        },
        {
          "first_name": "Alba",
          "last_name": "Spirli-Rose"
        }
      ]
    }
  }
}

AND with filtered fields example

query get_providers {
  people(
    query: {
      keyword: "Tanya Rose"
      operator: AND
      fields: [{ name: "last_name" }, { name: "first_name" }]
    }
  ) {
    results {
      first_name
      last_name
    }
  }
}

Because the above query is asking for users that have "Tanya Rose" in first_name or last_name results will be empty in this case.

{
  "data": {
    "people": {
      "results": []
    }
  }
}

There are no users with "Tanya Rose" in the first_name or last_name fields.

Priority

While defining which fields should be traversed in keyword search you can also force the priority of each field to make sure they will appear higher in search results (they will have higher score).

Questions?

We are always happy to help with any questions you may have. Check out our Help page, or contact us.