Best way to connect node.js and sphinx
I'm 开发者_如何学JAVAtrying to search in sphinx from node.js code. The only way to do it I know is to connect to searchd as to mysqld server. I'd absolutely all known mysql libraries, but no of them even connected to sphinx.
Also you can try to use https://github.com/kurokikaze/limestone, but it may be a bit outdated.
The simplest way can be: Install Sphinx table engine to MySQL and use it using any Node.js-MySQL connector.
The better solution will be to implement sphinx client in node.js - it should be pretty easy. Just check the Sphinx PHP API - it's not so hard to recode it with node.js sockets.
Are you connecting to the right port? To query the latest version of Sphinx with a MySQL client you need to configure a MySQL protocol listener like so:
listen = localhost:9306:mysql41
...and then connect to that port (9306 in this case) with your client.
npm install sphinxapi
npm install mysql
var mysql = require('mysql');
var connection = mysql.createConnection(
{
localAddress : '127.0.0.1',
port : '9306'
}
);
connection.connect();
var queryString = "SELECT date FROM emails WHERE MATCH('@message mysql')limit 100";
connection.query(queryString, function(err, rows, fields) {
if (err) throw err;
for (var i in rows) {
console.log('date:', rows[i].date);
}
});
connection.end();
精彩评论