Skip to content

A Node.js native module that gives you advanced searching via CLucene--itself a C++ port of Lucene

Notifications You must be signed in to change notification settings

temas/node-clucene

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OVERVIEW

node-clucene is a native Node.js module that wraps up the CLucene library. CLucene is a C++ port of the ubiquitous Java Lucene library. The Lucene ecosystem is vibrant, and lots of great code has come out of it. However, for those who do not wish to run a JVM-based information retrieval system, CLucene makes a lot of sense.

CLucene is based on a port of Lucene 2.3. Unfortunately, there's been a lot of new updates and features added since then. The goal is to add features to this module as necessary, without rewriting it to map method-to-method with the current version of Lucene.

Right now, adding a document with the same docId will replace the older document in the index that has the same docId. This is intentional, and makes document updating simple. In the future, this will probably get refactored into a separate updateDocument() method call instead, and revert addDocument() back to adding only.

This library begun as a project from Tyler Gillies (http://github.com/tjgillies/node-lucene). Mad props to him for getting this library bootstrapped and running!

HOW IT WORKS:

Indexing information into the index

	var cl = require('clucene').CLucene;
	var doc = new cl.Document();
	
	doc.addField('name', 'Eric Jennings', cl.Store.STORE_YES|cl.Index.INDEX_TOKENIZED);
	doc.addField('timestamp', 'Eric Jennings', cl.Store.STORE_YES|cl.Index.INDEX_UNTOKENIZED);
	
	lucene.addDocument(docId, doc, '/path/where/to/store/index', function(err, indexTime, docsReplaced) {
			if (err) {
					console.log('Error indexing document: ' + err);
			}
			
			console.log('Indexed document in ' + indexTime + ' ms');
			
			if (docsReplaced > 0) {
					console.log('Updated ' + docsReplaced + ' existing document(s)');
			}
	});

Querying information out of the index

	var cl = require('./clucene').CLucene;
	var lucene = new cl.Lucene();
	var util = require('util');
	
	var queryTerm = 'name:Eri*'

	lucene.search('/path/where/index/stored', queryTerm, function(err, results) {
			if (err) {
					console.log('Search error: ' + err);
					return;
			}
			
			console.log('Search results: ');
			
			for (var i=0; i<results.length; i++) {
				console.log(results[i]);
			}
	});

REQUIREMENTS:

node-clucene requires the CLucene library. This is not included in this module, you must install it on your own. Instructions can be found here (http://clucene.sourceforge.net/)

About

A Node.js native module that gives you advanced searching via CLucene--itself a C++ port of Lucene

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 69.3%
  • JavaScript 18.5%
  • C 12.2%