js_需求

2018-08-13  本文已影响0人  唯此

整体数据流转:

用户输入 (input_content)-> 请求(search_request) -> 向ES发送请求(es_query) -> 获取ES的返回结果(es_result) -> 展示结果

input_content

设输入的内容为inputContent, inputContent按照如下格式做解析:“字段1:具体值 字段2:具体值”.解析示例:“ 日期:20150201~20160101 公司:深高速 公告来源:上交所 排序:日期”需要解析为如下形式
localhost:3000//s?annouceDate=20150201~20160101&announceCompany=深高速&fileSrc=上交所&sortBy=annouceDate

  1. 单个字段的合法性检查见下表


    image.png
  2. 搜索条件至少有一个。

  3. 对于不合法的字段需要提示字段不合法。例如“日期:20150201~201601“会被提示”日期字段不合法“。

search_request

search_request的示例如下:

para: {annouceDate: 20150201~20160101,
announceCompany: '深高速',
fileSrc: '上交所',
sortBy: annouceDate}
}

参考的解析代码(JS):

function parseSearchInput(sample_str) {
    // 1.把所有的中文的冒号转换为英文的冒号
    // 2.根据英文冒号来做切断,获取每个断点的坐标,保存在indexArr里。
    // 3.根据indexArr把原先的字符串解析成object, 其中把空格分开的
    let new_str = sample_str.replace(/:/g,':')
    let headPattern = /[\d\w\u4e00-\u9fa5]+:/g
    let indexArr = []
    let aObj = {}
    let theRes
    while (true){
        theRes = headPattern.exec(new_str)
        if(theRes === null){
            indexArr.push(new_str.length)
            break
        }
        indexArr.push(theRes.index)
        indexArr.push(theRes.index+theRes[0].length)
    }
    let theValueArr
    for(i=0; i<indexArr.length/2 -1;i++){
        theValueArr = sample_str.slice(indexArr[2*i+1],indexArr[2*i+2]).split(' ')
        theValueArr = theValueArr.filter((value) => (value.length > 0))
        aObj[sample_str.slice(indexArr[2*i],indexArr[2*i+1]-1)] = theValueArr
    }
    return aObj
}
let sample_str = '字段1:adfjlk 字段2:萨芬'
console.log(JSON.stringify(parseSearchInput(sample_str)))
​
let sample_str2 = '字段1:深圳 高速 字段2:萨芬'
console.log(JSON.stringify(parseSearchInput(sample_str2)))

es_query

hosts='192.168.1.6'
index = 'index_info'

es_result

返回结果的json样式如下:

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 2176,
    "max_score": 1.0,
    "hits": [
      {
        "_index": "index_info",
        "_type": "json",
        "_id": "302",
        "_score": 1.0,
        "_source": {
          "title": "公开发行可转换公司债券发行公告",
          "pdf_id": "20180718302"
        }
      },
      {
        "_index": "index_info",
        "_type": "json",
        "_id": "313",
        "_score": 1.0,
        "_source": {
          "title": "第五届董事会2018年度第五次临时会议决议公告",
          "pdf_id": "20180718313"
        }
      },
      {
        "_index": "index_info",
        "_type": "json",
        "_id": "314",
        "_score": 1.0,
        "_source": {
          "title": "长沙中联重科环境产业有限公司审计报告",
          "pdf_id": "20180718314"
        }
      },
      {
        "_index": "index_info",
        "_type": "json",
        "_id": "322",
        "_score": 1.0,
        "_source": {
          "title": "简式权益变动报告书(二)",
          "pdf_id": "20180718322"
        }
      },
      {
        "_index": "index_info",
        "_type": "json",
        "_id": "332",
        "_score": 1.0,
        "_source": {
          "title": "发行股份购买资产暨关联交易报告书(草案)摘要",
          "pdf_id": "20180718332"
        }
      },
      {
        "_index": "index_info",
        "_type": "json",
        "_id": "335",
        "_score": 1.0,
        "_source": {
          "title": "关于本次重大资产重组相关主体不存在依据《关于加强与上市公司重大资产重组相关股票异常交易监管的暂行规定》第十三条不得参与任何上市公司重大资产重组情形的说明",
          "pdf_id": "20180718335"
        }
      },
      {
        "_index": "index_info",
        "_type": "json",
        "_id": "338",
        "_score": 1.0,
        "_source": {
          "title": "关于公司股票暂不复牌的提示性公告",
          "pdf_id": "20180718338"
        }
      },
      {
        "_index": "index_info",
        "_type": "json",
        "_id": "340",
        "_score": 1.0,
        "_source": {
          "title": "关于本次资产重组前12个月内购买、出售资产情况的说明",
          "pdf_id": "20180718340"
        }
      },
      {
        "_index": "index_info",
        "_type": "json",
        "_id": "343",
        "_score": 1.0,
        "_source": {
          "title": "董事会关于评估机构的独立性、评估假设前提的合理性、评估方法与评估目的的相关性以及评估定价的公允性的说明",
          "pdf_id": "20180718343"
        }
      },
      {
        "_index": "index_info",
        "_type": "json",
        "_id": "349",
        "_score": 1.0,
        "_source": {
          "title": "独立董事关于发行股份购买资产暨关联交易的独立意见",
          "pdf_id": "20180718349"
        }
      }
    ]
  }
}

调整

1.logo与网站名字替换.
2.搜索结果,全都采用了分词匹配的模式.需求是要求关键词要精确匹配. 应该要改一下发给ES的请求样式.


image.png
  1. 筛选放在一个按钮上,是有颜色的.重置放在另一个按钮上,是浅色的.(理由:预期用户80%的概率是点击筛选,只有20%的概率是点击重置). 这个控件最好封装为一个我们自己的组件.


    image.png

    4.输入框放大(现在太窄了)


    image.png
上一篇 下一篇

猜你喜欢

热点阅读