Sphinx 3.1.1 not returning correct snippet
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?
sphinx
add a comment |
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?
sphinx
have you tried usinghl_fields
? to precompute structure for the snippet. Also not entirely sure what it does, but have tried accessing content with DOCUMENT(), the docs seems to implyDOCUMENT({content})
might work?
– barryhunter
Nov 20 '18 at 10:28
@barryhunter, that is for building a snippet based on the content of a subdocument right? Besides, thehl_fields
directive is only to speed up snippet building right?
– Thomas van Hesteren
Nov 20 '18 at 10:52
Well dont think 'subdocument' is really a concept, its just the language of the documentation.
– barryhunter
Nov 20 '18 at 11:38
add a comment |
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?
sphinx
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?
sphinx
sphinx
asked Nov 20 '18 at 10:01
Thomas van HesterenThomas van Hesteren
5318
5318
have you tried usinghl_fields
? to precompute structure for the snippet. Also not entirely sure what it does, but have tried accessing content with DOCUMENT(), the docs seems to implyDOCUMENT({content})
might work?
– barryhunter
Nov 20 '18 at 10:28
@barryhunter, that is for building a snippet based on the content of a subdocument right? Besides, thehl_fields
directive is only to speed up snippet building right?
– Thomas van Hesteren
Nov 20 '18 at 10:52
Well dont think 'subdocument' is really a concept, its just the language of the documentation.
– barryhunter
Nov 20 '18 at 11:38
add a comment |
have you tried usinghl_fields
? to precompute structure for the snippet. Also not entirely sure what it does, but have tried accessing content with DOCUMENT(), the docs seems to implyDOCUMENT({content})
might work?
– barryhunter
Nov 20 '18 at 10:28
@barryhunter, that is for building a snippet based on the content of a subdocument right? Besides, thehl_fields
directive is only to speed up snippet building right?
– Thomas van Hesteren
Nov 20 '18 at 10:52
Well dont think 'subdocument' is really a concept, its just the language of the documentation.
– barryhunter
Nov 20 '18 at 11:38
have you tried using
hl_fields
? to precompute structure for the snippet. Also not entirely sure what it does, but have tried accessing content with DOCUMENT(), the docs seems to imply DOCUMENT({content})
might work?– barryhunter
Nov 20 '18 at 10:28
have you tried using
hl_fields
? to precompute structure for the snippet. Also not entirely sure what it does, but have tried accessing content with DOCUMENT(), the docs seems to imply DOCUMENT({content})
might work?– barryhunter
Nov 20 '18 at 10:28
@barryhunter, that is for building a snippet based on the content of a subdocument right? Besides, the
hl_fields
directive is only to speed up snippet building right?– Thomas van Hesteren
Nov 20 '18 at 10:52
@barryhunter, that is for building a snippet based on the content of a subdocument right? Besides, the
hl_fields
directive is only to speed up snippet building right?– Thomas van Hesteren
Nov 20 '18 at 10:52
Well dont think 'subdocument' is really a concept, its just the language of the documentation.
– barryhunter
Nov 20 '18 at 11:38
Well dont think 'subdocument' is really a concept, its just the language of the documentation.
– barryhunter
Nov 20 '18 at 11:38
add a comment |
1 Answer
1
active
oldest
votes
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
That might be very well possible indeed. I have perhaps made some changes without updating the index. To be sure, I will recreate the index. Thanks for doing some quick tests
– Thomas van Hesteren
Nov 20 '18 at 12:04
You where right, I have rebuild my index and now it works fine! Thanks
– Thomas van Hesteren
Nov 20 '18 at 12:36
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390473%2fsphinx-3-1-1-not-returning-correct-snippet%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
That might be very well possible indeed. I have perhaps made some changes without updating the index. To be sure, I will recreate the index. Thanks for doing some quick tests
– Thomas van Hesteren
Nov 20 '18 at 12:04
You where right, I have rebuild my index and now it works fine! Thanks
– Thomas van Hesteren
Nov 20 '18 at 12:36
add a comment |
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
That might be very well possible indeed. I have perhaps made some changes without updating the index. To be sure, I will recreate the index. Thanks for doing some quick tests
– Thomas van Hesteren
Nov 20 '18 at 12:04
You where right, I have rebuild my index and now it works fine! Thanks
– Thomas van Hesteren
Nov 20 '18 at 12:36
add a comment |
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
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
answered Nov 20 '18 at 11:43
barryhunterbarryhunter
19.1k22235
19.1k22235
That might be very well possible indeed. I have perhaps made some changes without updating the index. To be sure, I will recreate the index. Thanks for doing some quick tests
– Thomas van Hesteren
Nov 20 '18 at 12:04
You where right, I have rebuild my index and now it works fine! Thanks
– Thomas van Hesteren
Nov 20 '18 at 12:36
add a comment |
That might be very well possible indeed. I have perhaps made some changes without updating the index. To be sure, I will recreate the index. Thanks for doing some quick tests
– Thomas van Hesteren
Nov 20 '18 at 12:04
You where right, I have rebuild my index and now it works fine! Thanks
– Thomas van Hesteren
Nov 20 '18 at 12:36
That might be very well possible indeed. I have perhaps made some changes without updating the index. To be sure, I will recreate the index. Thanks for doing some quick tests
– Thomas van Hesteren
Nov 20 '18 at 12:04
That might be very well possible indeed. I have perhaps made some changes without updating the index. To be sure, I will recreate the index. Thanks for doing some quick tests
– Thomas van Hesteren
Nov 20 '18 at 12:04
You where right, I have rebuild my index and now it works fine! Thanks
– Thomas van Hesteren
Nov 20 '18 at 12:36
You where right, I have rebuild my index and now it works fine! Thanks
– Thomas van Hesteren
Nov 20 '18 at 12:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390473%2fsphinx-3-1-1-not-returning-correct-snippet%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
have you tried using
hl_fields
? to precompute structure for the snippet. Also not entirely sure what it does, but have tried accessing content with DOCUMENT(), the docs seems to implyDOCUMENT({content})
might work?– barryhunter
Nov 20 '18 at 10:28
@barryhunter, that is for building a snippet based on the content of a subdocument right? Besides, the
hl_fields
directive is only to speed up snippet building right?– Thomas van Hesteren
Nov 20 '18 at 10:52
Well dont think 'subdocument' is really a concept, its just the language of the documentation.
– barryhunter
Nov 20 '18 at 11:38