Solr列出顶部不同场景的部分匹配

时间:2016-04-06 12:49:20

标签: search solr full-text-search search-engine

我已针对字段公司 进行搜索(**这是ngram-d,因为我需要根据部分匹配获取结果)**与搜索文本" aetnahmo" 。我可以带来完全匹配和部分匹配。 我需要处理一个场景,例如: 示例:从以下结果中,我需要带来" AETNA BETTER HLTH PAHMO "和#34; AETNA更好的健康MAHMO "位于" CIGNAHMO HEALTHPLAN - METH "的顶部。 在这里,即使这些结果也没有'aetnahmo'它有' aetna'。我需要在此处显示结果,低于完全匹配和类似匹配。

  "docs": [
  {
    "company": "AETNAHMOGNPIPA",
    "score": 0.32741508
  },
  {
    "company": "AETNAHMOPOSOUT OF NETWORK",
    "score": 0.32741508
  },
  {
    "company": "CIGNAHMO HEALTHPLAN - METH",
    "score": 0.14788051
  },
  {
    "company": "CIGNAHMOPOSOZ08",
    "score": 0.14500062
  },
  {
    "company": "CIGNAHMOPOSGNPIPA",
    "score": 0.14500062
  },
  {
    "company": "HUMANAHMO MCD",
    "score": 0.14500062
  },
  {
    "company": "AETNA BETTER HLTH PAHMO",
    "score": 0.1069743
  },
  {
    "company": "AETNA BETTER HEALTH MAHMO",
    "score": 0.1069743
  },
  {
    "company": "MOLINA HLTHCARE IL PAHMO",
    "score": 0.067287326
  },
  {
    "company": "BCBSMAHMO OUTPT",
    "score": 0.065203
  }
  ]

有没有办法实现这一目标。请帮忙

1 个答案:

答案 0 :(得分:0)

短语提升将在这里发挥作用。

您需要使用edismax查询解析器以及pf字段。

您的查询附加的以下参数应该可以解决问题: &defType=edismax&pf=company

我已经使用您在上面发布的数据集对Solr-5.4.1进行了测试,结果如下:

查询:http://localhost:8983/solr/Test/select?q=company%3Aaetnamho&wt=json&indent=true&defType=edismax&pf=company&stopwords=true&lowercaseOperators=true&omitHeader=true

响应:

{
"response":{"numFound":9,"start":0,"docs":[
  {
    "company":"AETNAHMOPOSOUT OF NETWORK",
    "id":2,
    "_version_":1530885533005250560},
  {
    "company":"AETNA BETTER HEALTH MAHMO",
    "id":8,
    "_version_":1530885600368918528},
  {
    "company":"AETNA BETTER HLTH PAHMO",
    "id":7,
    "_version_":1530885592734236672},
  {
    "company":"AETNAHMOGNPIPA",
    "id":1,
    "_version_":1530885512290631680},
  {
    "company":"CIGNAHMO HEALTHPLAN - METH",
    "id":3,
    "_version_":1530885543046414336},
  {
    "company":"MOLINA HLTHCARE IL PAHMO",
    "id":9,
    "_version_":1530885608894889984},
  {
    "company":"CIGNAHMOPOSGNPIPA",
    "id":5,
    "_version_":1530885565434560512},
  {
    "company":"CIGNAHMOPOSOZ08",
    "id":4,
    "_version_":1530885555631423488},
  {
    "company":"HUMANAHMO MCD",
    "id":6,
    "_version_":1530885585061806080}]
}}