Skip to main content
Version: Current

Search Types

  • EraseDocumentResult

    Defines the result of an erase document operation.

  • RecordSearchCollectionRequest

    Defines an interface that represents a request for recordSearchCollection.

    Members

    • address string

      The address that the collection should be recorded to.

    • markers? string[]

      The markers that should be applied to the collection.

    • recordName string

      The name of the record that the collection should be recorded to.

    • schema SearchCollectionSchema

      The schema that should be used for the collection.

  • RecordSearchDocumentRequest

    Defines an interface that represents a request for recordSearchDocument.

    Members

  • SearchCollectionField

    Defines a field for a search collection schema.

    Members

    • facet? boolean

      Enables faceting on the field.

      Defaults to false.

    • index? boolean

      When set to false, the field will not be indexed in any in-memory index (e.g. search/sort/filter/facet). Default: true.

    • infix? boolean

      When set to true, the field value can be infix-searched. Incurs significant memory overhead. Default: false.

    • locale? string

      For configuring language specific tokenization, e.g. jp for Japanese. Default: en which also broadly supports most European languages.

    • optional? boolean

      When set to true, the field can have empty, null or missing values. Default: false.

    • sort? boolean

      When set to true, the field will be sortable. Default: true for numbers, false otherwise.

    • stem? boolean

      Values are stemmed before indexing in-memory. Default: false.

    • store? boolean

      When set to false, the field value will not be stored on disk. Default: true.

    • type ("string" | "object" | "float" | "auto" | "string[]" | "int32" | "int32[]" | "int64" | "int64[]" | "float[]" | "bool" | "bool[]" | "geopoint" | "geopoint[]" | "geopolygon" | "object[]" | "string*" | "image")

      The type of the field.

  • SearchCollectionSchema

    Defines the schema for a search collection.

    Members

  • SearchDocument

    Defines a document that can be stored in a search collection.

    Members

    • Index Signature

      The properties of the document.

      [key: string]: any
    • id? string

      The ID of the document. If not provided, a new ID will be generated.

  • SearchHighlight

    Defines the interface for a search highlight returned by the search engine.

    Members

    • field string

    • indices [number, number]

    • matchedTokens (string[] | string[][])

    • snippet string

    • snippets? string[]

    • value? string

  • SearchHit

    Defines the interface for a search hit returned by the search engine.

    Members

  • SearchNode

    Defines a node that search clients can use to connect to the search engine.

    Members

    • host string

      The host of the node.

    • port number

      The port number of the node.

    • protocol? ("http" | "https")

      The protocol to use when connecting to the node.

  • SearchQuery

    Defines a search query that can be used to search through documents in a collection.

    Members

    • Index Signature

      A parameter that controls the search query.

      [key: string]: any
    • filterBy? string

      Filter conditions for refining your search results.

      A field can be matched against one or more values.

      Examples:

      • country: USA
      • country: [USA, UK] returns documents that have country of USA OR UK.

      Exact vs Non-Exact Filtering:

      To match a string field's full value verbatim, you can use the := (exact match) operator. For eg: category := Shoe will match documents with category set as Shoe and not documents with a category field set as Shoe Rack.

      Using the : (non-exact) operator will do a word-level partial match on the field, without taking token position into account (so is usually faster). Eg: category:Shoe will match records with category of Shoe or Shoe Rack or Outdoor Shoe.

      Tip: If you have a field that doesn't have any spaces in the values across any documents and want to filter on it, you want to use the : operator to improve performance, since it will avoid doing token position checks.

      Escaping Special Characters:

      You can also filter using multiple values and use the backtick character to denote a string literal: category:= [Running Shoes, Men, Sneaker (Men), Boots].

      Negation:

      Not equals / negation is supported via the :!= operator, e.g. author:!=JK Rowling or id:!=[id1, id2]. You can also negate multiple values: author:!=[JK Rowling, Gilbert Patten]

      To exclude results that contains a specific string during filtering you can do artist:! Jackson will exclude all documents whose artist field value contains the word jackson.

      Numeric Filtering:

      Filter documents with numeric values between a min and max value, using the range operator [min..max] or using simple comparison operators >, >=, <, <=, =.

      You can enable "range_index": true on the numerical field schema for fast range queries (will incur additional memory usage for the index though).

      Examples: -num_employees:<40 -num_employees:[10..100] -num_employees:[<10, >100] -num_employees:[10..100, 140] (Filter docs where value is between 10 to 100 or exactly 140). -num_employees:!= [10, 100, 140] (Filter docs where value is NOT 10, 100 or 140).

      Multiple Conditions:

      You can separate multiple conditions with the && operator.

      Examples:

      • num_employees:>100 && country: [USA, UK]
      • categories:=Shoes && categories:=Outdoor

      To do ORs across different fields (eg: color is blue OR category is Shoe), you can use the || operator.

      Examples:

      • color: blue || category: shoe
      • (color: blue || category: shoe) && in_stock: true

      Filtering Arrays:

      filter_by can be used with array fields as well.

      For eg: If genres is a string[] field:

      • genres:=[Rock, Pop] will return documents where the genres array field contains Rock OR Pop.
      • genres:=Rock && genres:=Acoustic will return documents where the genres array field contains both Rock AND Acoustic.

      Filtering Nested Arrays of Objects:

      When filtering on fields inside nested array objects, you need to use a special syntax to ensure the filters are applied to the same object within the array. The syntax is: <nested_field_parent>.{<filter_conditions>}.

      For eg, if you have a document like this:

       {"name": "Pasta", "ingredients": [ {"name": "cheese", "concentration": 40}, {"name": "spinach", "concentration": 10} ] }
      

      To filter on all dishes that have cheese with a concentration of less than 30, you would do:

       filter_by: ingredients.{name:=cheese && concentration:<30}
      

      Prefix filtering:

      You can filter on records that begin with a given prefix string like this:

      company_name: Acm*

      This will will return documents where any of the words in the company_name field begin with acm, for e.g. a name like Corporation of Acme.

      You can combine the field-level match operator := with prefix filtering like this:

      name := S*

      This will return documents that have name: Steve Jobs but not documents that have name: Adam Stator.

      Geo Filtering:

      Read more about GeoSearch and filtering in this dedicated section.

      Embedding Filters in API Keys:

      You can embed the filter_by parameter (or parts of it) in a Scoped Search API Key to set up conditional access control for documents and/or enforce filters for any search requests that use that API key. Read more about Scoped Search API Key in this dedicated section.

    • q string

      The query text to search for in the collection.

      Use q: "*" (wildcard operator) as the search string to return all documents. This is typically useful when used in conjunction with filter_by.

      For example, to return all documents that match a filter, use: q=*&filter_by=num_employees:10.

      Surround words with double quotes to do an exact phrase search. Eg: Setting q to "tennis ball" (including the surrounding double quotes) will only return documents that have those two words in that exact order, without any typo tolerance.

      To exclude words in your query explicitly, prefix the word with the - operator, e.g. q: 'electric car -tesla'.

    • queryBy string

      One or more field names that should be queried against.

      Separate multiple fields with a comma: company_name, country.

      The order of the fields is important: a record that matches on a field earlier in the list is considered more relevant than a record matched on a field later in the list. So, in the example above, documents that match on the company_name field are ranked above documents matched on the country field.

      Only string and string array fields can be used for full-text search in the query_by parameter. When you specify an object or object array field, Typesense uses the object(s)' children's string and string array fields automatically. You can read more about nested object fields here.

  • SearchRecordOutput

    Defines a record that represents a collection of documents that can be searched.

    Members

    • address string

      The address of the record.

    • collectionName string

      The name of the collection that this search record is attached to.

    • markers string[]

      The markers that are associated with the record.

    • nodes? SearchNode[]

      The search nodes that should be used by clients to connect to the search engine.

    • schema? SearchCollectionSchema

      The schema that is defined in the schema.

    • searchApiKey string

      The API key that is used to query the collection.

  • StoreDocumentResult

    Defines the result of an store document operation.