sphinx 搜索 return 匹配和周围的字符
sphinx search return match and surrounding characters
在 Sphinx 中(使用 mysql 连接),我如何匹配一个术语并获得,比方说匹配前后的 5 个字符?
例如:一行包含this is a word in a sentence
.
当我查询时:SELECT term FROM table WHERE MATCH('"word*"')
我希望看到 is a word in a s
返回。这可能吗?
编辑 使用下面@barryhunter 的有用答案,现在试图弄清楚如何将其纳入我的查询:
SELECT field1,field2,SPHINX_SNIPPETS(field3,indexName, "word") as snippet FROM tableName
这就是 CALL SNIPPETS
的设计目的。虽然它是用文字来计算的,而不是字符。
http://sphinxsearch.com/docs/current/sphinxql-call-snippets.html
CALL SNIPPETS('this is a word in a sentance','index1','word', 2 AS around, 5 as limit_words);
会回来的
... is a word in a ...
add '' as chunk_separator
不需要省略号
编辑添加:然后如果想在搜索查询期间构建代码段(而不是作为单独的 CALL 查询),可以在初始 select 中使用 SNIPPET()
函数
http://sphinxsearch.com/docs/current.html#sphinxql-select
在 Sphinx 中(使用 mysql 连接),我如何匹配一个术语并获得,比方说匹配前后的 5 个字符?
例如:一行包含this is a word in a sentence
.
当我查询时:SELECT term FROM table WHERE MATCH('"word*"')
我希望看到 is a word in a s
返回。这可能吗?
编辑 使用下面@barryhunter 的有用答案,现在试图弄清楚如何将其纳入我的查询:
SELECT field1,field2,SPHINX_SNIPPETS(field3,indexName, "word") as snippet FROM tableName
这就是 CALL SNIPPETS
的设计目的。虽然它是用文字来计算的,而不是字符。
http://sphinxsearch.com/docs/current/sphinxql-call-snippets.html
CALL SNIPPETS('this is a word in a sentance','index1','word', 2 AS around, 5 as limit_words);
会回来的
... is a word in a ...
add '' as chunk_separator
不需要省略号
编辑添加:然后如果想在搜索查询期间构建代码段(而不是作为单独的 CALL 查询),可以在初始 select 中使用 SNIPPET()
函数
http://sphinxsearch.com/docs/current.html#sphinxql-select