Skip to content

Commit

Permalink
Build version 0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
weixsong committed Jul 20, 2016
1 parent 59f5571 commit 80404de
Show file tree
Hide file tree
Showing 18 changed files with 128 additions and 155 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.mdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* remove useless variable length of elasticlunr.InvertedIndex.
* review code of elasticlunr.EventEmitter.
* review test cases of elasticlunr.EventEmitter.
* merge pull request from [BrianRosamilia](https://github.com/weixsong/elasticlunr.js/pull/20)

## 0.8.9

Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ SERVER_PORT ?= 3000
TEST_PORT ?= 32423

DOXX ?= ./node_modules/.bin/doxx
NODE ?= /usr/local/bin/node
NPM ?= /usr/local/bin/npm
NODE ?= /usr/bin/node
NPM ?= /usr/bin/npm
PHANTOMJS ?= ./node_modules/.bin/phantomjs
UGLIFYJS ?= ./node_modules/.bin/uglifyjs

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.8.9
0.9.0
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.9",
"version": "0.9.0",
"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.9",
"version": "0.9.0",
"description": "Lightweight full-text search engine in Javascript for browser search and offline search.",
"license": "MIT",
"main": "elasticlunr.js",
Expand Down
8 changes: 4 additions & 4 deletions docs/event_emitter.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ <h5 class="subheader"></h5>
<div class="label label-success radius ctx-type">constructor</div><span>elasticlunr.EventEmitter()</span>
</p>
</section>
<div class="description"><p>elasticlunr.EventEmitter is an event emitter for elasticlunr. It manages adding and removing event handlers and triggering events and their handlers.</p><p>Each event could has multiple corresponding functions, these functions will be called as the sequence that they are added into the event.</p> </div>
<div class="description"><p>elasticlunr.EventEmitter is an event emitter for elasticlunr.<br />It manages adding and removing event handlers and triggering events and their handlers.</p><p>Each event could has multiple corresponding functions,<br />these functions will be called as the sequence that they are added into the event.</p> </div>
<pre><code class="language-javascript">elasticlunr.EventEmitter = function () {
this.events = {};
};</code></pre>
Expand Down Expand Up @@ -184,7 +184,7 @@ <h5 class="subheader"></h5>
if (!this.hasHandler(name)) return;

var fnIndex = this.events[name].indexOf(fn);
if (fnIndex == -1) return;
if (fnIndex === -1) return;

this.events[name].splice(fnIndex, 1);

Expand Down Expand Up @@ -213,15 +213,15 @@ <h5 class="subheader"></h5>
</tr>
</tbody>
</table>
<div class="description"><p>Calls all functions bound to the given event.</p><p>Additional data can be passed to the event handler as arguments to <code>emit</code><br />after the event name.</p> </div>
<div class="description"><p>Call all functions that bounded to the given event.</p><p>Additional data can be passed to the event handler as arguments to <code>emit</code><br />after the event name.</p> </div>
<pre><code class="language-javascript">elasticlunr.EventEmitter.prototype.emit = function (name) {
if (!this.hasHandler(name)) return;

var args = Array.prototype.slice.call(arguments, 1);

this.events[name].forEach(function (fn) {
fn.apply(undefined, args);
});
}, this);
};</code></pre>
</div>
</div>
Expand Down
33 changes: 30 additions & 3 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,14 +178,14 @@ <h2>Example</h2>
index.setRef(&#39;id&#39;);
index.saveDocument(false);
</code></pre>
<p>Default supported language of elasticlunr.js is English, if you want to use elasticlunr.js to index other language documents, then you need to use elasticlunr.js combined with <a href="https://github.com/weixsong/lunr-languages">lunr-languages</a>.<br />Assume you&#39;re using lunr-language in Node.js envrionment, you could import lunr-language as followings:</p><pre><code class="lang-javascript">var elasticlunr = require(&#39;./lib/elasticlunr.js&#39;);
<p>Default supported language of elasticlunr.js is English, if you want to use elasticlunr.js to index other language documents, then you need to use elasticlunr.js combined with <a href="https://github.com/weixsong/lunr-languages">lunr-languages</a>.<br />Assume you&#39;re using lunr-language in Node.js envrionment, you could import lunr-language as followings:</p><pre><code class="lang-javascript">var elasticlunr = require(&#39;elasticlunr&#39;);
require(&#39;./lunr.stemmer.support.js&#39;)(elasticlunr);
require(&#39;./lunr.de.js&#39;)(elasticlunr);

var idx = elasticlunr(function () {
var index = elasticlunr(function () {
// use the language (de)
this.use(lunr.de);
// then, the normal lunr index initialization
// then, the normal elasticlunr index initialization
this.addField(&#39;title&#39;)
this.addField(&#39;body&#39;)
});
Expand Down Expand Up @@ -297,6 +297,33 @@ <h3>6.2 Add customized stop words</h3>
<p>User could add a list of customized stop words.</p><pre><code class="lang-javascript">var customized_stop_words = [&#39;an&#39;, &#39;hello&#39;, &#39;xyzabc&#39;];
elasticlunr.addStopWords(customized_stop_words);
</code></pre>
<h2>7. Use elasticlunr in Node.js</h2>
<p>Elasticlunr support Node.js, you could use elastilunr in node.js as a node-module.</p><p>Install elasticlunr by:</p><pre><code class="lang-javascript">npm install elasticlunr
</code></pre>
<p>then in your node.js project or in node.js console:</p><pre><code class="lang-javascript">var elasticlunr = require(&#39;elasticlunr&#39;);

var index = elasticlunr(function () {
this.addField(&#39;title&#39;)
this.addField(&#39;body&#39;)
});

var doc1 = {
&quot;id&quot;: 1,
&quot;title&quot;: &quot;Oracle released its latest database Oracle 12g&quot;,
&quot;body&quot;: &quot;Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year.&quot;
}

var doc2 = {
&quot;id&quot;: 2,
&quot;title&quot;: &quot;Oracle released its profit report of 2015&quot;,
&quot;body&quot;: &quot;As expected, Oracle released its profit report of 2015, during the good sales of database and hardware, Oracle&#39;s profit of 2015 reached 12.5 Billion.&quot;
}

index.addDoc(doc1);
index.addDoc(doc2);

index.search(&quot;Oracle database profit&quot;);
</code></pre>
<h1>Contributing</h1>
<p>See the <a href="CONTRIBUTING.mdown"><code>CONTRIBUTING.mdown</code> file</a>.</p></section>
</div>
Expand Down
32 changes: 0 additions & 32 deletions docs/index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -631,38 +631,6 @@ <h5 class="subheader"></h5>
results.sort(function (a, b) { return b.score - a.score; });
return results;
};</code></pre>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th style="width:20%">Option name</th>
<th style="width:20%">Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>queryTokens</td>
<td>Array</td>
<td><p>The query tokens to query in this field.</p></td>
</tr>
<tr>
<td>field</td>
<td>String</td>
<td><p>Field to query in.</p></td>
</tr>
<tr>
<td>config</td>
<td>elasticlunr.Configuration</td>
<td><p>The user query config, JSON format.</p></td>
</tr>
<tr>
<td>return</td>
<td>Object</td>
<td></td>
</tr>
</tbody>
</table>
<div class="description"><p>search queryTokens in specified field.</p> </div>
<section id="fieldSearch">
<h1>fieldSearch</h1>
<h5 class="subheader"></h5>
Expand Down
25 changes: 10 additions & 15 deletions docs/inverted_index.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,9 @@ <h5 class="subheader"></h5>
<div class="label label-success radius ctx-type">constructor</div><span>elasticlunr.InvertedIndex()</span>
</p>
</section>
<div class="description"><p>elasticlunr.InvertedIndex is used for efficient storing and lookup of the inverted index of token to document ref.</p> </div>
<div class="description"><p>elasticlunr.InvertedIndex is used for efficiently storing and<br />lookup of documents that contain a given token.</p> </div>
<pre><code class="language-javascript">elasticlunr.InvertedIndex = function () {
this.root = { docs: {}, df: 0 };
this.length = 0;
};</code></pre>
<section id="load">
<h1>load</h1>
Expand Down Expand Up @@ -156,9 +155,7 @@ <h5 class="subheader"></h5>
<div class="description"><p>Loads a previously serialised inverted index.</p> </div>
<pre><code class="language-javascript">elasticlunr.InvertedIndex.load = function (serialisedData) {
var idx = new this;

idx.root = serialisedData.root;
idx.length = serialisedData.length;

return idx;
};</code></pre>
Expand Down Expand Up @@ -195,7 +192,7 @@ <h5 class="subheader"></h5>
</tr>
</tbody>
</table>
<div class="description"><p>Adds a {token: tokenInfo} pair to the inverted index.<br />If the token already exist, then update the tokenInfo.</p><p>By default this function starts at the root of the current inverted index, however<br />it can start at any node of the inverted index if required.</p> </div>
<div class="description"><p>Adds a {token: tokenInfo} pair to the inverted index.<br />If the token already exist, then update the tokenInfo.</p><p>tokenInfo format: { ref: 1, tf: 2}<br />tokenInfor should contains the document&#39;s ref and the tf(token frequency) of that token in<br />the document.</p><p>By default this function starts at the root of the current inverted index, however<br />it can start at any node of the inverted index if required.</p> </div>
<pre><code class="language-javascript">elasticlunr.InvertedIndex.prototype.addToken = function (token, tokenInfo, root) {
var root = root || this.root,
idx = 0;
Expand All @@ -213,7 +210,6 @@ <h5 class="subheader"></h5>
// if this doc not exist, then add this doc
root.docs[docRef] = {tf: tokenInfo.tf};
root.df += 1;
this.length += 1;
} else {
// if this doc already exist, then update tokenInfo
root.docs[docRef] = {tf: tokenInfo.tf};
Expand All @@ -238,7 +234,7 @@ <h5 class="subheader"></h5>
<tr>
<td>token</td>
<td>String</td>
<td><p>The token to check</p></td>
<td><p>The token to be checked</p></td>
</tr>
<tr>
<td>return</td>
Expand All @@ -247,7 +243,7 @@ <h5 class="subheader"></h5>
</tr>
</tbody>
</table>
<div class="description"><p>Checks whether this key is in this elasticlunr.InvertedIndex.</p> </div>
<div class="description"><p>Checks whether a token is in this elasticlunr.InvertedIndex.</p> </div>
<pre><code class="language-javascript">elasticlunr.InvertedIndex.prototype.hasToken = function (token) {
if (!token) return false;

Expand Down Expand Up @@ -329,7 +325,7 @@ <h5 class="subheader"></h5>
</tr>
</tbody>
</table>
<div class="description"><p>Retrieve the documents for a given token.<br />If token not found, return {}.</p> </div>
<div class="description"><p>Retrieve the documents of a given token.<br />If token not found, return {}.</p> </div>
<pre><code class="language-javascript">elasticlunr.InvertedIndex.prototype.getDocs = function (token) {
var node = this.getNode(token);
if (node == null) {
Expand Down Expand Up @@ -442,16 +438,16 @@ <h5 class="subheader"></h5>
<tr>
<td>token</td>
<td>String</td>
<td><p>The token to get the documents for.</p></td>
<td><p>Remove the document from which token.</p></td>
</tr>
<tr>
<td>ref</td>
<td>String</td>
<td><p>The ref of the document to remove from this token.</p></td>
<td><p>The ref of the document to remove from given token.</p></td>
</tr>
</tbody>
</table>
<div class="description"><p>Remove the document identified by ref from the token in the inverted index.</p> </div>
<div class="description"><p>Remove the document identified by document&#39;s ref from the token in the inverted index.</p> </div>
<pre><code class="language-javascript">elasticlunr.InvertedIndex.prototype.removeToken = function (token, ref) {
if (!token) return;
var node = this.getNode(token);
Expand Down Expand Up @@ -491,7 +487,7 @@ <h5 class="subheader"></h5>
</tr>
</tbody>
</table>
<div class="description"><p>Find all the possible suffixes of the passed token using tokens currently in the inverted index.<br />If token not found, return empty Array.</p> </div>
<div class="description"><p>Find all the possible suffixes of given token using tokens currently in the inverted index.<br />If token not found, return empty Array.</p> </div>
<pre><code class="language-javascript">elasticlunr.InvertedIndex.prototype.expandToken = function (token, memo, root) {
if (token == null || token == '') return [];
var memo = memo || [];
Expand Down Expand Up @@ -521,8 +517,7 @@ <h5 class="subheader"></h5>
<div class="description"><p>Returns a representation of the inverted index ready for serialisation.</p> </div>
<pre><code class="language-javascript">elasticlunr.InvertedIndex.prototype.toJSON = function () {
return {
root: this.root,
length: this.length
root: this.root
};
};</code></pre>
</div>
Expand Down
Loading

0 comments on commit 80404de

Please sign in to comment.