Sphinx 3.1.1 没有返回正确的片段
Sphinx 3.1.1 not returning correct snippet
我有一个 Sphinx 3.1.1.
安装,我想在其中显示使用 DocStore 找到的结果的片段。但是,该片段只是返回文档内容的开头。
我使用的查询:
SELECT id, SNIPPET(content, QUERY()) AS snippet FROM test_index WHERE MATCH('test');
这 returns 我的结果如下:
+--+--------------------------------------------------------+
|id |snippet |
+-----------------------------------------------------------+
|1 |this is a test document to test Sphinx 3.1.1 ... |
+-----------------------------------------------------------+
|2 |another test document to test Sphinx 3.1.1. ... |
+--+--------------------------------------------------------+
请注意,返回的片段在搜索词 test
周围没有突出显示 b
标记,并且返回的片段是文档的起始字符串。例如,如果我搜索 test2
,结果是相同的(文档在内容中进一步包含 test2
,但该片段仅显示内容中的前 x 个词,没有任何突出显示?)
我的索引配置是:
index test_index
{
type = rt
path = /mtn/data001/test_index
rt_field = content
stored_fields = content
}
我哪里做错了,为什么我的代码片段不包含高亮标记?
嗯,我刚刚尝试 copy/pasting 你的 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 关闭时)并重试。也许您以某种方式损坏了您的索引文件(例如,在创建它后更改了配置)——这在实验过程中很容易做到
我有一个 Sphinx 3.1.1.
安装,我想在其中显示使用 DocStore 找到的结果的片段。但是,该片段只是返回文档内容的开头。
我使用的查询:
SELECT id, SNIPPET(content, QUERY()) AS snippet FROM test_index WHERE MATCH('test');
这 returns 我的结果如下:
+--+--------------------------------------------------------+
|id |snippet |
+-----------------------------------------------------------+
|1 |this is a test document to test Sphinx 3.1.1 ... |
+-----------------------------------------------------------+
|2 |another test document to test Sphinx 3.1.1. ... |
+--+--------------------------------------------------------+
请注意,返回的片段在搜索词 test
周围没有突出显示 b
标记,并且返回的片段是文档的起始字符串。例如,如果我搜索 test2
,结果是相同的(文档在内容中进一步包含 test2
,但该片段仅显示内容中的前 x 个词,没有任何突出显示?)
我的索引配置是:
index test_index
{
type = rt
path = /mtn/data001/test_index
rt_field = content
stored_fields = content
}
我哪里做错了,为什么我的代码片段不包含高亮标记?
嗯,我刚刚尝试 copy/pasting 你的 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 关闭时)并重试。也许您以某种方式损坏了您的索引文件(例如,在创建它后更改了配置)——这在实验过程中很容易做到