Giter Club home page Giter Club logo

limestone's Introduction

Limestone is a Sphinx search server connector for Node.js

Usage:

var limestone = require("./limestone").SphinxClient(),

limestone.connect(9312, // port. 9312 is standard Sphinx port. also 'host:port' allowed
	      function(err) { // callback
		  if (err) {
		      console.log('Connection error: ' + err.message);
			  process.exit();
		  }
		  console.log('Connected, sending queries');
		  
		  limestone.query('test', function(err, answer) { // Simple query
			console.log('Simple query returned ' + answer.match_count + 'results');
		  });
		  
		  limestone.query( // Query with options
		      {'query':'test', maxmatches:1}, 
		      function(err, answer) {
			  limestone.disconnect();
			  console.log("Extended search for 'test' yielded " + 
				   answer.match_count + " results: " + 
				   JSON.stringify(answer));
		      });
	      });

To Use Build_Excerpts:

limestone.connect(9312,  // port
	function(err) { //callback
		if (err) {
		console.log('Connection error: ' + err);
		}
		console.log('Connected Build Excerpts');
		limestone.build_excerpts(
			[
				'this is my teste text to be highlighted', 
				'this is another test text to be highlighted'
			], // docs
			'questions_1',
			'test text',
			{},
			function(err, answer) {
				limestone.disconnect();
				console.log(JSON.stringify(answer));
			}
		);
	}
);

Bonus: persistent connection: You can ask sphinx to open a persistent connection. You can then make several request through the same connection

limestone.connect(9312, // port
	true, // persistent (optional)
	function(err) { // callback
		if (err){
			console.log('Connection error: ' + err);
		}
		console.log('Connected Search'); 
		console.log('sending query');  
		limestone.query({
			'query' : 'test', // query object with sphinx options
			'maxmatches' : 1,
			'indexes':'questions_1,products_3'},
			function(err, answer){ 			// callback
				console.log('Extended search yielded ' + 
					answer.match_count + " results\n" +
					JSON.stringify(answer));
			
				limestone.build_excerpts([
						'this is my test text to be highlighted', 
						'this is another test text to be highlighted'
					], // docs
					'questions_1', // index
					'test text', // words
					{},
					function(err, answer){
						limestone.disconnect();
						console.log(JSON.stringify(answer));
					}
				);
				  
			}
		);
	}
);

Limestone is queueing now: You can safely call limestone.query or limestone.build_excerpts methods outside the scope of the callback functions, provided the connection is made persistent. Limestone will enqueue the sphinx commands and run them sequentially.

This works:

limestone.connect(9312, // port. 9312 is standard Sphinx port
	      function(err) { // callback
	          ...
		  limestone.query(
		      {'query':'test', maxmatches:1}, 
		      function(err, answer) {
		          ....
		      });
	      });

limestone.query({'second query':'test'}, function(err, answer){..}); // won't crash with previous

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.