我有工作代码:
PHP:
$conn = new PDO('mysql:host=ubuntu;port=9306;charset=utf8','','');
$query = $conn->quote($_GET['query']);
$sql = "SELECT *,SNIPPET(content,$query) AS `snippet` FROM `test1` WHERE MATCH($query)";
foreach ($conn->query($sql) as $info) {
echo $info['snippet']. "<br><br>";
}
$_SESSION['phrase'] = $query; // Only 1 word here now (or phrase with space), while need in array.
和JS:
markInstance = new Mark(textCont);
markInstance.mark(phrase, {}); // from $_SESSION['phrase']
highlighted = [...textCont.querySelectorAll('mark')];
positions = highlighted.map(el => el.offsetTop);
我在片段输出(词干提取)中有一些不同的突出显示的单词。但其中只有一个由 Mark.JS 突出显示.
我也想使用所有已建立的词干作为 html 文件中突出显示的单词。如何在 Mark.js 中使用 Sphinx 的词干结果?
最佳答案
好的,所以您需要以某种方式在 Mark.js 中实现词干提取支持。也许有类似的东西 https://github.com/MarkKahn/stem作为灵感
...使用了很多正则表达式,因此也许可以将它们实现为 mark.js 中的正则表达式突出显示。
(忘记了 sphinx 中的词干提取功能,不确定它的任何直接用途(除了暗示它可以实现)。您不能直接在 mark.js 中使用 sphinxes 引擎)
关于javascript - 如何在Mark.JS中获取词干突出显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51369352/