Comparing version 2.2.0 to 2.2.1
# Changelog | ||
## 2.2.1 | ||
* Fix bug [#344](https://github.com/olivernn/lunr.js/issues/344) in logic for required terms in multiple fields, thanks [Stephane Mankowski](https://github.com/miraks31). | ||
* Upgrade mocha and fix some test snafus. | ||
## 2.2.0 | ||
@@ -4,0 +9,0 @@ |
@@ -168,3 +168,4 @@ /*! | ||
var clause = query.clauses[i], | ||
terms = null | ||
terms = null, | ||
clauseMatches = lunr.Set.complete | ||
@@ -239,11 +240,11 @@ if (clause.usePipeline) { | ||
* if the presence of this term is required ensure that the matching | ||
* documents are added to the set of required matches for this field, | ||
* creating that set if it does not yet exist. | ||
* documents are added to the set of required matches for this clause. | ||
* | ||
*/ | ||
if (clause.presence == lunr.Query.presence.REQUIRED) { | ||
clauseMatches = clauseMatches.union(matchingDocumentsSet) | ||
if (requiredMatches[field] === undefined) { | ||
requiredMatches[field] = lunr.Set.complete | ||
} | ||
requiredMatches[field] = requiredMatches[field].intersect(matchingDocumentsSet) | ||
} | ||
@@ -312,2 +313,15 @@ | ||
} | ||
/** | ||
* If the presence was required we need to update the requiredMatches field sets. | ||
* We do this after all fields for the term have collected their matches because | ||
* the clause terms presence is required in _any_ of the fields not _all_ of the | ||
* fields. | ||
*/ | ||
if (clause.presence === lunr.Query.presence.REQUIRED) { | ||
for (var k = 0; k < clause.fields.length; k++) { | ||
var field = clause.fields[k] | ||
requiredMatches[field] = requiredMatches[field].intersect(clauseMatches) | ||
} | ||
} | ||
} | ||
@@ -327,3 +341,3 @@ | ||
if (requiredMatches[field]) { | ||
allRequiredMatches = allRequiredMatches.union(requiredMatches[field]) | ||
allRequiredMatches = allRequiredMatches.intersect(requiredMatches[field]) | ||
} | ||
@@ -330,0 +344,0 @@ |
{ | ||
"name": "lunr", | ||
"description": "Simple full-text search in your browser.", | ||
"version": "2.2.0", | ||
"version": "2.2.1", | ||
"author": "Oliver Nightingale", | ||
"keywords": [ | ||
"search" | ||
], | ||
"keywords": ["search"], | ||
"homepage": "http://lunrjs.com", | ||
@@ -10,0 +8,0 @@ "bugs": "http://github.com/olivernn/lunr.js/issues", |
@@ -119,3 +119,2 @@ suite('lunr.QueryParser', function () { | ||
test('has 2 clause', function () { | ||
debugger | ||
assert.lengthOf(this.clauses, 2) | ||
@@ -122,0 +121,0 @@ }) |
@@ -560,5 +560,3 @@ suite('search', function () { | ||
suite('match', function () { | ||
var assertions = function (fn) { | ||
setup(fn) | ||
var assertions = function () { | ||
test('two results found', function () { | ||
@@ -579,18 +577,24 @@ assert.lengthOf(this.results, 2) | ||
suite('#query', assertions(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('candlestick', { presence: lunr.Query.presence.PROHIBITED }) | ||
q.term('green', { presence: lunr.Query.presence.OPTIONAL }) | ||
suite('#query', function () { | ||
setup(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('candlestick', { presence: lunr.Query.presence.PROHIBITED }) | ||
q.term('green', { presence: lunr.Query.presence.OPTIONAL }) | ||
}) | ||
}) | ||
})) | ||
suite('#search', assertions(function () { | ||
this.results = this.idx.search('-candlestick green') | ||
})) | ||
assertions() | ||
}) | ||
suite('#search', function () { | ||
setup(function () { | ||
this.results = this.idx.search('-candlestick green') | ||
}) | ||
assertions() | ||
}) | ||
}) | ||
suite('no match', function () { | ||
var assertions = function (fn) { | ||
setup(fn) | ||
var assertions = function () { | ||
test('no matches', function () { | ||
@@ -601,17 +605,23 @@ assert.lengthOf(this.results, 0) | ||
suite('#query', assertions(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('green', { presence: lunr.Query.presence.PROHIBITED }) | ||
suite('#query', function () { | ||
setup(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('green', { presence: lunr.Query.presence.PROHIBITED }) | ||
}) | ||
}) | ||
})) | ||
suite('#search', assertions(function () { | ||
this.results = this.idx.search('-green') | ||
})) | ||
assertions() | ||
}) | ||
suite('#search', function () { | ||
setup(function () { | ||
this.results = this.idx.search('-green') | ||
}) | ||
assertions() | ||
}) | ||
}) | ||
suite('negated query no match', function () { | ||
var assertions = function (fn) { | ||
setup(fn) | ||
var assertions = function () { | ||
test('all documents returned', function () { | ||
@@ -626,17 +636,23 @@ assert.lengthOf(this.results, 3) | ||
suite('#query', assertions(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('qwertyuiop', { presence: lunr.Query.presence.PROHIBITED }) | ||
suite('#query', function () { | ||
setup(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('qwertyuiop', { presence: lunr.Query.presence.PROHIBITED }) | ||
}) | ||
}) | ||
})) | ||
suite('#search', assertions(function () { | ||
this.results = this.idx.search("-qwertyuiop") | ||
})) | ||
assertions() | ||
}) | ||
suite('#search', function () { | ||
setup(function () { | ||
this.results = this.idx.search("-qwertyuiop") | ||
}) | ||
assertions() | ||
}) | ||
}) | ||
suite('negated query some match', function () { | ||
var assertions = function (fn) { | ||
setup(fn) | ||
var assertions = function () { | ||
test('all documents returned', function () { | ||
@@ -655,17 +671,23 @@ assert.lengthOf(this.results, 1) | ||
suite('#query', assertions(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('plant', { presence: lunr.Query.presence.PROHIBITED }) | ||
suite('#query', function () { | ||
setup(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('plant', { presence: lunr.Query.presence.PROHIBITED }) | ||
}) | ||
}) | ||
})) | ||
suite('#search', assertions(function () { | ||
this.results = this.idx.search("-plant") | ||
})) | ||
assertions() | ||
}) | ||
suite('#search', function () { | ||
setup(function () { | ||
this.results = this.idx.search("-plant") | ||
}) | ||
assertions() | ||
}) | ||
}) | ||
suite('field match', function () { | ||
var assertions = function (fn) { | ||
setup(fn) | ||
var assertions = function () { | ||
test('one result found', function () { | ||
@@ -684,13 +706,20 @@ assert.lengthOf(this.results, 1) | ||
suite('#query', assertions(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('plant', { presence: lunr.Query.presence.PROHIBITED, fields: ['title'] }) | ||
q.term('plumb', { presence: lunr.Query.presence.OPTIONAL }) | ||
suite('#query', function () { | ||
setup(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('plant', { presence: lunr.Query.presence.PROHIBITED, fields: ['title'] }) | ||
q.term('plumb', { presence: lunr.Query.presence.OPTIONAL }) | ||
}) | ||
}) | ||
})) | ||
suite('#search', assertions(function () { | ||
this.results = this.idx.search('-title:plant plumb') | ||
})) | ||
assertions() | ||
}) | ||
suite('#search', function () { | ||
setup(function () { | ||
this.results = this.idx.search('-title:plant plumb') | ||
}) | ||
assertions() | ||
}) | ||
}) | ||
@@ -701,5 +730,3 @@ }) | ||
suite('match', function () { | ||
var assertions = function (fn) { | ||
setup(fn) | ||
var assertions = function () { | ||
test('one result found', function () { | ||
@@ -718,19 +745,24 @@ assert.lengthOf(this.results, 1) | ||
suite('#search', assertions(function () { | ||
this.results = this.idx.search("+candlestick green") | ||
})) | ||
suite('#search', function () { | ||
setup(function () { | ||
this.results = this.idx.search("+candlestick green") | ||
}) | ||
suite('#query', assertions(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('candlestick', { presence: lunr.Query.presence.REQUIRED }) | ||
q.term('green', { presence: lunr.Query.presence.OPTIONAL }) | ||
assertions() | ||
}) | ||
suite('#query', function () { | ||
setup(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('candlestick', { presence: lunr.Query.presence.REQUIRED }) | ||
q.term('green', { presence: lunr.Query.presence.OPTIONAL }) | ||
}) | ||
}) | ||
})) | ||
assertions() | ||
}) | ||
}) | ||
suite('no match', function () { | ||
var assertions = function (fn) { | ||
setup(fn) | ||
var assertions = function () { | ||
test('no matches', function () { | ||
@@ -741,18 +773,24 @@ assert.lengthOf(this.results, 0) | ||
suite('#query', assertions(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('mustard', { presence: lunr.Query.presence.REQUIRED }) | ||
q.term('plant', { presence: lunr.Query.presence.REQUIRED }) | ||
suite('#query', function () { | ||
setup(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('mustard', { presence: lunr.Query.presence.REQUIRED }) | ||
q.term('plant', { presence: lunr.Query.presence.REQUIRED }) | ||
}) | ||
}) | ||
})) | ||
suite('#search', assertions(function () { | ||
this.results = this.idx.search('+mustard +plant') | ||
})) | ||
assertions() | ||
}) | ||
suite('#search', function () { | ||
setup(function () { | ||
this.results = this.idx.search('+mustard +plant') | ||
}) | ||
assertions() | ||
}) | ||
}) | ||
suite('no matching term', function () { | ||
var assertions = function (fn) { | ||
setup(fn) | ||
var assertions = function () { | ||
test('no matches', function () { | ||
@@ -763,18 +801,59 @@ assert.lengthOf(this.results, 0) | ||
suite('#query', assertions(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('qwertyuiop', { presence: lunr.Query.presence.REQUIRED }) | ||
q.term('green', { presence: lunr.Query.presence.OPTIONAL }) | ||
suite('#query', function () { | ||
setup(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('qwertyuiop', { presence: lunr.Query.presence.REQUIRED }) | ||
q.term('green', { presence: lunr.Query.presence.OPTIONAL }) | ||
}) | ||
}) | ||
})) | ||
suite('#search', assertions(function () { | ||
this.results = this.idx.search('+qwertyuiop green') | ||
})) | ||
assertions() | ||
}) | ||
suite('#search', function () { | ||
setup(function () { | ||
this.results = this.idx.search('+qwertyuiop green') | ||
}) | ||
assertions() | ||
}) | ||
}) | ||
suite('field match', function () { | ||
var assertions = function (fn) { | ||
setup(fn) | ||
var assertions = function () { | ||
test('one result found', function () { | ||
assert.lengthOf(this.results, 1) | ||
}) | ||
test('matching documents returned', function () { | ||
assert.equal('b', this.results[0].ref) | ||
}) | ||
test('matching terms returned', function () { | ||
assert.sameMembers(['plant', 'green'], Object.keys(this.results[0].matchData.metadata)) | ||
}) | ||
} | ||
suite('#query', function () { | ||
setup(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('plant', { presence: lunr.Query.presence.REQUIRED, fields: ['title'] }) | ||
q.term('green', { presence: lunr.Query.presence.OPTIONAL }) | ||
}) | ||
}) | ||
assertions() | ||
}) | ||
suite('#search', function () { | ||
setup(function () { | ||
this.results = this.idx.search('+title:plant green') | ||
}) | ||
assertions() | ||
}) | ||
}) | ||
suite('field and non field match', function () { | ||
var assertions = function () { | ||
test('one result found', function () { | ||
@@ -793,20 +872,60 @@ assert.lengthOf(this.results, 1) | ||
suite('#query', assertions(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('plant', { presence: lunr.Query.presence.REQUIRED, fields: ['title'] }) | ||
q.term('green', { presence: lunr.Query.presence.OPTIONAL }) | ||
suite('#search', function () { | ||
setup(function () { | ||
this.results = this.idx.search('+title:plant +green') | ||
}) | ||
})) | ||
suite('#search', assertions(function () { | ||
this.results = this.idx.search('+title:plant green') | ||
})) | ||
assertions() | ||
}) | ||
suite('#query', function () { | ||
setup(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('plant', { fields: ['title'], presence: lunr.Query.presence.REQUIRED }) | ||
q.term('green', { presence: lunr.Query.presence.REQUIRED }) | ||
}) | ||
}) | ||
assertions() | ||
}) | ||
}) | ||
suite('different fields', function () { | ||
var assertions = function () { | ||
test('one result found', function () { | ||
assert.lengthOf(this.results, 1) | ||
}) | ||
test('matching documents returned', function () { | ||
assert.equal('b', this.results[0].ref) | ||
}) | ||
test('matching terms returned', function () { | ||
assert.sameMembers(['studi', 'plant'], Object.keys(this.results[0].matchData.metadata)) | ||
}) | ||
} | ||
suite('#search', function () { | ||
setup(function () { | ||
this.results = this.idx.search('+title:plant +body:study') | ||
}) | ||
assertions() | ||
}) | ||
suite('#query', function () { | ||
setup(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('plant', { fields: ['title'], presence: lunr.Query.presence.REQUIRED }) | ||
q.term('study', { fields: ['body'], presence: lunr.Query.presence.REQUIRED }) | ||
}) | ||
}) | ||
assertions() | ||
}) | ||
}) | ||
}) | ||
suite('combined', function () { | ||
var assertions = function (fn) { | ||
setup(fn) | ||
var assertions = function () { | ||
test('one result found', function () { | ||
@@ -825,16 +944,24 @@ assert.lengthOf(this.results, 1) | ||
suite('#query', assertions(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('plant', { presence: lunr.Query.presence.REQUIRED }) | ||
q.term('green', { presence: lunr.Query.presence.OPTIONAL }) | ||
q.term('office', { presence: lunr.Query.presence.PROHIBITED }) | ||
suite('#query', function () { | ||
setup(function () { | ||
this.results = this.idx.query(function (q) { | ||
q.term('plant', { presence: lunr.Query.presence.REQUIRED }) | ||
q.term('green', { presence: lunr.Query.presence.OPTIONAL }) | ||
q.term('office', { presence: lunr.Query.presence.PROHIBITED }) | ||
}) | ||
}) | ||
})) | ||
suite('#search', assertions(function () { | ||
this.results = this.idx.search('+plant green -office') | ||
})) | ||
assertions() | ||
}) | ||
suite('#search', function () { | ||
setup(function () { | ||
this.results = this.idx.search('+plant green -office') | ||
}) | ||
assertions() | ||
}) | ||
}) | ||
}) | ||
}) |
@@ -16,3 +16,3 @@ suite('lunr.Set', function () { | ||
suite('populated set', function () { | ||
before(function () { | ||
setup(function () { | ||
this.set = new lunr.Set (['foo']) | ||
@@ -32,3 +32,3 @@ }) | ||
suite('#union', function () { | ||
before(function () { | ||
setup(function () { | ||
this.set = new lunr.Set(['foo']) | ||
@@ -64,3 +64,3 @@ }) | ||
suite('#intersect', function () { | ||
before(function () { | ||
setup(function () { | ||
this.set = new lunr.Set(['foo']) | ||
@@ -85,3 +85,3 @@ }) | ||
suite('no intersection', function () { | ||
test('contains intersection elements', function () { | ||
test('does not contain intersection elements', function () { | ||
var target = new lunr.Set (['bar']) | ||
@@ -88,0 +88,0 @@ var result = target.intersect(this.set) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 3 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
923599
28183
77
24
1