简体   繁体   中英

Best way to connect node.js and sphinx

I'm trying 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.

您也可以尝试使用https://github.com/kurokikaze/limestone ,但这可能有点过时了。

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM