diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..1ca95717 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +node_modules/ +npm-debug.log diff --git a/README.mdown b/README.mdown index c0660509..c7fefd98 100644 --- a/README.mdown +++ b/README.mdown @@ -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 @@ -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' - diff --git a/lib/index.js b/lib/index.js index 9704e0bc..3609a938 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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, @@ -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) @@ -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 diff --git a/package.json b/package.json index 97e90b45..9a14e7d7 100644 --- a/package.json +++ b/package.json @@ -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"