Homepage

[DEPRECATED] Narrowing Keyword Search

Last edit: Jan 25, 2024

Warning

This article promotes customizations, listings and people GraphQL queries, which are deprecated due to the limited configuration option. To leverage the power of ElasticSearch, we recommend using JSON Documents, which allows you to define your own ElasticSearch mapping and have full control on what gets stored in the ElasticSearch.

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.

Note

Operator is applied only to the keyword query. It does not affect fields behavior.

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 visit 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.

contact us