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.
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.
jpfor Japanese. Default:enwhich 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:
truefor numbers,falseotherwise.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
Index Signature
The schema that defines the fields in the search collection.
[key: string]: SearchCollectionField
SearchHit
Defines the interface for a search hit returned by the search engine.
Members
document SearchDocument
highlight SearchHighlight
highlights? SearchHighlight[]
textMatch? number
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]: anyfilterBy? string
Filter conditions for refining your search results.
A field can be matched against one or more values.
Examples:
country: USAcountry: [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 := Shoewill match documents withcategoryset asShoeand not documents with acategoryfield set asShoe 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:Shoewill match records withcategoryofShoeorShoe RackorOutdoor 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 Rowlingorid:!=[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:! Jacksonwill exclude all documents whose artist field value contains the wordjackson.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": trueon 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
genresis astring[]field:genres:=[Rock, Pop]will return documents where the genres array field containsRock OR Pop.genres:=Rock && genres:=Acousticwill return documents where the genres array field contains bothRock 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_namefield begin withacm, for e.g. a name likeCorporation 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 Jobsbut 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_byparameter (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 withfilter_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
qto"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_namefield 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_byparameter. 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.