json - 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},
{
您可以看到两者Problem
都Solution
作为数组输出。这在我的项目中引起了其他问题。我相信这是因为我的架构是如何设置的。
Problem
和都Solution
被text_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 我是一名新编码员,并且正在尝试构建我的问题以对其他初学者有益,如果您对我的问题有疑问或相信我可以包含更多信息或我尝试过的示例,请告诉我。在将我的问题带到这里之前,真的要进行足够的研究。
解决方案
如果您注意到架构定义中的multiValued="true"
.
将其更改为“false”应该会阻止您的字段成为数组。
自然,一旦您更改了架构,您将需要重新索引搜索索引中已有的数据。
推荐阅读
- c++ - 打开 VST 插件的编辑器窗口后无法写入文件
- php - 当我想连接我的数据库时出现此错误
- conv-neural-network - 带有 numpy einsum 的 CNN 前向和后向为 for 循环实现提供了不同的结果
- javascript -
- forms - 在颤动中动态添加表单字段
- python - 部署到 Heroku 后尝试在 Django 中添加类别时获取“'bool' 类型的对象没有 len()”
- r - 在同一图表中绘制 2 个条形图
- python - Keras CNN:检查输入时出错:预期 conv1d_46_input 有 3 个维度,但得到了形状为 (3780, 6) 的数组
- excel - 使用 DATEDIF 函数添加 2 个日期范围的总和(以年、月、日格式显示)
- android - Flutter:在 ListView Builder 中使用 Hero 动画