solr mysql mutivalue_在Solr中使用ContentStreamUpdateRequest设置多值字段(Set multivalued fields with ContentStr...

在Solr中使用ContentStreamUpdateRequest设置多值字段(Set multivalued fields with ContentStreamUpdateRequest in Solr)

我正在使用SolrJ + SolrCell来索引各种Word / Excel / PDF文件的内容,但是我希望能够自己设置一些字段(例如id,name):

ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update/extract");

req.addFile(docFile, null);

req.setParam("literal.id", docProperties.getId());

req.setParam("literal.name", docProperties.getName());

我对普通字段没有任何问题,但我发现当我尝试使用同样的setParam方法设置多值字段时,只存储输入数组中的最后一个元素:

if (docProperties.getCategories() != null) {

for (String category : docProperties.getCategories()) {

req.setParam("literal.categories", category);

}

}

例如,如果docProperties.getCategories()是[“News”,“Computers”,“Tech”],则存储在多值类别字段中的唯一值是[“Tech”]。 我实际上对此并不感到惊讶,因为我不认为使用setParam方法是将值附加到多值字段的正确方法。

但是,我不知道如何使用可用的ContentStreamUpdateRequest方法来做到这一点。 如果我正在使用SolrInputDocument,那么将数组传递给addField方法就是一件简单的事情。

String[] categoriesArray = {"News", "Computers", "Tech"};

ArrayList categories = new ArrayList(Arrays.asList(categoriesArray));

doc.addField("categories", categories );

有没有办法使用ContentStreamUpdateRequest做同样的事情?

I'm using SolrJ+SolrCell to index the contents of various Word/Excel/PDF files, but there are some fields (e.g. id, name) that I want to be able to set myself:

ContentStreamUpdateRequest req = new ContentStreamUpdateRequest("/update/extract");

req.addFile(docFile, null);

req.setParam("literal.id", docProperties.getId());

req.setParam("literal.name", docProperties.getName());

I am not having any issues with normal fields, but I find that when I try using this same setParam method to set multivalued fields, only the last element in the input array is stored:

if (docProperties.getCategories() != null) {

for (String category : docProperties.getCategories()) {

req.setParam("literal.categories", category);

}

}

For example, if docProperties.getCategories() is ["News", "Computers", "Tech"], the only value stored in the multivalued category field is ["Tech"]. I'm actually not too surprised by this, since I don't think using the setParam method is the proper way to append values to a multivalued field.

However, I am at a loss as to how to do this using available ContentStreamUpdateRequest methods. If I was working with a SolrInputDocument, then it'd be a simple matter of passing an array to the addField method.

String[] categoriesArray = {"News", "Computers", "Tech"};

ArrayList categories = new ArrayList(Arrays.asList(categoriesArray));

doc.addField("categories", categories );

Is there a way to do this same sort of thing using ContentStreamUpdateRequest?

原文:https://stackoverflow.com/questions/21536102

更新时间:2020-01-26 07:37

相关问答

看我以前的回答 。 由于id是文档的uniqueKey,因此它是默认的“无模式”托管模式中未定义为多值的少数字段之一。 由于5.x默认使用托管架构 - 如果在升级后第一次启动Solr时没有正确的schema.xml文件,则可能会发生这种情况。 您可以使用solrconfig.xml的ClassicIndexSchemaFactory更改此行为。 _version_字段是必需的,因为Solr内部 - 它必须存在于模式中,因为它用于部分更新(即其他人在您提交部件之前更新了文档),SolrCloud模式

...

当字段有多个值时,多值字段很有用。 一个简单的例子就是标签,可以有多个标签需要编入索引。 所以如果我们将标签字段作为多值,则solr响应将返回一个列表而不是一个字符串值。 需要注意的一点是,您需要为每个标签值提交多行,如: tag1

tag2

...

tagn

一旦你拥有所有的值索引,你可以搜索或过滤结果的任何值,e,g。 您可以使用查询来查

...

您必须删除KeywordTokenizer - 这将整个存储的文本保存为一个令牌。 使用WhitespaceTokenizer或StandardTokenizer应该可以工作,请记住,在以任何方式更改分析链之后,您必须重新编制索引(除非您仅更改处理查询内容的方式)。 使用默认的动态字段*_txt (定义为StandardTokenizer,只能删除*_txt和停用词)以及索引您的两个文档: q=*:* "response":{"numFound":2,"start":0,"docs":[

...

我在文档csv update params中得到了一个线索,说明这个问题与我通过的这个参数有关( &rowid=MyId )。 正如文档所述,我们应该通过这个参数来添加行号作为id。 这就解释了为什么我的密钥( MyId )变成了多值([我的实际密钥,行号])。 但是,如果我删除这个参数,它给出了一个错误,该id没有被填充。 这意味着它期待一个id字段。 所以添加&literal.id=1 ,现在一切工作正常(这是因为在我的架构有需要的id字段。)。 感谢您的帮助。 I got a clue in

...

从http://wiki.apache.org/solr/ExtractingRequestHandler#SolrJ ,使用ModifiableSolrParams设置这些文字参数适用于多值字段。 From http://wiki.apache.org/solr/ExtractingRequestHandler#SolrJ, using ModifiableSolrParams to set these literal parameters works for multivalued field

...

我认为最优化的方法是创建一个单独的集合或核心(取决于您是否使用云)并以某种方式索引数据,以便查询所需的查询结果。 当然,在某些情况下可能无法实现,但如果是在你的情况下,那就去做吧。 在这样的核心中,您只有与自动完成相关的字段和数据,因此在大多数情况下,它将比原始核心更小,更少的术语,这将导致更快的查询。 除此之外,此类核心或集合针对自动完成查询进行了优化,您将从中获得更多性能。 但是,如果您不能采用多核/集合方法,那么突出显示可能是最好的方法,如果您需要过滤。 在这种情况下,您可能希望打开术语验证

...

您可能需要在流程类中提及完整的类名称,并且multivaluedfield. 喜欢 multivaluedFieldXYZ I was able to r

...

在两个不同版本的Solr中使用完全相同的配置文件将为架构属性(如multiValued生成相同的默认行为。 如果你看到不同的行为,那么你在某个地方有一种堕落...... 1) 声明上属性的默认行为首先取决于相应上的属性。 由于您的问题没有指定两个schema.xml文件中string的声明是什么,因此它们可能在您的两个配置之间有所不同。 2)如果或定义中没有定义multiValued属性,则默认

...

我们遇到了这个问题。 但我们使用两个集合来解决这个问题。 使用SoleEntityProcessor将文档从一个集合移动到另一个集合。 [SolrEntityProcessor]

...

无模式模式使得所有内容都是多值的,因为它不知道您是否有单个值后跟同一字段的多值。 因此,它使所有字段都是多值的,并且还将数字类型升级到最大值。 如果您熟悉您的域名,这很容易调整。 整个映射链在solrconfig.xml的更新请求处理器链中定义( add-unknown-fields-to-the schema ),您可以将类型映射从多值类型更改为等效的单值类型。 对于字符串,可以更改defaultFieldType的值。 The schemaless mode makes everything

...

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值