Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide context #58

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
npm-debug.log
11 changes: 9 additions & 2 deletions README.mdown
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ Contributions are very welcome, to make the process as easy as possible please f

A JavaScript runtime is required for building the library.

Run the tests with, this will use phantomjs to run the tests:
Install node dependencies with npm:

npm install

Start the test server:

make test_serevr

Then, run the tests with `make`. This uses phantomjs to run the tests:

make test

Expand All @@ -79,4 +87,3 @@ The tests can also be run in the browser by starting the test server:
make test_server

This will start a server on port 3000, the tests are then available at '/test'

6 changes: 4 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ lunr.Index.prototype.search = function (query) {

if (!hasSomeToken) return []

var ref_to_pos = {}

queryTokens
.forEach(function (token, i, tokens) {
var tf = 1 / tokens.length * this._fields.length * fieldBoosts,
Expand All @@ -318,7 +320,7 @@ lunr.Index.prototype.search = function (query) {
if (pos > -1) queryArr[pos] = tf * idf * similarityBoost

// add all the documents that have this key into a set
Object.keys(self.tokenStore.get(key)).forEach(function (ref) { set.add(ref) })
Object.keys(self.tokenStore.get(key)).forEach(function (ref) { set.add(ref); ref_to_pos[ref] = pos })

return memo.union(set)
}, new lunr.SortedSet)
Expand All @@ -334,7 +336,7 @@ lunr.Index.prototype.search = function (query) {

return documentSet
.map(function (ref) {
return { ref: ref, score: queryVector.similarity(this.documentVector(ref)) }
return { ref: ref, score: queryVector.similarity(this.documentVector(ref)), position: ref_to_pos[ref] }
}, this)
.sort(function (a, b) {
return b.score - a.score
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
"url": "https://github.com/olivernn/lunr.js.git"
},
"devDependencies": {
"phantomjs": "1.8.1-3"
"phantomjs": "1.8.1-3",
"dox": "0.4.4",
"dox-template": "0.1.1"
},
"scripts": {
"test": "phantomjs test/env/runner.js http://localhost:3000/test"
Expand Down