Merge pull request #31951 from narthollis/lunr-add-term-presence-constants

Lunr - Add Query.presence constants, Update term method arguments
This commit is contained in:
Ron Buckton
2019-01-22 09:41:11 -08:00
committed by GitHub
2 changed files with 35 additions and 1 deletions
+25 -1
View File
@@ -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,
@@ -598,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
@@ -611,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 {
+10
View File
@@ -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() {