Sphinx 3.1.1未返回正确的代码段

时间:2018-11-20 10:01:06

标签: sphinx

我有一个Sphinx 3.1.1.安装,我想在其中显示使用DocStore找到的结果的摘要。但是,该代码段只是返回文档内容的开头。

我使用的查询:

SELECT id, SNIPPET(content, QUERY()) AS snippet FROM test_index WHERE MATCH('test');

这将给我返回如下结果:

+--+--------------------------------------------------------+
|id |snippet                                                |                
+-----------------------------------------------------------+
|1  |this is a test document to test Sphinx 3.1.1 ...       |
+-----------------------------------------------------------+
|2  |another test document to test Sphinx 3.1.1. ...        |
+--+--------------------------------------------------------+

请注意,返回的代码段在搜索词b周围没有突出显示的test标签,并且返回的代码段是文档的起始字符串。例如,如果我搜索test2,结果是相同的(文档中的内容进一步包含test2,但是该片段仅显示内容中的前x个单词,而没有突出显示?)

我的索引的配置是:

index test_index
{
    type          = rt
    path          = /mtn/data001/test_index
    rt_field      = content
    stored_fields = content
}

我做错了什么,为什么我的代码片段不包含突出显示标签?

1 个答案:

答案 0 :(得分:1)

嗯,我只是尝试将test_index复制/粘贴到配置文件,然后启动sphinx3实例...

barry@tea:~/sphinx-3.1.1$ bin/searchd --config test.conf
Sphinx 3.1.1 (commit 612d99f)
Copyright (c) 2001-2018, Andrew Aksyonoff
Copyright (c) 2008-2016, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file 'test.conf'...
listening on all interfaces, port=10312
listening on all interfaces, port=10306
precaching index 'test_index'
precached 1 indexes in 0.001 sec

barry@tea:~/sphinx-3.1.1$ mysql --protocol=tcp -P10306  --prompt='sphinxQL3>' --default-character-set=utf8
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 3.1.1 (commit 612d99f)

sphinxQL3>SELECT id, DOCUMENT() as doc, DOCUMENT({content}) FROM test_index WHERE MATCH('test');
Empty set (0.00 sec)

sphinxQL3>insert into test_index values (1,'this is a test');
Query OK, 1 row affected (0.00 sec)

sphinxQL3>insert into test_index values (2,'this is a test more');
Query OK, 1 row affected (0.00 sec)

sphinxQL3>SELECT id, SNIPPET(DOCUMENT({content}), QUERY()) AS snippet FROM test_index WHERE MATCH('test');
+------+----------------------------+
| id   | snippet                    |
+------+----------------------------+
|    1 | this is a <b>test</b>      |
|    2 | this is a <b>test</b> more |
+------+----------------------------+
2 rows in set (0.00 sec)

sphinxQL3>SELECT id, SNIPPET(content, QUERY()) AS snippet FROM test_index WHERE MATCH('test');
+------+----------------------------+
| id   | snippet                    |
+------+----------------------------+
|    1 | this is a <b>test</b>      |
|    2 | this is a <b>test</b> more |
+------+----------------------------+
2 rows in set (0.00 sec)

sphinxQL3>SELECT id, SNIPPET(content, QUERY()) AS snippet FROM test_index WHERE MATCH('more');
+------+----------------------------+
| id   | snippet                    |
+------+----------------------------+
|    2 | this is a test <b>more</b> |
+------+----------------------------+
1 row in set (0.00 sec)

sphinxQL3>insert into test_index values (3,'this is a test document to test Sphinx 3.1.1 Technically, Sphinx is a standalone software package provides fast and relevant full-text search functionality to client applications. It was specially designed to integrate well with SQL databases storing the data, and to be easily accessed by scripting languages. However, Sphinx does not depend on nor require any specific database to function. ');
Query OK, 1 row affected (0.00 sec)

sphinxQL3>SELECT id, SNIPPET(content, QUERY()) AS snippet FROM test_index WHERE MATCH('test');                                                                                                    +------+-------------------------------------------------------------------------------+
| id   | snippet                                                                       |
+------+-------------------------------------------------------------------------------+
|    1 | this is a <b>test</b>                                                         |
|    2 | this is a <b>test</b> more                                                    |
|    3 | this is a <b>test</b> document to <b>test</b> Sphinx 3.1.1 Technically,  ...  |
+------+-------------------------------------------------------------------------------+
3 rows in set (0.00 sec)

sphinxQL3>SELECT id, SNIPPET(content, QUERY()) AS snippet FROM test_index WHERE MATCH('scripting');
+------+------------------------------------------------------------------------------------------+
| id   | snippet                                                                                  |
+------+------------------------------------------------------------------------------------------+
|    3 |  ...  to be easily accessed by <b>scripting</b> languages. However, Sphinx does not ...  |
+------+------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

因此,似乎3.1.1确实可以正常工作,但是您的配置有些奇怪。

也许尝试删除test_index文件(当searchd关闭时),然后重试。也许您已经以某种方式破坏了索引文件(例如,自创建以来更改了配置)-在实验过程中这样做很容易