我有一个 Spring MVC
投射那个 Solr
已连接到。因此,项目中实施了全文搜索,由于项目是俄文的, SOLR
搜索俄语信息(例如:ivan-russian)иван"), 而且如果你用俄语输入一个单词,忘记切换键盘语言bdfy-“ivan”(在俄语-英语键盘的英文布局上),无论如何他会给出正确的结果-它会给用户一个名字ivan。
但问题是,如果有一个名为abdula(俄语字母)的用户,在搜索中键入俄语-абдула", 然后他将显示唯一可用的абдула 对我来说,那一个用俄语写的将被翻译成英文版式(“абдула" - f、 lekf),然后将返回更多用户的部分名称匹配f,lekf。
这怎么能修好。。。?
因此,如果他找到一个名为abdula的用户,他就不会进一步转换数据并显示不必要的。。。
public <T extends Index> IndexQueryResult<T> query(IndexQuery<T> indexQuery) throws IndexException {
Core core = getCore(indexQuery.getEntityClass());
try {
if (core == null)
throw new SolrServerException("Solr core is not defined");
SolrClient solr = solrConfiguration.getSolrClient(core);
String selectQuery = indexQuery.getQuery() == null
? "" : StringUtils.escapeCharacters(indexQuery.getQuery(), ESCAPE_CHARACTERS, '\\');
String spellcheckSuggestion = null;
if (indexQuery.isUseSpellcheck()) {
SolrQuery spellSelect = new SolrQuery(selectQuery);
spellSelect.setParam("spellcheck.q", selectQuery);
spellSelect.setParam("spellcheck", "on");
spellSelect.setRequestHandler("/spell");
QueryResponse spellResponse = solr.query(spellSelect, SolrRequest.METHOD.POST);
if (spellResponse.getSpellCheckResponse() != null) {
spellcheckSuggestion = spellResponse.getSpellCheckResponse().getCollatedResult();
}
}
// Other method code ...
}
<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="df">text_spell</str>
<!-- Solr will use suggestions from both the 'default' spellchecker
and from the 'wordbreak' spellchecker and combine them.
collations (re-written queries) can include a combination of
corrections from both spellcheckers -->
<str name="spellcheck.dictionary">default</str>
<!-- <str name="spellcheck.dictionary">wordbreak</str>-->
<str name="spellcheck">on</str>
<str name="spellcheck.extendedResults">true</str>
<str name="spellcheck.count">10</str>
<str name="spellcheck.alternativeTermCount">0</str>
<str name="spellcheck.maxResultsForSuggest">0</str>
<str name="spellcheck.collate">true</str>
<str name="spellcheck.collateExtendedResults">true</str>
<str name="spellcheck.maxCollationTries">10</str>
<str name="spellcheck.maxCollations">5</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
</arr>
</requestHandler>
myclasskeyboardlayoutfilter(用于make(rus.ivan)”иван" -> "bdfy“)。
protected static final char[] LATINS = {'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']',
'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', 'z', 'x', 'c', 'v',
'b', 'n', 'm', ',', '.', '`'};
// ... other code
protected void incrementTokenLogic() {
char[] buffer = charTermAttr.buffer();
if (buffer.length > 0) {
char[] newBuffer = new char[charTermAttr.length()];
for (int i = 0; i < charTermAttr.length(); i++) {
char ch = buffer[i];
if (LATIN_TO_CYR_MAP.containsKey(ch)) {
newBuffer[i] = LATIN_TO_CYR_MAP.get(ch);
} else {
newBuffer[i] = CYR_TO_LATIN_MAP.getOrDefault(ch, ch);
}
}
terms.add(newBuffer);
}
}
暂无答案!
目前还没有任何答案,快来回答吧!