如何自定义Solr搜索结果?

时间:2018-04-06 13:19:53

标签: solr

我正在使用Solr满足以下搜索需求:

原始数据:采用FIX格式,如果您不知道它是什么,可以使用特殊的分隔符将其视为csv。

解析数据:来自原始数据,全部采用相同格式的一堆JSON格式,包含所有100多个字段。

示例:

原始数据:分隔符是\ u001:

  

8 = FIX.4.4 9 = 653 35 = RIO 1 = TEST 11 = 337912000000002 38 = 1 44 = 2.0 39 = A 40 = 2   49 = VIPER 50 = JPNIK01 54 = 1 55 = JNI253D8.OS 56 = XSVC 59 = 0 75 = 20180350   100 = XOSE 10039 = viperooe 10241 = viperooe 150 = A 372 = D.   122 = 20180320-08:08:35.038 10066 = 20180320-08:08:35.038   10436 = 20180320-08:08:35.038 202 = 25375.0 52 = 20180320-08:08:35.088   60 = 20180320-08:08:35.088 10071 = 20180320-08:08:35.088   11210 = 337912000000002 37 = 337912000000002 10184 = 337912000000002 201 = 1   29 = 4 10438 = RIO.4.5 10005 = 178 10515 = 178 10518 = 178 581 = 13 660 = 102 1133 = G   528 = P 10104 = Y 10202 = APMKTMAKING 10208 = APAC.VIPER.OOE 10217 = Y 10292 = 115   11032 = -1 382 = 0 10537 = XOSE 15 = JPY 167 = OPT 48 = 179492540 455 = 179492540   22 = 101 456 = 101 151 = 1.0 421 = JPN 10 = 200

解析数据:在​​json:

  

{" 122":" 20180320-08:08:35.038"," 49":" VIPER",&#34 ; 382":" 0"," 151":   " 1.0"," 9":" 653"," 10071":" 20180320-08:08:35.088&# 34;," 15":" JPY",   " 56":" XSVC"," 54":" 1"," 10202":" APMKTMAKING& #34;," 10537":" XOSE",   " 10217":" Y"," 48":" 179492540"," 201":" 1& #34;," 40":" 2"," 8":   " FIX.4.4"," 167":" OPT"," 421":" JPN",&# 34; 10292":" 115"," 10184":   " 337912000000002"," 456":" 101"," 11210":" 337912000000002"," 1133& #34 ;:   " G"," 10515":" 178"," 10":" 200"," 11032& #34;:" -1"," 10436":   " 20180320-08:08:35.038"," 10518":" 178"," 11":" 337912000000002&#34 ;,   " 75":" 20180320"," 10005":" 178"," 10104":" Y& #34;," 35":" RIO"," 10208":   " APAC.VIPER.OOE"," 59":" 0"," 60":" 20180320-08:08: 35.088"," 528":   " P"," 581":" 13"," 1":" TEST"," 202& #34;:" 25375.0"," 455":" 179492540",   " 55":" JNI253D8.OS"," 100":" XOSE"," 52":&#34 ; 20180320-08:08:35.088&#34 ;,   " 10241":" viperooe"," 150":" A"," 10039":" viperooe& #34;," 39":" A",   " 10438":" RIO.4.5"," 38":" 1"," 37":&# 34; 337912000000002"," 372":" D",   " 660":" 102"," 44":" 2.0"," 10066":" 20180320-08:08:35.038"," 29":   " 4"," 50":" JPNIK01"," 22":" 101"}

用于搜索的字段是order_id(标记37)和trd_date(标记75)。我将创建添加了两个字段的模式

<field name="37" type="text_general" indexed="true" stored="false" multiValued="true"/>
<field name="75" type="text_general" indexed="true" stored="false" multiValued="true"/>

目前我可以得到结果:http://192.168.112.141:8983/solr/fix_messages/select?q=37:337912000000002 其中37是order_id,337912000000002是要在&#34; 37&#34;

的字段中搜索的值

我得到的结果是:

 {
  "responseHeader":{
    "status":0,
    "QTime":6,
    "params":{
      "q":"37:337912000000002"}},
  "response":{"numFound":1,"start":0,"docs":[
      {
        "122":["20180320-08:08:35.038"],
        "49":["VIPER"],
        "382":[0],
        "151":[1.0],
        "9":[653],
        "10071":["20180320-08:08:35.088"],
        "15":["JPY"],
        "56":["XSVC"],
        "54":[1],
        "10202":["APMKTMAKING"],
........

我需要显示如下结果:

  1. order_id:&#34; order_id&#34;必须显示而不是其实际标签37;
  2. trd_date:&#34; trd_date&#34;必须显示在结果中;
  3. 整个消息:整个和原始消息必须显示在结果中;
  4. 必须突出显示order_id和trd_date这两个字段。
  5. 谁能告诉我该怎么做?非常感谢你提前。

1 个答案:

答案 0 :(得分:0)

您应该在构建JSON结构时添加列的名称,或者创建一个小脚本来更改JSON文件中的键并为您输出新结构。实际上没有办法解决这个问题 - 除非您可以在前端层中进行映射。

如果您需要整个消息 - 这取决于您是否需要JSON或FIX消息 - 但同样,您需要对其进行预处理以将其添加到JSON文件中。

对于“突出显示字段” - 可以使用hl.fl启用常规的Solr突出显示。