简体   繁体   English

连接 node.js 和 sphinx 的最佳方式

[英]Best way to connect node.js and sphinx

I'm trying to search in sphinx from node.js code.我正在尝试从 node.js 代码中搜索狮身人面像。 The only way to do it I know is to connect to searchd as to mysqld server.我知道的唯一方法是连接到 searchd 作为 mysqld 服务器。 I'd absolutely all known mysql libraries, but no of them even connected to sphinx.我绝对知道 mysql 个库,但没有一个与 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. 最简单的方法可以是:将Sphinx表引擎安装到MySQL并通过任何Node.js-MySQL连接器使用它。

The better solution will be to implement sphinx client in node.js - it should be pretty easy. 更好的解决方案是在node.js中实现sphinx客户端-这应该很容易。 Just check the Sphinx PHP API - it's not so hard to recode it with node.js sockets. 只需检查Sphinx PHP API,就可以使用node.js套接字对其进行重新编码并不难。

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: 要使用MySQL客户端查询Sphinx的最新版本,您需要像这样配置MySQL协议侦听器:

listen = localhost:9306:mysql41

...and then connect to that port (9306 in this case) with your client. ...然后与您的客户端连接到该端口(在本例中为9306)。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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