我在 Sphinx 中使用 regexp_filter 替换术语
在大多数情况下,我可以这样做,例如拼写错误很容易:
regexp_filter = Backround => Background
甚至使用捕获组表示法进行交换:
regexp_filter = (Left)(Right) => \2\1
但是,在使用模式匹配来查找要替换的给定单词时,我遇到了更多麻烦:
regexp_filter = (PatternWord1|PatternWord2)\W+(?:\w+\W+){1,6}?(SearchTerm)\b => NewSearchTerm
其中 NewSearchTerm 将是我只想替换 \2 的术语(仅留下 \1 和模式的其余部分)。所以
因此,如果我当时有文字'Pizza and Taco Parlor'
:
regexp_filter = (Pizza)\W+(?:\w+\W+){1,6}?(Parlor)\b => Store
将转换为'Pizza and Taco Store'
我知道在这种情况下 SearchTerm 是 /2 但不确定如何转换。我知道我可以附加 eg /2s 使其成为复数,但实际上我该如何替换它,因为它只是一个由多个捕获组组成的捕获组,而我只想替换该组?