Reputation: 123
I have a Sphinx 3.1.1.
installation where I want to show snippets for the found results using DocStore. However, the snippet is just returning the beginning of the content of the document.
The query I use:
SELECT id, SNIPPET(content, QUERY()) AS snippet FROM test_index WHERE MATCH('test');
This returns me results like:
+--+--------------------------------------------------------+
|id |snippet |
+-----------------------------------------------------------+
|1 |this is a test document to test Sphinx 3.1.1 ... |
+-----------------------------------------------------------+
|2 |another test document to test Sphinx 3.1.1. ... |
+--+--------------------------------------------------------+
Please note that the returned snippets have no highlighting b
-tags around the search word test
and the returned snippet is the starting string of the document. If I for instance search for test2
, the results are the same (the documents contain test2
further in the content, but the snippet only shows the first x words from the content without any highlighting?)
The configuration of my index is:
index test_index
{
type = rt
path = /mtn/data001/test_index
rt_field = content
stored_fields = content
}
What am I doing wrong and why does my snippet not contain highlight tags?
Upvotes: 0
Views: 435
Reputation: 21091
Hmm, I just tried copy/pasting your test_index to a config file, and starting a sphinx3 instance...
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)
So it seems that 3.1.1 does work as such, but something odd is going on with your configuration.
Maybe try deleting the test_index files (while searchd is shutdown) and trying again. Maybe you've somehow corrupted your index files (eg changed the config since creating it) - this is quite easy to do during experimentation
Upvotes: 2