Query

The Query object configures what and how to search. At minimum, provide search text and a max results count.

Constructor

csharp
var query = new Query("search text", maxResults);

Full Configuration

csharp
var query = new Query("search text", maxResults)
{
    EnableCoverage  = true,              // default: true
    CoverageDepth   = 500,               // default: 500
    CoverageSetup   = coverageSetup,     // default: null
    EnableFacets    = false,             // default: false
    EnableBoost     = false,             // default: false
    SortBy          = engine.GetField("rating"), // default: null
    SortAscending   = false,             // default: false
    RemoveDuplicates = true,             // default: true
    Filter          = filter,            // default: null
    Boosts          = boostArray,        // default: null
    FieldBoosts     = new Dictionary<string, float>
    {
        ["title"] = 2.0f                 // multiplies title's Weight; key must be searchable
    },                                   // BM25F mode only, default: null
    KeyExcludeFilter = excludeSet,       // exclude specific document keys
    KeyIncludeFilter = includeSet,       // restrict to specific document keys
    TimeOutLimitMilliseconds = 1000      // default: 1000, max: 10000
};

Properties

PropertyTypeDefaultDescription
Text
string
""
Search text
MaxNumberOfRecordsToReturn
int
—
Maximum results to return
EnableCoverage
bool
true
Enable coverage-based ranking
CoverageDepth
int
500
How many candidate documents coverage evaluates. Hits beyond the depth are never confirmed, so a count landing exactly on the depth is the cap, not the data — see Deep coverage
CoverageSetup
CoverageSetup?
null
Fine-grained coverage configuration
EnableFacets
bool
false
Return facet counts in the result. Also required for an empty Text: without it the empty query is refused, returning an empty Result with a Reason — see Empty search
EnableBoost
bool
false
Apply boosts defined in Boosts
SortBy
Field?
null
Secondary sort field. Score is always the primary key
SortAscending
bool
false
Sort direction when SortBy is set
RemoveDuplicates
bool
true
When documents share a foreign key, return only the best-scoring one. Not a group-by on arbitrary fields — see Variants and editions
Filter
Filter?
null
Boolean filter applied before scoring
Boosts
Boost[]?
null
Score boosts applied to matching documents
FieldBoosts
Dictionary<string, float>?
null
Per-query multipliers on each field's Weight. Keys must be searchable fields — an unknown or non-searchable key makes Search return an empty Result. Only applies in BM25F mode
TimeOutLimitMilliseconds
int
1000
Abort scoring after this many milliseconds. Max: 10000

Per-Query Field Boosts

FieldBoosts lets you adjust how much each field counts for one search, without reconfiguring or rebuilding the index.

csharp
// title and description are both Searchable in the field configuration.
var query = new Query("noise cancelling", 10)
{
    FieldBoosts = new Dictionary<string, float>
    {
        ["title"]       = 3.0f,  // 3 × title's Weight
        ["description"] = 0.5f   // half of description's Weight
    }
};
  • A boost multiplies the field's Weight; it does not replace it. A field with Weight = 2.0f and a boost of 3.0f counts 6×. Fields you leave out keep their Weight (a boost of 1.0). In BM25F terms the boost is folded into the pseudo term-frequency as boost × weight × tf.
  • Every key must be a searchable field. An unknown or non-searchable key makes Search return an empty Result — no records, and today no Reason either, so it looks like a search that matched nothing. The message is on engine.Status.ErrorMessage. Making a field non-searchable does not remove it from boosts your code still sends.
  • Boosts only apply in BM25F mode. Check engine.ScoringMode after Index(). The engine uses BM25F when every searchable field has the same BM25k1 (the default); if they differ it scores fields separately and ignores FieldBoosts — valid keys have no effect, and an invalid key still returns an empty result.

Constructors

csharp
Query()

For serializer.

csharp
Query(string queryText, int maxNumberOfRecordsToReturn)

Constructor for the class Query, having default parameters for most of the fields. This query uses the Coverage function, and times out after 1000 ms. To adjust more parameters, set them directly on the instance after creation.

  • string queryText
  • int maxNumberOfRecordsToReturn

Properties

NameTypeAccessDescription
Boosts
Boost[]
get/set
is the method to pass the list of boosts to be applied during the search.
CoverageDepth
int
get/set
The number of results from the pattern matcher to be considered by Coverage.
CoverageSetup
CoverageSetup
get/set
Field that controls behavior of the Coverage algorithms. Have no effect for other algorithms.
DocumentsBoosted
int
get
Returns the number of documents that may be boosted in the search.
EnableBoost
bool
get/set
Is used to toggle boosted searches on or off.
EnableCoverage
bool
get/set
Coverage is a function that detects exact matching on tokens in the query, and lifts them up to the top of the result list. If set to false, the search will run with pattern recognition (Relevancy Ranking) only. When Coverage is active, the search result will also return an index number to truncate the list on.
EnableFacets
bool
get/set
Activates calculations of facet histograms in the search results.
FieldBoosts
Dictionary<string, float>
get/set
Per-field BM25F boost factors applied at query time. Key = field name (must match a searchable field name). Value = multiplicative boost for that field's contribution to pseudo_tf. Fields not listed default to 1.0. Typical range: 0.5–3.0. Values below 1.0 de-emphasize a field; values above ~5.0 tend to overwhelm the IDF component and reduce result quality. Example: { "title": 2.0f, "body": 1.0f } doubles the title field's influence.
Filter
Filter
get/set
Is used to pass a filter to the search query.
LogPrefix
string
get/set
If the instance of the search engine has had a logger injected into its constructor, every search will be logged. The log prefix is then first added to the log text, and can be used by the client to add statistical information, for example for use in dashboards.
MaxBoost
int
get/set
Denotes the maximum possible boost that can be assigned. A hit with full boost gets the top score, 65 535; a full unboosted score is 65 535 - MaxBoost · 257.
MaxNumberOfRecordsToReturn
int
get/set
Defines the maximum number of documents to be returned.
RemoveDuplicates
bool
get/set
Removes all duplicates of documents with the same foreign key. Only the one with the best score value is returned in the results list. If foreign keys are not in use, this can be set to null.
SerializedQueryKey
string
get
Serialized key for caching empty search results. Format: F:{filterKey}|B:{boostFilter1};{strength1},{boostFilter2};{strength2}|S:{sortField};{asc}|M:{maxRecords}|E:{enableFacets}
SortAscending
bool
get/set
Only applicable if SortBy != null.
SortBy
Field
get/set
Use this in order to setup sorting of the results.
Text
string
get/set
Refers to the text (input) to be searched for.
TimeOutLimitMilliseconds
int
get/set
Sets maximum waiting time in case of overloaded CPU. We recommend 1000 ms. Cannot be more than 10000 ms.