如何在LINUX(ubuntu)上安装Sphinx

发布于 2024-12-27 18:18:03 字数 3205 浏览 1 评论 0原文

我是 Raja,我正在使用 PHP 进行 Web 开发。最近我应该将“Sphinx”搜索安装到我的应用程序中,并使用 LINUX 作为操作系统。

中给出的说明进行操作

我已按照本网站http://www .howtoforge.com/how-to-install-sphinx-on-ubuntu-10.10

在 LINUX(Ubuntu) 操作系统中安装 sphinx 并且我已经在终端中测试了该应用程序,我得到了像这样的结果

root@dev2:/# search "test"
Sphinx 0.9.9-release (r2117)
Copyright (c) 2001-2009, Andrew Aksyonoff

using config file '/etc/sphinxsearch/sphinx.conf'...
index 'test1': query 'test ': returned 3 matches of 3 total in 0.000 sec

displaying matches:
1. document=1, weight=2, group_id=1, date_added=Thu Jan  5 18:18:55 2012
        id=1
        group_id=1
        group_id2=5
        date_added=2012-01-05 18:18:55
        title=test one
        content=this is my test document number one. also checking search within phrases.
2. document=2, weight=2, group_id=1, date_added=Thu Jan  5 18:18:55 2012
        id=2
        group_id=1
        group_id2=6
        date_added=2012-01-05 18:18:55
        title=test two
        content=this is my test document number two
3. document=4, weight=1, group_id=2, date_added=Thu Jan  5 18:18:55 2012
        id=4
        group_id=2
        group_id2=8
        date_added=2012-01-05 18:18:55
        title=doc number four
        content=this is to test groups

words:
1. 'test': 3 documents, 5 hits

问题是,我在位置“/var/www/sphinx_search”创建了目录,其中包含 sphinx.conf、sphinxapi.php 和 test.php 文件。

sphinx.conf 背后的代码是

source src1
{
    type = mysql
    sql_host = localhost
    sql_user = user
    sql_pass = pwd
    sql_db = test
    sql_port = 3306 # optional, default is 3306
    sql_query = \
    SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
    FROM documents
    sql_attr_uint = group_id
    sql_attr_timestamp = date_added
    sql_query_info = SELECT * FROM documents WHERE id=$id
}

index test1
{
    source = src1
    path = /var/lib/sphinxsearch/data/test1
    docinfo = extern
    charset_type = sbcs
}

indexer
{
    mem_limit = 32M
}

searchd
{
    port = 9312
    log = /var/log/sphinxsearch/searchd.log
    query_log = /var/log/sphinxsearch/query.log
    read_timeout = 5
    max_children = 30
    pid_file = /var/run/searchd.pid
    max_matches = 1000
    seamless_rotate = 1
    preopen_indexes = 0
    unlink_old = 1
}

test.php 背后的代码是

require_once('sphinxapi.php');
//require_once('api/sphinxapi.php');
$s = new SphinxClient;
$s->setServer("123.123.123.123", 9312); // NOT "localhost" under Windows 7!
$s->setMatchMode(SPH_MATCH_EXTENDED2);

$result = $s->Query("group");

echo '<pre>';print_r($result);

当我尝试在浏览器中运行此应用程序时(http://localhost/Raja/search_engine/sphinx/),会显示此错误。

{"status":"failed","status_message":"connection to localhost:9312 failed (errno=10060, msg=A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)"}

由于我是 Sphinx 的新手,我无法立即获得它。任何人都可以帮助我进一步进行。

好奇地早点寻找解决方案,

提前致谢, 拉贾。

This is Raja, I'm using PHP for my web development. Recently i was supposed to install "Sphinx" search into my application with LINUX as OS.

I've followed the instruction given in this website

http://www.howtoforge.com/how-to-install-sphinx-on-ubuntu-10.10

to install sphinx in LINUX(Ubuntu) OS and I've tested the application in the terminal, i got the results like this

root@dev2:/# search "test"
Sphinx 0.9.9-release (r2117)
Copyright (c) 2001-2009, Andrew Aksyonoff

using config file '/etc/sphinxsearch/sphinx.conf'...
index 'test1': query 'test ': returned 3 matches of 3 total in 0.000 sec

displaying matches:
1. document=1, weight=2, group_id=1, date_added=Thu Jan  5 18:18:55 2012
        id=1
        group_id=1
        group_id2=5
        date_added=2012-01-05 18:18:55
        title=test one
        content=this is my test document number one. also checking search within phrases.
2. document=2, weight=2, group_id=1, date_added=Thu Jan  5 18:18:55 2012
        id=2
        group_id=1
        group_id2=6
        date_added=2012-01-05 18:18:55
        title=test two
        content=this is my test document number two
3. document=4, weight=1, group_id=2, date_added=Thu Jan  5 18:18:55 2012
        id=4
        group_id=2
        group_id2=8
        date_added=2012-01-05 18:18:55
        title=doc number four
        content=this is to test groups

words:
1. 'test': 3 documents, 5 hits

The Problem is that, I've created the directory in the location "/var/www/sphinx_search", which contains sphinx.conf, sphinxapi.php and test.php files.

the code behind sphinx.conf is

source src1
{
    type = mysql
    sql_host = localhost
    sql_user = user
    sql_pass = pwd
    sql_db = test
    sql_port = 3306 # optional, default is 3306
    sql_query = \
    SELECT id, group_id, UNIX_TIMESTAMP(date_added) AS date_added, title, content \
    FROM documents
    sql_attr_uint = group_id
    sql_attr_timestamp = date_added
    sql_query_info = SELECT * FROM documents WHERE id=$id
}

index test1
{
    source = src1
    path = /var/lib/sphinxsearch/data/test1
    docinfo = extern
    charset_type = sbcs
}

indexer
{
    mem_limit = 32M
}

searchd
{
    port = 9312
    log = /var/log/sphinxsearch/searchd.log
    query_log = /var/log/sphinxsearch/query.log
    read_timeout = 5
    max_children = 30
    pid_file = /var/run/searchd.pid
    max_matches = 1000
    seamless_rotate = 1
    preopen_indexes = 0
    unlink_old = 1
}

and the code behind test.php is

require_once('sphinxapi.php');
//require_once('api/sphinxapi.php');
$s = new SphinxClient;
$s->setServer("123.123.123.123", 9312); // NOT "localhost" under Windows 7!
$s->setMatchMode(SPH_MATCH_EXTENDED2);

$result = $s->Query("group");

echo '<pre>';print_r($result);

when i'm trying to run this application in browser (http://localhost/Raja/search_engine/sphinx/) this error is getting displayed.

{"status":"failed","status_message":"connection to localhost:9312 failed (errno=10060, msg=A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)"}

As i'm new to Sphinx, i cant get it right away. Can anybody help me to proceed further.

Curiously looking for a solution earlier,

Thanks in Advance,
Raja.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅语花开 2025-01-03 18:18:03

在您的搜索示例中,您使用搜索实用程序,该实用程序不需要运行 searchd 守护进程。这就是搜索成功执行的原因。

要使用 sphinx API,您需要启动 searchd 守护进程,例如:

/path/to/searchd --config /etc/sphinxsearch/sphinx.conf

如果您使用 apt-get 安装了 sphinx,则尝试:

searchd --config /etc/sphinxsearch/sphinx.conf

之后您可以在浏览器中尝试应用程序。

但是,我不明白这一点

$s->setServer("123.123.123.123", 9312); // NOT "localhost" under Windows 7!

你说你在ubuntu下运行sphinx,而不是windows 7。所以,sphinx服务器IP应该是ubuntu主机的IP,而不是localhost。

顺便说一句,ubuntu 附带旧版本的 Sphinx,我建议从 sphinxsearch.com 下载最新版本。最新版本是2.0.3

In your example with search you using search utility which don't require searchd daemon to be running. That's why search is executed successfully.

To use sphinx API you need to start searchd daemon, like:

/path/to/searchd --config /etc/sphinxsearch/sphinx.conf

If you installed sphinx using apt-get then try:

searchd --config /etc/sphinxsearch/sphinx.conf

After that you could try application in browser.

But, I don't understand this

$s->setServer("123.123.123.123", 9312); // NOT "localhost" under Windows 7!

You said you running sphinx under ubuntu, not windows 7. So, sphinx server IP should be IP of ubuntu host, not localhost.

BTW, ubuntu ship old version of Sphinx, I would recommend to download latest from sphinxsearch.com. Latest version is 2.0.3

对风讲故事 2025-01-03 18:18:03

将你的 setServer() 更改为这个

$s->SetServer('localhost', 'mysql_user_name', 'mysql_password', 3312);

,并在你的 sphinx.conf 中将端口设置为 3312

port = 3312

我想这可能对你有用。如果不告诉我发生了什么事。

change your setServer() to this one

$s->SetServer('localhost', 'mysql_user_name', 'mysql_password', 3312);

and set the port as 3312 in your sphinx.conf

port = 3312

I thing this might work for you. If not tell me what happened.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文