我已经启动并运行了 SOLR,通过 DIH 索引数据,并正确返回查询结果。我正在尝试设置另一个核心来运行建议程序,以便自动完成地理位置。我们有一个需要接受城市、州/地区、国家/地区输入的 Web 应用程序。我们希望在单个输入框中执行此操作。这里有些例子:
布鲁克林,纽约,美国
美国宾夕法尼亚州费城
西类牙加泰罗尼亚巴塞罗那
现在假设世界上的每个位置都可以分成这个 3 形式的输入。我已经设置了我的 DIH 来创建一个 TemplateTransformer 字段,该字段将 4 个表(城市、州和国家/地区都是通过主地点表相互连接的独立表)组合到一个名为“fullplacename”的字段中:
<field column="fullplacename" template="${city_join.plainname},
${region_join.plainname}, ${country_join.plainname}"/>
我在 schema.xml 中定义了一个“text_auto”字段:
<fieldType class="solr.TextField" name="text_auto">
<analyzer>
<tokenizer class="solr.KeywordTokenizerFactory"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
并定义了这两个字段:
<field name="name_autocomplete" type="text_auto" indexed="true" stored="true" multiValued="true" />
<copyField source="fullplacename" dest="name_autocomplete" />
现在,这是我的问题。这适用于第一个术语,即如果我输入“brooklyn”,我会得到我期望的结果,使用这个 URL 来查询:
http://localhost:8983/solr/places/suggest?q=brooklyn
However, as soon as I put a comma and/or a space in there, it breaks them up into 2 suggestions, and I get a suggestion for each:
http://localhost:8983/solr/places/suggest?q=brooklyn%2C%20ny
Gives me a suggestion for "brooklyn" and a suggestion for "ny" instead of a suggestion that matches "brooklyn, ny". I've tried every solution I can find via google and haven't had any luck. Is there something simple that I've missed, or is this the wrong approach?
Thanks!
EDIT: Just in case, here's the searchComponent and requestHandler definition:
<requestHandler name="/suggest" class="org.apache.solr.handler.component.SearchHandler">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">suggest</str>
<str name="spellcheck.count">10</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
<searchComponent name="suggest" class="solr.SpellCheckComponent">
<lst name="spellchecker">
<str name="name">suggest</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookup</str>
<str name="field">name_autocomplete</str>`<br/>
</lst>
</searchComponent>
最佳答案
问题在于建议者。就像拼写检查器一样,它在空格上标记。
http://lucene.472066.n3.nabble.com/suggester-issues-tp3262718p3266140.html有一个解决这个问题的方法。
关于autocomplete - 对多个术语使用 SOLR 自动完成(即逗号分隔的位置),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8705600/