123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- lunr.Query = function (allFields) {
- this.clauses = []
- this.allFields = allFields
- }
- lunr.Query.wildcard = new String ("*")
- lunr.Query.wildcard.NONE = 0
- lunr.Query.wildcard.LEADING = 1
- lunr.Query.wildcard.TRAILING = 2
- lunr.Query.presence = {
-
- OPTIONAL: 1,
-
- REQUIRED: 2,
-
- PROHIBITED: 3
- }
- lunr.Query.prototype.clause = function (clause) {
- if (!('fields' in clause)) {
- clause.fields = this.allFields
- }
- if (!('boost' in clause)) {
- clause.boost = 1
- }
- if (!('usePipeline' in clause)) {
- clause.usePipeline = true
- }
- if (!('wildcard' in clause)) {
- clause.wildcard = lunr.Query.wildcard.NONE
- }
- if ((clause.wildcard & lunr.Query.wildcard.LEADING) && (clause.term.charAt(0) != lunr.Query.wildcard)) {
- clause.term = "*" + clause.term
- }
- if ((clause.wildcard & lunr.Query.wildcard.TRAILING) && (clause.term.slice(-1) != lunr.Query.wildcard)) {
- clause.term = "" + clause.term + "*"
- }
- if (!('presence' in clause)) {
- clause.presence = lunr.Query.presence.OPTIONAL
- }
- this.clauses.push(clause)
- return this
- }
- lunr.Query.prototype.isNegated = function () {
- for (var i = 0; i < this.clauses.length; i++) {
- if (this.clauses[i].presence != lunr.Query.presence.PROHIBITED) {
- return false
- }
- }
- return true
- }
- lunr.Query.prototype.term = function (term, options) {
- if (Array.isArray(term)) {
- term.forEach(function (t) { this.term(t, lunr.utils.clone(options)) }, this)
- return this
- }
- var clause = options || {}
- clause.term = term.toString()
- this.clause(clause)
- return this
- }
|