From 838a4ccb8122e160b5e9b1b0f70122b09cdb8451 Mon Sep 17 00:00:00 2001 From: Nicholas Steicke Date: Tue, 8 Jan 2019 08:46:22 +1030 Subject: [PATCH 1/3] Add lunr.Query.presence constants --- types/lunr/index.d.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/types/lunr/index.d.ts b/types/lunr/index.d.ts index 415c7c1d8f..f542280df3 100644 --- a/types/lunr/index.d.ts +++ b/types/lunr/index.d.ts @@ -535,6 +535,24 @@ declare namespace lunr { } namespace Query { + /** + * Constants for indicating what kind of presence a term must have in matching documents. + */ + enum presence { + /** + * Term's presence in a document is optional, this is the default value. + */ + OPTIONAL = 1, + /** + * Term's presence in a document is required, documents that do not contain this term will not be returned. + */ + REQUIRED = 2, + /** + * Term's presence in a document is prohibited, documents that do contain this term will not be returned. + */ + PROHIBITED = 3 + } + enum wildcard { NONE = 0, LEADING = 1 << 0, From 3f322082f0ab2373af8199e473b259a380c06358 Mon Sep 17 00:00:00 2001 From: Nicholas Steicke Date: Tue, 8 Jan 2019 08:47:39 +1030 Subject: [PATCH 2/3] Update lunr.Query.prototype.term to accept arrays and Token objects --- types/lunr/index.d.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/types/lunr/index.d.ts b/types/lunr/index.d.ts index f542280df3..ab59d556f6 100644 --- a/types/lunr/index.d.ts +++ b/types/lunr/index.d.ts @@ -616,6 +616,12 @@ declare namespace lunr { * Adds a term to the current query, under the covers this will create a {@link lunr.Query~Clause} * to the list of clauses that make up this query. * + * The term is used as is, i.e. no tokenization will be performed by this method. Instead conversion + * to a token or token-like string should be done before calling this method. + * + * The term will be converted to a string by calling `toString`. Multiple terms can be passed as an + * array, each term in the array will share the same options. + * * @param term - The term to add to the query. * @param [options] - Any additional properties to add to the query clause. * @see lunr.Query#clause @@ -629,7 +635,7 @@ declare namespace lunr { * wildcard: lunr.Query.wildcard.TRAILING * }) */ - term(term: string, options: object): Query; + term(term: string | string[] | Token | Token[], options: object): Query; } class QueryParseError extends Error { From 314a93b409d40f27ca6ad26021966e8a5f8b5cf2 Mon Sep 17 00:00:00 2001 From: Nicholas Steicke Date: Tue, 8 Jan 2019 09:57:42 +1030 Subject: [PATCH 3/3] Update tests to verify term and Query changes --- types/lunr/lunr-tests.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/types/lunr/lunr-tests.ts b/types/lunr/lunr-tests.ts index a14fd1947f..4d3fa57461 100644 --- a/types/lunr/lunr-tests.ts +++ b/types/lunr/lunr-tests.ts @@ -25,6 +25,16 @@ function basic_test() { }); index.search("foo"); + + index.query(q => { + q.term( + lunr.tokenizer('search terms'), + { + wildcard: lunr.Query.wildcard.TRAILING, + presence: lunr.Query.presence.REQUIRED + } + ); + }); } function pipeline_test() {