Skip to content

Commit

Permalink
fix issue: boolean "AND" error
Browse files Browse the repository at this point in the history
fix issue #8 (comment)
  • Loading branch information
weixsong committed Mar 9, 2016
1 parent caee5ad commit 31ab173
Show file tree
Hide file tree
Showing 17 changed files with 110 additions and 32 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.mdown
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
#

## 0.8.9

* fix issue [#8](https://github.com/weixsong/elasticlunr.js/issues/8#issuecomment-193266856), boolean "AND" error.
* need to add test cases for issue fix #8

## 0.8.8

* during to the ugly slow network of my family, re-publish this version.

## 0.8.7

* remove make server
* remove .DS_Store
* remove folder perf
* fix issue [#8](https://github.com/weixsong/elasticlunr.js/issues/8), do tokenizenation even if the parameter of tokenizer is array type, because if we do not do segmentation, the whole array item will be used to build index then partial query will not be searchable.
* but currently exist cross query error, need to fix.

## 0.8.6

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.8.6
0.8.8
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elasticlunr.js",
"version": "0.8.6",
"version": "0.8.8",
"main": "elasticlunr.js",
"ignore": [
"tests/",
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "elasticlunr",
"repo": "weixsong/elasticlunr.js",
"version": "0.8.6",
"version": "0.8.8",
"description": "Lightweight full-text search engine in Javascript for browser search and offline search.",
"license": "MIT",
"main": "elasticlunr.js",
Expand Down
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ <h1>elasticlunr</h1>
</div>
<div class="span9">
<section id="Main"><h1>Elasticlunr.js</h1>
<p><a href="https://travis-ci.org/weixsong/elasticlunr.js"><img src="https://travis-ci.org/weixsong/elasticlunr.js.svg?branch=master" alt="Build Status"></a></p><p>Elasticlunr.js is a lightweight full-text search engine developed in JavaScript for browser search and offline search.<br />Elasticlunr.js is developed based on Lunr.js, but more flexible than lunr.js. Elasticlunr.js provides Query-Time boosting, field search, more rational scoring/ranking methodology, fast computation speed and so on.<br />Elasticlunr.js is a bit like Solr, but much smaller and not as bright, but also provide flexible configuration, query-time boosting, field search and other features.</p><h1>Why You Need Lightweight Offline Search?</h1>
<p><a href="https://travis-ci.org/weixsong/elasticlunr.js"><img src="https://travis-ci.org/weixsong/elasticlunr.js.svg?branch=master" alt="Build Status"></a><br /><a href="https://badge.fury.io/js/elasticlunr"><img src="https://badge.fury.io/js/elasticlunr.svg" alt="npm version"></a><br /><a href="https://raw.githubusercontent.com/weixsong/elasticlunr.js/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="GitHub license"></a></p><p>Elasticlunr.js is a lightweight full-text search engine developed in JavaScript for browser search and offline search.<br />Elasticlunr.js is developed based on Lunr.js, but more flexible than lunr.js. Elasticlunr.js provides Query-Time boosting, field search, more rational scoring/ranking methodology, fast computation speed and so on.<br />Elasticlunr.js is a bit like Solr, but much smaller and not as bright, but also provide flexible configuration, query-time boosting, field search and other features.</p><h1>Why You Need Lightweight Offline Search?</h1>
<ol>
<li>In some system, you don&#39;t want to deploy any <strong>complex full-text search engine</strong>(such as Lucence, Elasticsearch, Sphinx, etc.), you only want to provide some static web pages and provide search functionality , then you could build index in previous and load index in client side(such as Browser).</li>
<li>Provide offline search functionality. For some documents, user usually download these documents, you could build index and put index in the documents package, then provide offline search functionality.</li>
Expand Down
10 changes: 9 additions & 1 deletion docs/tokenizer.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,17 @@ <h5 class="subheader"></h5>
return true;
});

return arr.map(function (t) {
arr = arr.map(function (t) {
return elasticlunr.utils.toString(t).toLowerCase();
});

var out = [];
arr.forEach(function(item) {
var tokens = item.split(elasticlunr.tokenizer.seperator);
out = out.concat(tokens);
}, this);

return out;
}

return str.toString().trim().toLowerCase().split(elasticlunr.tokenizer.seperator);
Expand Down
14 changes: 11 additions & 3 deletions elasticlunr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* elasticlunr - http://weixsong.github.io
* Lightweight full-text search engine in Javascript for browser search and offline search. - 0.8.6
* Lightweight full-text search engine in Javascript for browser search and offline search. - 0.8.8
*
* Copyright (C) 2016 Oliver Nightingale
* Copyright (C) 2016 Wei Song
Expand Down Expand Up @@ -83,7 +83,7 @@ var elasticlunr = function (config) {
return idx;
};

elasticlunr.version = "0.8.6";
elasticlunr.version = "0.8.8";
/*!
* elasticlunr.utils
* Copyright (C) 2016 Oliver Nightingale
Expand Down Expand Up @@ -243,9 +243,17 @@ elasticlunr.tokenizer = function (str) {
return true;
});

return arr.map(function (t) {
arr = arr.map(function (t) {
return elasticlunr.utils.toString(t).toLowerCase();
});

var out = [];
arr.forEach(function(item) {
var tokens = item.split(elasticlunr.tokenizer.seperator);
out = out.concat(tokens);
}, this);

return out;
}

return str.toString().trim().toLowerCase().split(elasticlunr.tokenizer.seperator);
Expand Down
4 changes: 2 additions & 2 deletions elasticlunr.min.js

Large diffs are not rendered by default.

14 changes: 11 additions & 3 deletions example/elasticlunr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* elasticlunr - http://weixsong.github.io
* Lightweight full-text search engine in Javascript for browser search and offline search. - 0.8.6
* Lightweight full-text search engine in Javascript for browser search and offline search. - 0.8.8
*
* Copyright (C) 2016 Oliver Nightingale
* Copyright (C) 2016 Wei Song
Expand Down Expand Up @@ -83,7 +83,7 @@ var elasticlunr = function (config) {
return idx;
};

elasticlunr.version = "0.8.6";
elasticlunr.version = "0.8.8";
/*!
* elasticlunr.utils
* Copyright (C) 2016 Oliver Nightingale
Expand Down Expand Up @@ -243,9 +243,17 @@ elasticlunr.tokenizer = function (str) {
return true;
});

return arr.map(function (t) {
arr = arr.map(function (t) {
return elasticlunr.utils.toString(t).toLowerCase();
});

var out = [];
arr.forEach(function(item) {
var tokens = item.split(elasticlunr.tokenizer.seperator);
out = out.concat(tokens);
}, this);

return out;
}

return str.toString().trim().toLowerCase().split(elasticlunr.tokenizer.seperator);
Expand Down
4 changes: 2 additions & 2 deletions example/elasticlunr.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/example_index.json

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,21 @@ elasticlunr.Index.prototype.fieldSearch = function (queryTokens, fieldName, conf
if (expand == true) {
tokens = this.index[fieldName].expandToken(token);
}

tokens.forEach(function (key) {
var docs = this.index[fieldName].getDocs(key);
var idf = this.idf(key, fieldName);

// only record appeared token for retrieved documents for the
// original token, not for expaned token.
// beause for doing coordNorm for a retrieved document, coordNorm only care how many
// query token appear in that document.
// so expanded token should not be added into docTokens, if added, this will pollute the
// coordNorm
if (key == token) {
this.fieldSearchStats(docTokens, key, docs);
}

for (var docRef in docs) {
var tf = this.index[fieldName].getTermFrequency(key, docRef);
var fieldLength = this.documentStore.getFieldLength(docRef, fieldName);
Expand All @@ -397,14 +408,6 @@ elasticlunr.Index.prototype.fieldSearch = function (queryTokens, fieldName, conf
// currently I'm not sure if this penality is enough,
// need to do verification
penality = (1 - (key.length - token.length) / key.length) * 0.15;
} else {
// only record appeared token for retrieved documents for the
// original token, not for expaned token.
// beause for doing coordNorm for a retrieved document, coordNorm only care how many
// query token appear in that document.
// so expanded token should not be added into docTokens, if added, this will pollute the
// coordNorm
this.fieldSearchStats(docTokens, key, docs);
}

var score = tf * idf * fieldLengthNorm * penality;
Expand Down
10 changes: 9 additions & 1 deletion lib/tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,17 @@ elasticlunr.tokenizer = function (str) {
return true;
});

return arr.map(function (t) {
arr = arr.map(function (t) {
return elasticlunr.utils.toString(t).toLowerCase();
});

var out = [];
arr.forEach(function(item) {
var tokens = item.split(elasticlunr.tokenizer.seperator);
out = out.concat(tokens);
}, this);

return out;
}

return str.toString().trim().toLowerCase().split(elasticlunr.tokenizer.seperator);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "elasticlunr",
"description": "Lightweight full-text search engine in Javascript for browser search and offline search.",
"version": "0.8.6",
"version": "0.8.8",
"author": "Wei Song",
"keywords": ["search", "text retrieval", "offline search", "full text search"],
"homepage": "http://weixsong.github.io",
Expand Down
14 changes: 11 additions & 3 deletions release/elasticlunr.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* elasticlunr - http://weixsong.github.io
* Lightweight full-text search engine in Javascript for browser search and offline search. - 0.8.6
* Lightweight full-text search engine in Javascript for browser search and offline search. - 0.8.8
*
* Copyright (C) 2016 Oliver Nightingale
* Copyright (C) 2016 Wei Song
Expand Down Expand Up @@ -83,7 +83,7 @@ var elasticlunr = function (config) {
return idx;
};

elasticlunr.version = "0.8.6";
elasticlunr.version = "0.8.8";
/*!
* elasticlunr.utils
* Copyright (C) 2016 Oliver Nightingale
Expand Down Expand Up @@ -243,9 +243,17 @@ elasticlunr.tokenizer = function (str) {
return true;
});

return arr.map(function (t) {
arr = arr.map(function (t) {
return elasticlunr.utils.toString(t).toLowerCase();
});

var out = [];
arr.forEach(function(item) {
var tokens = item.split(elasticlunr.tokenizer.seperator);
out = out.concat(tokens);
}, this);

return out;
}

return str.toString().trim().toLowerCase().split(elasticlunr.tokenizer.seperator);
Expand Down
4 changes: 2 additions & 2 deletions release/elasticlunr.min.js

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions test/tokenizer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,27 @@ test("test get seperator function", function () {
elasticlunr.tokenizer.setSeperator(sep2);
deepEqual(elasticlunr.tokenizer.getSeperator(), sep2);
});

test("tokenize array", function () {
var str = ['hello world', 'glad to see you'];
var tokens = elasticlunr.tokenizer(str);
deepEqual(tokens, ['hello', 'world', 'glad', 'to', 'see', 'you']);
});

test("tokenize array 2", function () {
var str = ['helloworld', 'glad to see you'];
var tokens = elasticlunr.tokenizer(str);
deepEqual(tokens, ['helloworld', 'glad', 'to', 'see', 'you']);
});

test("tokenize array", function () {
var str = ['helloworld', null, undefined, 'glad to see you'];
var tokens = elasticlunr.tokenizer(str);
deepEqual(tokens, ['helloworld', 'glad', 'to', 'see', 'you']);
});

test("tokenize array", function () {
var str = ['helloworld', 'glad to see you', 'hyper-parameters'];
var tokens = elasticlunr.tokenizer(str);
deepEqual(tokens, ['helloworld', 'glad', 'to', 'see', 'you', 'hyper', 'parameters']);
});

0 comments on commit 31ab173

Please sign in to comment.