首页 > 解决方案 > Solr JSON 输出从数组到字符串

问题描述

这就是我通过 solr ui 执行查询时发生的情况。

{
  "responseHeader":{
    "status":0,
    "QTime":1,
    "params":{
      "q":"*:*",
      "_":"1548964207972"}},
  "response":{"numFound":10,"start":0,"docs":[
      {
        "date":"2018-12-07T06:00:00Z",
        "Problem":["unlock a user"],
        "id":"1",
        "Solution":["solution to unlock"],
        "_version_":1624206363327463424},
      {
        "date":"2018-12-07T06:00:00Z",
        "Problem":["unlock another user"],
        "id":"2",
        "Solution":["solution 2"],
        "_version_":1624206363330609152},
      {

您可以看到两者ProblemSolution作为数组输出。这在我的项目中引起了其他问题。我相信这是因为我的架构是如何设置的。

Problem和都Solutiontext_general索引,而不是存储。

我相信问题出在我的 solr 架构上,因为我的数据库中的那些字段只是 text utf8_unicode_ci。以下是text_general我的架构中的部分:

  <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100" multiValued="true">
    <analyzer type="index">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
      <tokenizer class="solr.StandardTokenizerFactory"/>
      <filter class="solr.StopFilterFactory" words="stopwords.txt" ignoreCase="true"/>
      <filter class="solr.SynonymGraphFilterFactory" expand="true" ignoreCase="true" synonyms="synonyms.txt"/>
      <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>

一旦我的项目收到 json 输出,它应该计算解决方案中的字符,所以我需要输出是文本。

编辑:console.log(Solution);在应用程序上使用 solr 表明它是一个数组。

["solution 2"]0: "solution 2"length: 1__proto__: Array(0)

ToWhomItMayConcern 我是一名新编码员,并且正在尝试构建我的问题以对其他初学者有益,如果您对我的问题有疑问或相信我可以包含更多信息或我尝试过的示例,请告诉我。在将我的问题带到这里之前,真的要进行足够的研究。

标签: jsonsolr

解决方案


如果您注意到架构定义中的multiValued="true".

将其更改为“false”应该会阻止您的字段成为数组。

自然,一旦您更改了架构,您将需要重新索引搜索索引中已有的数据。


推荐阅读