我需要做一些与 Solr 的同义词匹配。
例如,在瑞典,街道名称通常采用Foogatan
where gatan 是英语中街道名称的形式。这个街道名称可以写成缩写形式Foog.
(有点像你用英文写st.
的street
)
我熟悉它的synonyms.txt
工作原理,但我不知道如何创建一个同义词来检查它是否包含一些字母 beforegatan
或 before g.
。
我需要一个与 and 匹配的*g.
同义词*gatan
。
我最终这样做了(似乎是我所追求的草稿)
public boolean incrementToken() throws IOException {
// See http://solr.pl/en/2012/05/14/developing-your-own-solr-filter/
if (!input.incrementToken()) return false;
String string = charTermAttr.toString();
boolean containsGatan = string.contains("gatan");
boolean containsG = string.contains("g.");
if (containsGatan) {
string = string.replace("gatan", "g.");
char[] newBuffer = string.toCharArray();
charTermAttr.setEmpty();
charTermAttr.copyBuffer(newBuffer, 0, newBuffer.length);
return true;
}
if (containsG) {
string = string.replace("g.", "gatan");
char[] newBuffer = string.toCharArray();
charTermAttr.setEmpty();
charTermAttr.copyBuffer(newBuffer, 0, newBuffer.length);
return true;
}
return false;
}
我还有一个类似的问题是你可以用031-123456
和 的形式写电话号码031123456
。当搜索像 031123456 这样的电话号码时,它也应该找到031-123456
如何在 Solr 中实现这一点?