使用JSON结果在Solr中的Hightlight

时间:2015-07-29 07:28:58

标签: solr solrj

我想强调Solr搜索中使用的术语。我正在进行搜索并获得以下结果。如何使用以下JSON响应突出显示该术语,或者我在配置中遗漏了哪些东西阻止我获取预期的结果。

 {
    "_header": {
        "nvPairs": [
            "status",
            0,
            "QTime",
            1,
            "params",
            {
                "nvPairs": [
                    "hl.fragsize",
                    "100000",
                    "hl.simple.pre",
                    "<em>",
                    "hl.fl",
                    "name",
                    "wt",
                    "javabin",
                    "hl.maxAnalyzedChars",
                    "100000",
                    "hl",
                    "true",
                    "version",
                    "2",
                    "hl.highlightMultiTerm",
                    "true",
                    "hl.snippets",
                    "100",
                    "hl.useFastVectorHighlighter",
                    "true",
                    "q",
                    "Ajay",
                    "hl.regex.slop",
                    "0.5",
                    "hl.regex.pattern",
                    "[-\\w ,/\n\\\"']*",
                    "hl.simple.post",
                    "</em>"
                ]
            }
        ]
    },
    "_results": [
        {
            "id": "1",
            "last_modified": "Jul 10, 2015 12:30:00 PM",
            "name": [
                "Ajay"
            ],
            "last_name": "Kalkoti",
            "mobile": "11",
            "_version_": 1508131686161842200
        }
    ],
    "_highlightingInfo": {
        "nvPairs": [
            "1",
            {
                "nvPairs": [
                    "name",
                    [
                        "<em>Ajay</em>"
                    ]
                ]
            }
        ]
    },
    "_highlighting": {
        "1": {
            "name": [
                "<em>Ajay</em>"
            ]
        }
    },
    "elapsedTime": 10,
    "response": {
        "nvPairs": [
            "responseHeader",
            {
                "nvPairs": [
                    "status",
                    0,
                    "QTime",
                    1,
                    "params",
                    {
                        "nvPairs": [
                            "hl.fragsize",
                            "100000",
                            "hl.simple.pre",
                            "<em>",
                            "hl.fl",
                            "name",
                            "wt",
                            "javabin",
                            "hl.maxAnalyzedChars",
                            "100000",
                            "hl",
                            "true",
                            "version",
                            "2",
                            "hl.highlightMultiTerm",
                            "true",
                            "hl.snippets",
                            "100",
                            "hl.useFastVectorHighlighter",
                            "true",
                            "q",
                            "Ajay",
                            "hl.regex.slop",
                            "0.5",
                            "hl.regex.pattern",
                            "[-\\w ,/\n\\\"']*",
                            "hl.simple.post",
                            "</em>"
                        ]
                    }
                ]
            },
            "response",
            [
                {
                    "id": "1",
                    "last_modified": "Jul 10, 2015 12:30:00 PM",
                    "name": [
                        "Ajay"
                    ],
                    "last_name": "Kalkoti",
                    "mobile": "11",
                    "_version_": 1508131686161842200
                }
            ],
            "highlighting",
            {
                "nvPairs": [
                    "1",
                    {
                        "nvPairs": [
                            "name",
                            [
                                "<em>Ajay</em>"
                            ]
                        ]
                    }
                ]
            }
        ]
    }
}

请告诉我如果您需要任何内容​​。我突出显示solrconfig.xml的默认值如下所示。

 <str name="hl">on</str>
         <str name="hl.fl">name_s</str>
         <str name="hl.preserveMulti">true</str>
         <str name="hl.encoder">html</str>
         <str name="hl.simple.pre">&lt;b&gt;</str>
         <str name="hl.simple.post">&lt;/b&gt;</str>
         <str name="f.title.hl.fragsize">0</str>
         <str name="f.title.hl.alternateField">title</str>
         <str name="f.name.hl.fragsize">100</str>
         <str name="f.name.hl.alternateField">name</str>
         <str name="f.content.hl.snippets">3</str>
         <str name="f.content.hl.fragsize">200</str>
         <str name="f.content.hl.alternateField">content</str>
       <str name="f.content.hl.maxAlternateFieldLength">750</str>

1 个答案:

答案 0 :(得分:0)

我弄清楚问题是什么。无法突出显示动态字段。必须在schema.xml中定义字段才能突出显示。