Solr 突出显示 - 带有变音符号的术语未突出显示 found/not

Solr highlighting - terms with umlaut not found/not highlighted

我正在玩7.2版本的solr。我已经上传了一个很好的德语文本集合,并尝试查询并突出显示一些查询。

如果我用高亮显示这个查询:

http://localhost:8983/solr/trans/select?q=trans:Zeit&hl=true&hl.fl=trans&hl.q=Kundigung&hl.snippets=3&wt=xml&rows=1

我收到一条很好的短信:

<response>
    <lst name="responseHeader">
        <bool name="zkConnected">true</bool>
        <int name="status">0</int>
        <int name="QTime">10</int>
        <lst name="params">
            <str name="hl.snippets">3</str>
            <str name="q">trans:Zeit</str>
            <str name="hl">true</str>
            <str name="hl.q">Kundigung</str>
            <str name="hl.fl">trans</str>
            <str name="rows">1</str>
            <str name="wt">xml</str>
        </lst>
    </lst>
    <result name="response" numFound="418" start="0" maxScore="1.6969817">
        <doc>
            <str name="id">x</str>
            <str name="trans">... Zeit  ...</str>
            <date name="t">2018-03-01T14:32:29.400Z</date>
            <int name="l">2305</int>
            <long name="_version_">1594374122229465088</long>
        </doc>
    </result>
    <lst name="highlighting">
        <lst name="x">
            <arr name="trans">
                <str> ... <em>Kündigung</em> ... </str>
                <str> ... <em>Kündigung</em> ... </str>
            </arr>
        </lst>
    </lst>
</response>

但是,如果我提供 Kündigung 作为高亮文本,我得不到任何答案,因为 text/query 解析器将所有 ü 字符替换为 u

我觉得我需要提供正确的 qparser。我应该如何指定它?在我看来,该集合是使用默认 LuceneQParser 解析器构建和查询的。如何在上面的 url 中提供此解析器?

更新:

http://localhost:8983/solr/trans/schema/fields/trans returns

{
  "responseHeader":{
    "status":0,
    "QTime":0},
  "field":{
    "name":"trans",
    "type":"text_de",
    "indexed":true,
    "stored":true}}

更新 2:所以我查看了我的 solr installation/collection 架构配置的托管架构,发现以下内容:

  <fieldType name="text_de" class="solr.TextField" positionIncrementGap="100">
    <analyzer>
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" format="snowball" words="lang/stopwords_de.txt" ignoreCase="true"/>
      <filter class="solr.GermanNormalizationFilterFactory"/>
      <filter class="solr.GermanLightStemFilterFactory"/>
    </analyzer>
  </fieldType>

我解释信息的方式是,由于省略了查询和索引部分,所以上面的代码对于查询和索引来说是相同的。哪个...没有显示任何类似于 ...

的错误配置问题

不过我记得,添加字段 trans 类型为 text_de:

curl -X POST -H 'Content-type:application/json' --data-binary '{
"add-field":{
     "name":"trans",
     "type":"text_de",
     "stored":true,
     "indexed":true}
}' http://localhost:8983/solr/trans/schema

我已经使用

删除了所有文档
curl http://localhost:8983/solr/trans/update?commit=true -d "<delete><query>*:*<
/query></delete>"

然后重新插入:

curl  -X POST http://localhost:8983/solr/trans/update?commit=true -H "Content-Type: application/json" -d @all.json

solr 中 "rebuild" 索引的正确方法吗?

更新 3: 标准 JAVA 安装的字符集设置未设置为 UTF-8:

C:\tmp>java -classpath . Hello
Cp1252
Cp1252
windows-1252

C:\tmp>cat Hello.java
public class Hello {
 public static void main(String args[]) throws Exception{
  // not crossplateform safe
  System.out.println(System.getProperty("file.encoding"));
  // jdk1.4
  System.out.println(
     new java.io.OutputStreamWriter(
        new java.io.ByteArrayOutputStream()).getEncoding()
     );
  // jdk1.5
  System.out.println(java.nio.charset.Charset.defaultCharset().name());
  }
}

更新 4:使用 UTF8 设置重新启动 solr:

bin\solr.cmd start -Dfile.encoding=UTF8 -c -p 8983 -s example/cloud/node1/solr
bin\solr.cmd start -Dfile.encoding=UTF8 -c -p 7574 -s example/cloud/node2/solr -z localhost:9983

检查了 JVM 设置:

http://localhost:8983/solr/#/~java-properties



file.​encoding    UTF8
file.​encoding.​pkg    sun.io

重新插入了文档。无变化:http://localhost:8983/solr/trans/select?q=trans:Zeit&hl=true&hl.fl=trans&hl.q=Kundigung&hl.qparser=lucene&hl.snippets=3&rows=1&wt=xml 给出:

<lst name="highlighting">
    <lst name="32e42caa-313d-45ed-8095-52f2dd6861a1">
        <arr name="trans">
            <str> ... <em>Kündigung</em> ...</str>
            <str> ... <em>Kündigung</em> ...</str>
        </arr>
    </lst>
</lst>

http://localhost:8983/solr/trans/select?q=trans:Zeit&hl=true&hl.fl=trans&hl.q=K%C3%BCndigung&hl.qparser=lucene&hl.snippets=3&rows=1&wt=xml 给出:

<lst name="highlighting">
    <lst name="32e42caa-313d-45ed-8095-52f2dd6861a1"/>
</lst>

uchardet all.json (file -bi all.json) 报告 UTF-8

运行 来自 windows 下的 ubuntu 子系统:

$ export LC_ALL='en_US.UTF-8'
$ export LC_CTYPE='en_US.UTF-8'
$ curl -H "Content-Type: application/json" http://localhost:8983/solr/trans/query?hl=true\&hl.fl=trans\&fl=id -d '
{
  "query" : "trans:Kündigung",
  "limit" : "1", params: {"hl.q":"Kündigung"}
}'
{
  "responseHeader":{
    "zkConnected":true,
    "status":0,
    "QTime":21,
    "params":{
      "hl":"true",
      "fl":"id",
      "json":"\n{\n  \"query\" : \"trans:Kündigung\",\n  \"limit\" : \"1\", params: {\"hl.q\":\"Kündigung\"}\n}",
      "hl.fl":"trans"}},
  "response":{"numFound":124,"start":0,"maxScore":4.3724422,"docs":[
      {
        "id":"b952b811-3711-4bb1-ae3d-e8c8725dcfe7"}]
  },
  "highlighting":{
    "b952b811-3711-4bb1-ae3d-e8c8725dcfe7":{}}}
$ curl -H "Content-Type: application/json" http://localhost:8983/solr/trans/query?hl=true\&hl.fl=trans\&fl=id -d '
{
  "query" : "trans:Kündigung",
  "limit" : "1", params: {"hl.q":"Kundigung"}
}'
{
  "responseHeader":{
    "zkConnected":true,
    "status":0,
    "QTime":18,
    "params":{
      "hl":"true",
      "fl":"id",
      "json":"\n{\n  \"query\" : \"trans:Kündigung\",\n  \"limit\" : \"1\", params: {\"hl.q\":\"Kundigung\"}\n}",
      "hl.fl":"trans"}},
  "response":{"numFound":124,"start":0,"maxScore":4.3724422,"docs":[
      {
        "id":"b952b811-3711-4bb1-ae3d-e8c8725dcfe7"}]
  },
  "highlighting":{
    "b952b811-3711-4bb1-ae3d-e8c8725dcfe7":{
      "trans":[" ... <em>Kündigung</em> ..."]}}}

更新 5 不提供 hl.qhttp://localhost:8983/solr/trans/select?q=trans:Kundigung&hl=true&hl.fl=trans&hl.qparser=lucene&hl.snippets=3&rows=1&wt=xmlhttp://localhost:8983/solr/trans/select?q=trans:K%C3%BCndigung&hl=true&hl.fl=trans&hl.qparser=lucene&hl.snippets=3&rows=1&wt=xml):

<lst name="highlighting">
    <lst name="b952b811-3711-4bb1-ae3d-e8c8725dcfe7">
        <arr name="trans">
            <str> ... <em>Kündigung</em> ... </str>
            <str> ... <em>Kündigung</em> ... </str>
            <str> ... <em>Kündigung</em> ... </str>
        </arr>
    </lst>
</lst>

在这种情况下,hl.q 从查询本身中提取了突出显示的术语,并且做得非常好..

可能是您的 JVM 编码有问题。 -Dfile.encoding=UTF8 怎么样?还要检查 LC_ALL 和 LC_CTYPE。应该是UTF-8。

trans字段是什么字段类型?我什至用 text_en 为德语文本编制了索引,并且在突出显示或搜索时使用变音符号没有任何问题,而且我也使用 LuceneQParser。

当您通过 Solr Admin UI (http://localhost:8983/solr/#/trans/query) 查询并激活 hl 复选框时,响应如何?

还要检查您的分析器链。当我以这种方式错误配置链时,我得到了与您描述的相同的行为:

  <fieldType name="text_de" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="query">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" format="snowball" words="lang/stopwords_de.txt" ignoreCase="true"/>
    </analyzer>
    <analyzer type="index">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
      <filter class="solr.StopFilterFactory" format="snowball" words="lang/stopwords_de.txt" ignoreCase="true"/>
      <filter class="solr.GermanNormalizationFilterFactory"/>
      <filter class="solr.GermanLightStemFilterFactory"/>
    </analyzer>
  </fieldType>

GermanNormalizationFilterFactoryGermanLightStemFilterFactory 都替换了变音符号。

您需要指定的是属性,为此突出显示。类似于q=trans:Zeit,你指定trans作为一个属性,你需要指定hl.qhl.q=trans:Kündigung。您的请求将变为:

http://localhost:8983/solr/trans/select?q=trans:Zeit&hl=true&hl.fl=trans&hl.q=trans:Kündigung&hl.snippets=3&wt=xml&rows=1

这个答案由 David Smiley、Stefan Matheis 和 Erick Erickson、solr 社区和支持人员谦虚地提出。这是post他们的代表。