12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100 |
- suite('search', function () {
- setup(function () {
- this.documents = [{
- id: 'a',
- title: 'Mr. Green kills Colonel Mustard',
- body: 'Mr. Green killed Colonel Mustard in the study with the candlestick. Mr. Green is not a very nice fellow.',
- wordCount: 19
- },{
- id: 'b',
- title: 'Plumb waters plant',
- body: 'Professor Plumb has a green plant in his study',
- wordCount: 9
- },{
- id: 'c',
- title: 'Scarlett helps Professor',
- body: 'Miss Scarlett watered Professor Plumbs green plant while he was away from his office last week.',
- wordCount: 16
- }]
- })
- suite('with build-time field boosts', function () {
- setup(function () {
- var self = this
- this.idx = lunr(function () {
- this.ref('id')
- this.field('title')
- this.field('body', { boost: 10 })
- self.documents.forEach(function (document) {
- this.add(document)
- }, this)
- })
- })
- suite('no query boosts', function () {
- var assertions = function () {
- test('document b ranks highest', function () {
- assert.equal('b', this.results[0].ref)
- })
- }
- suite('#search', function () {
- setup(function () {
- this.results = this.idx.search('professor')
- })
- assertions()
- })
- suite('#query', function () {
- setup(function () {
- this.results = this.idx.query(function (q) {
- q.term('professor')
- })
- })
- assertions()
- })
- })
- })
- suite('with build-time document boost', function () {
- setup(function () {
- var self = this
- this.idx = lunr(function () {
- this.ref('id')
- this.field('title')
- this.field('body')
- self.documents.forEach(function (document) {
- var boost = document.id == 'c' ? 10 : 1
- this.add(document, { boost: boost })
- }, this)
- })
- })
- suite('no query boost', function () {
- var assertions = function () {
- test('document c ranks highest', function () {
- assert.equal('c', this.results[0].ref)
- })
- }
- suite('#search', function () {
- setup(function () {
- this.results = this.idx.search('plumb')
- })
- assertions()
- })
- suite('#query', function () {
- setup(function () {
- this.results = this.idx.query(function (q) {
- q.term('plumb')
- })
- })
- assertions()
- })
- })
- suite('with query boost', function () {
- var assertions = function () {
- test('document b ranks highest', function () {
- assert.equal('b', this.results[0].ref)
- })
- }
- suite('#search', function () {
- setup(function () {
- this.results = this.idx.search('green study^10')
- })
- assertions()
- })
- suite('#query', function () {
- setup(function () {
- this.results = this.idx.query(function (q) {
- q.term('green')
- q.term('study', { boost: 10 })
- })
- })
- assertions()
- })
- })
- })
- suite('without build-time boosts', function () {
- setup(function () {
- var self = this
- this.idx = lunr(function () {
- this.ref('id')
- this.field('title')
- this.field('body')
- self.documents.forEach(function (document) {
- this.add(document)
- }, this)
- })
- })
- suite('single term search', function () {
- suite('one match', function () {
- var assertions = function () {
- test('one result returned', function () {
- assert.lengthOf(this.results, 1)
- })
- test('document c matches', function () {
- assert.equal('c', this.results[0].ref)
- })
- test('matching term', function () {
- assert.sameMembers(['scarlett'], Object.keys(this.results[0].matchData.metadata))
- })
- }
- suite('#seach', function () {
- setup(function () {
- this.results = this.idx.search('scarlett')
- })
- assertions()
- })
- suite('#query', function () {
- setup(function () {
- this.results = this.idx.query(function (q) {
- q.term('scarlett')
- })
- })
- assertions()
- })
- })
- suite('no match', function () {
- setup(function () {
- this.results = this.idx.search('foo')
- })
- test('no matches', function () {
- assert.lengthOf(this.results, 0)
- })
- })
- suite('multiple matches', function () {
- setup(function () {
- this.results = this.idx.search('plant')
- })
- test('has two matches', function () {
- assert.lengthOf(this.results, 2)
- })
- test('sorted by relevance', function () {
- assert.equal('b', this.results[0].ref)
- assert.equal('c', this.results[1].ref)
- })
- })
- suite('pipeline processing', function () {
- // study would be stemmed to studi, tokens
- // are stemmed by default on index and must
- // also be stemmed on search to match
- suite('enabled (default)', function () {
- setup(function () {
- this.results = this.idx.query(function (q) {
- q.clause({term: 'study', usePipeline: true})
- })
- })
- test('has two matches', function () {
- assert.lengthOf(this.results, 2)
- })
- test('sorted by relevance', function () {
- assert.equal('b', this.results[0].ref)
- assert.equal('a', this.results[1].ref)
- })
- })
- suite('disabled', function () {
- setup(function () {
- this.results = this.idx.query(function (q) {
- q.clause({term: 'study', usePipeline: false})
- })
- })
- test('no matches', function () {
- assert.lengthOf(this.results, 0)
- })
- })
- })
- })
- suite('multiple terms', function () {
- suite('all terms match', function () {
- setup(function () {
- this.results = this.idx.search('fellow candlestick')
- })
- test('has one match', function () {
- assert.lengthOf(this.results, 1)
- })
- test('correct document returned', function () {
- assert.equal('a', this.results[0].ref)
- })
- test('matched terms returned', function () {
- assert.sameMembers(['fellow', 'candlestick'], Object.keys(this.results[0].matchData.metadata))
- assert.sameMembers(['body'], Object.keys(this.results[0].matchData.metadata['fellow']));
- assert.sameMembers(['body'], Object.keys(this.results[0].matchData.metadata['candlestick']));
- })
- })
- suite('one term matches', function () {
- setup(function () {
- this.results = this.idx.search('week foo')
- })
- test('has one match', function () {
- assert.lengthOf(this.results, 1)
- })
- test('correct document returned', function () {
- assert.equal('c', this.results[0].ref)
- })
- test('only matching terms returned', function () {
- assert.sameMembers(['week'], Object.keys(this.results[0].matchData.metadata))
- })
- })
- suite('duplicate query terms', function () {
- // https://github.com/olivernn/lunr.js/issues/256
- // previously this would throw a duplicate index error
- // because the query vector already contained an entry
- // for the term 'fellow'
- test('no errors', function () {
- var idx = this.idx
- assert.doesNotThrow(function () {
- idx.search('fellow candlestick foo bar green plant fellow')
- })
- })
- })
- suite('documents with all terms score higher', function () {
- setup(function () {
- this.results = this.idx.search('candlestick green')
- })
- test('has three matches', function () {
- assert.lengthOf(this.results, 3)
- })
- test('correct documents returned', function () {
- var matchingDocuments = this.results.map(function (r) {
- return r.ref
- })
- assert.sameMembers(['a', 'b', 'c'], matchingDocuments)
- })
- test('documents with all terms score highest', function () {
- assert.equal('a', this.results[0].ref)
- })
- test('matching terms are returned', function () {
- assert.sameMembers(['candlestick', 'green'], Object.keys(this.results[0].matchData.metadata))
- assert.sameMembers(['green'], Object.keys(this.results[1].matchData.metadata))
- assert.sameMembers(['green'], Object.keys(this.results[2].matchData.metadata))
- })
- })
- suite('no terms match', function () {
- setup(function () {
- this.results = this.idx.search('foo bar')
- })
- test('no matches', function () {
- assert.lengthOf(this.results, 0)
- })
- })
- suite('corpus terms are stemmed', function () {
- setup(function () {
- this.results = this.idx.search('water')
- })
- test('matches two documents', function () {
- assert.lengthOf(this.results, 2)
- })
- test('matches correct documents', function () {
- var matchingDocuments = this.results.map(function (r) {
- return r.ref
- })
- assert.sameMembers(['b', 'c'], matchingDocuments)
- })
- })
- suite('field scoped terms', function () {
- suite('only matches on scoped field', function () {
- setup(function () {
- this.results = this.idx.search('title:plant')
- })
- test('one result returned', function () {
- assert.lengthOf(this.results, 1)
- })
- test('returns the correct document', function () {
- assert.equal('b', this.results[0].ref)
- })
- test('match data', function () {
- assert.sameMembers(['plant'], Object.keys(this.results[0].matchData.metadata))
- })
- })
- suite('no matching terms', function () {
- setup(function () {
- this.results = this.idx.search('title:candlestick')
- })
- test('no results returned', function () {
- assert.lengthOf(this.results, 0)
- })
- })
- })
- suite('wildcard matching', function () {
- suite('trailing wildcard', function () {
- suite('no matches', function () {
- setup(function () {
- this.results = this.idx.search('fo*')
- })
- test('no results returned', function () {
- assert.lengthOf(this.results, 0)
- })
- })
- suite('one match', function () {
- setup(function () {
- this.results = this.idx.search('candle*')
- })
- test('one result returned', function () {
- assert.lengthOf(this.results, 1)
- })
- test('correct document matched', function () {
- assert.equal('a', this.results[0].ref)
- })
- test('matching terms returned', function () {
- assert.sameMembers(['candlestick'], Object.keys(this.results[0].matchData.metadata))
- })
- })
- suite('multiple terms match', function () {
- setup(function () {
- this.results = this.idx.search('pl*')
- })
- test('two results returned', function () {
- assert.lengthOf(this.results, 2)
- })
- test('correct documents matched', function () {
- var matchingDocuments = this.results.map(function (r) {
- return r.ref
- })
- assert.sameMembers(['b', 'c'], matchingDocuments)
- })
- test('matching terms returned', function () {
- assert.sameMembers(['plumb', 'plant'], Object.keys(this.results[0].matchData.metadata))
- assert.sameMembers(['plumb', 'plant'], Object.keys(this.results[1].matchData.metadata))
- })
- })
- })
- })
- })
- suite('wildcard matching', function () {
- suite('trailing wildcard', function () {
- suite('no matches found', function () {
- setup(function () {
- this.results = this.idx.search('fo*')
- })
- test('no results returned', function () {
- assert.lengthOf(this.results, 0)
- })
- })
- suite('results found', function () {
- setup(function () {
- this.results = this.idx.search('pl*')
- })
- test('two results returned', function () {
- assert.lengthOf(this.results, 2)
- })
- test('matching documents returned', function () {
- assert.equal('b', this.results[0].ref)
- assert.equal('c', this.results[1].ref)
- })
- test('matching terms returned', function () {
- assert.sameMembers(['plant', 'plumb'], Object.keys(this.results[0].matchData.metadata))
- assert.sameMembers(['plant', 'plumb'], Object.keys(this.results[1].matchData.metadata))
- })
- })
- })
- suite('leading wildcard', function () {
- suite('no results found', function () {
- setup(function () {
- this.results = this.idx.search('*oo')
- })
- test('no results found', function () {
- assert.lengthOf(this.results, 0)
- })
- })
- suite('results found', function () {
- setup(function () {
- this.results = this.idx.search('*ant')
- })
- test('two results found', function () {
- assert.lengthOf(this.results, 2)
- })
- test('matching documents returned', function () {
- assert.equal('b', this.results[0].ref)
- assert.equal('c', this.results[1].ref)
- })
- test('matching terms returned', function () {
- assert.sameMembers(['plant'], Object.keys(this.results[0].matchData.metadata))
- assert.sameMembers(['plant'], Object.keys(this.results[1].matchData.metadata))
- })
- })
- })
- suite('contained wildcard', function () {
- suite('no results found', function () {
- setup(function () {
- this.results = this.idx.search('f*o')
- })
- test('no results found', function () {
- assert.lengthOf(this.results, 0)
- })
- })
- suite('results found', function () {
- setup(function () {
- this.results = this.idx.search('pl*nt')
- })
- test('two results found', function () {
- assert.lengthOf(this.results, 2)
- })
- test('matching documents returned', function () {
- assert.equal('b', this.results[0].ref)
- assert.equal('c', this.results[1].ref)
- })
- test('matching terms returned', function () {
- assert.sameMembers(['plant'], Object.keys(this.results[0].matchData.metadata))
- assert.sameMembers(['plant'], Object.keys(this.results[1].matchData.metadata))
- })
- })
- })
- })
- suite('edit distance', function () {
- suite('no results found', function () {
- setup(function () {
- this.results = this.idx.search('foo~1')
- })
- test('no results returned', function () {
- assert.lengthOf(this.results, 0)
- })
- })
- suite('results found', function () {
- setup(function () {
- this.results = this.idx.search('plont~1')
- })
- test('two results found', function () {
- assert.lengthOf(this.results, 2)
- })
- test('matching documents returned', function () {
- assert.equal('b', this.results[0].ref)
- assert.equal('c', this.results[1].ref)
- })
- test('matching terms returned', function () {
- assert.sameMembers(['plant'], Object.keys(this.results[0].matchData.metadata))
- assert.sameMembers(['plant'], Object.keys(this.results[1].matchData.metadata))
- })
- })
- })
- suite('searching by field', function () {
- suite('unknown field', function () {
- test('throws lunr.QueryParseError', function () {
- assert.throws(function () {
- this.idx.search('unknown-field:plant')
- }.bind(this), lunr.QueryParseError)
- })
- })
- suite('no results found', function () {
- setup(function () {
- this.results = this.idx.search('title:candlestick')
- })
- test('no results found', function () {
- assert.lengthOf(this.results, 0)
- })
- })
- suite('results found', function () {
- setup(function () {
- this.results = this.idx.search('title:plant')
- })
- test('one results 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'], Object.keys(this.results[0].matchData.metadata))
- })
- })
- })
- suite('term boosts', function () {
- suite('no results found', function () {
- setup(function () {
- this.results = this.idx.search('foo^10')
- })
- test('no results found', function () {
- assert.lengthOf(this.results, 0)
- })
- })
- suite('results found', function () {
- setup(function () {
- this.results = this.idx.search('scarlett candlestick^5')
- })
- test('two results found', function () {
- assert.lengthOf(this.results, 2)
- })
- test('matching documents returned', function () {
- assert.equal('a', this.results[0].ref)
- assert.equal('c', this.results[1].ref)
- })
- test('matching terms returned', function () {
- assert.sameMembers(['candlestick'], Object.keys(this.results[0].matchData.metadata))
- assert.sameMembers(['scarlett'], Object.keys(this.results[1].matchData.metadata))
- })
- })
- })
- suite('typeahead style search', function () {
- suite('no results found', function () {
- setup(function () {
- this.results = this.idx.query(function (q) {
- q.term("xyz", { boost: 100, usePipeline: true })
- q.term("xyz", { boost: 10, usePipeline: false, wildcard: lunr.Query.wildcard.TRAILING })
- q.term("xyz", { boost: 1, editDistance: 1 })
- })
- })
- test('no results found', function () {
- assert.lengthOf(this.results, 0)
- })
- })
- suite('results found', function () {
- setup(function () {
- this.results = this.idx.query(function (q) {
- q.term("pl", { boost: 100, usePipeline: true })
- q.term("pl", { boost: 10, usePipeline: false, wildcard: lunr.Query.wildcard.TRAILING })
- q.term("pl", { boost: 1, editDistance: 1 })
- })
- })
- test('two results found', function () {
- assert.lengthOf(this.results, 2)
- })
- test('matching documents returned', function () {
- assert.equal('b', this.results[0].ref)
- assert.equal('c', this.results[1].ref)
- })
- test('matching terms returned', function () {
- assert.sameMembers(['plumb', 'plant'], Object.keys(this.results[0].matchData.metadata))
- assert.sameMembers(['plumb', 'plant'], Object.keys(this.results[1].matchData.metadata))
- })
- })
- })
- suite('term presence', function () {
- suite('prohibited', function () {
- suite('match', function () {
- var assertions = function () {
- test('two results found', function () {
- assert.lengthOf(this.results, 2)
- })
- test('matching documents returned', function () {
- assert.equal('b', this.results[0].ref)
- assert.equal('c', this.results[1].ref)
- })
- test('matching terms returned', function () {
- assert.sameMembers(['green'], Object.keys(this.results[0].matchData.metadata))
- assert.sameMembers(['green'], Object.keys(this.results[1].matchData.metadata))
- })
- }
- 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 })
- })
- })
- assertions()
- })
- suite('#search', function () {
- setup(function () {
- this.results = this.idx.search('-candlestick green')
- })
- assertions()
- })
- })
- suite('no match', function () {
- var assertions = function () {
- test('no matches', function () {
- assert.lengthOf(this.results, 0)
- })
- }
- suite('#query', function () {
- setup(function () {
- this.results = this.idx.query(function (q) {
- q.term('green', { presence: lunr.Query.presence.PROHIBITED })
- })
- })
- assertions()
- })
- suite('#search', function () {
- setup(function () {
- this.results = this.idx.search('-green')
- })
- assertions()
- })
- })
- suite('negated query no match', function () {
- var assertions = function () {
- test('all documents returned', function () {
- assert.lengthOf(this.results, 3)
- })
- test('all results have same score', function () {
- assert.isTrue(this.results.every(function (r) { return r.score === 0 }))
- })
- }
- suite('#query', function () {
- setup(function () {
- this.results = this.idx.query(function (q) {
- q.term('qwertyuiop', { presence: lunr.Query.presence.PROHIBITED })
- })
- })
- assertions()
- })
- suite('#search', function () {
- setup(function () {
- this.results = this.idx.search("-qwertyuiop")
- })
- assertions()
- })
- })
- suite('negated query some match', function () {
- var assertions = function () {
- test('all documents returned', function () {
- assert.lengthOf(this.results, 1)
- })
- test('all results have same score', function () {
- assert.isTrue(this.results.every(function (r) { return r.score === 0 }))
- })
- test('matching documents returned', function () {
- assert.equal('a', this.results[0].ref)
- })
- }
- suite('#query', function () {
- setup(function () {
- this.results = this.idx.query(function (q) {
- q.term('plant', { presence: lunr.Query.presence.PROHIBITED })
- })
- })
- assertions()
- })
- suite('#search', function () {
- setup(function () {
- this.results = this.idx.search("-plant")
- })
- assertions()
- })
- })
- suite('field match', function () {
- var assertions = function () {
- test('one result found', function () {
- assert.lengthOf(this.results, 1)
- })
- test('matching documents returned', function () {
- assert.equal('c', this.results[0].ref)
- })
- test('matching terms returned', function () {
- assert.sameMembers(['plumb'], 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.PROHIBITED, fields: ['title'] })
- q.term('plumb', { presence: lunr.Query.presence.OPTIONAL })
- })
- })
- assertions()
- })
- suite('#search', function () {
- setup(function () {
- this.results = this.idx.search('-title:plant plumb')
- })
- assertions()
- })
- })
- })
- suite('required', function () {
- suite('match', function () {
- var assertions = function () {
- test('one result found', function () {
- assert.lengthOf(this.results, 1)
- })
- test('matching documents returned', function () {
- assert.equal('a', this.results[0].ref)
- })
- test('matching terms returned', function () {
- assert.sameMembers(['candlestick', 'green'], Object.keys(this.results[0].matchData.metadata))
- })
- }
- suite('#search', function () {
- setup(function () {
- this.results = this.idx.search("+candlestick green")
- })
- 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 () {
- test('no matches', function () {
- assert.lengthOf(this.results, 0)
- })
- }
- 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 })
- })
- })
- assertions()
- })
- suite('#search', function () {
- setup(function () {
- this.results = this.idx.search('+mustard +plant')
- })
- assertions()
- })
- })
- suite('no matching term', function () {
- var assertions = function () {
- test('no matches', function () {
- assert.lengthOf(this.results, 0)
- })
- }
- 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 })
- })
- })
- assertions()
- })
- suite('#search', function () {
- setup(function () {
- this.results = this.idx.search('+qwertyuiop green')
- })
- assertions()
- })
- })
- suite('field match', 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(['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 () {
- 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('#search', function () {
- setup(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('different fields one without match', function () {
- var assertions = function () {
- test('no matches', function () {
- assert.lengthOf(this.results, 0)
- })
- }
- suite('#search', function () {
- setup(function () {
- this.results = this.idx.search('+title:plant +body:qwertyuiop')
- })
- 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('qwertyuiop', { fields: ['body'], presence: lunr.Query.presence.REQUIRED })
- })
- })
- assertions()
- })
- })
- })
- suite('combined', 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(['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 })
- q.term('green', { presence: lunr.Query.presence.OPTIONAL })
- q.term('office', { presence: lunr.Query.presence.PROHIBITED })
- })
- })
- assertions()
- })
- suite('#search', function () {
- setup(function () {
- this.results = this.idx.search('+plant green -office')
- })
- assertions()
- })
- })
- })
- })
- })
|