/
match-phrase-query-base.js
52 lines (46 loc) · 1.54 KB
/
match-phrase-query-base.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
'use strict';
const MonoFieldQueryBase = require('./mono-field-query-base');
/**
* The `MatchPhraseQueryBase` provides support for common options used across
* various bucket match phrase query implementations.
*
* **NOTE:** Instantiating this directly should not be required.
* However, if you wish to add a custom implementation for whatever reason,
* this class could be extended.
*
* @param {string} queryType
* @param {string} refUrl
* @param {string=} field The document field to query against
* @param {string=} queryString The query string
*
* @extends MonoFieldQueryBase
*/
class MatchPhraseQueryBase extends MonoFieldQueryBase {
// eslint-disable-next-line require-jsdoc
constructor(queryType, refUrl, field, queryString) {
super(queryType, field, queryString);
this._refUrl = refUrl;
}
/**
* @override
* @throws {Error} This method cannot be called on `MatchPhraseQueryBase`
*/
minimumShouldMatch() {
console.log(`Please refer ${this._refUrl}`);
throw new Error(
`minimumShouldMatch is not supported in ${this.constructor.name}`
);
}
/**
* Configures the `slop`(default is 0) for matching terms in any order.
* Transposed terms have a slop of 2.
*
* @param {number} slop A positive integer value, defaults is 0.
* @returns {MatchPhraseQueryBase} returns `this` so that calls can be chained.
*/
slop(slop) {
this._queryOpts.slop = slop;
return this;
}
}
module.exports = MatchPhraseQueryBase;