Indexing

Version 3.x ⚠

Moved to different package in modules indexing/searcher and indexing/writer.



Version 2.x

Indexing module is used for creating an in-memory full-text-search capable storage.

Basic Usage

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* globals $ */
/* eslint-env node, dirigible */

var indexing = require('service/indexing');
var response = require('net/http/response');

var index = indexing.getIndex("myIndex");
var document1 = {
       "id": "1",
       "content": "some cool content 1"
    };
var document2 = {
       "id": "2",
       "content": "some cool content 2"
    };

index.add(document1);
index.add(document2);

var results = index.search("cool");
for (var i=0;i<results.length;i++) {
	var result = results[i];
    response.println("[Found for 'cool']: " + result.id);    
}

results = index.search("1");
for (var i=0;i<results.length;i++) {
	result = results[i];
    response.println("[Found for '1']: " + result.id);
}

results = index.search("2");
for (var i=0;i<results.length;i++) {
	result = results[i];
    response.println("[Found for '2']: " + result.id);
}

index.clear();

response.flush();
response.close();

Definition

Functions


Function Description Returns
getIndex(name) Returns an Index by a given name. Creates it if needed. Index

Objects


Index
Function Description Returns
add(document) Adds a document to the Index -
search(term) Returns the matching documents array of Document
clear() Removes all the documents from the Index -
Document
Function Description Returns
id The ID of the Document string
content The content of the Document string

Compatibility

Rhino Nashorn V8
βœ… βœ… ❌
Edit