简体   繁体   English

Solr 中的“multiValued”字段类型有什么用?

[英]What is the use of “multiValued” field type in Solr?

I'm new to Apache Solr.我是 Apache Solr 的新手。 Even after reading the documentation part, I'm finding it difficult to clearly understand the functionality and use of the multiValued field type property.即使在阅读了文档部分之后,我也很难清楚地理解multiValued字段类型属性的功能和使用。

What internally Solr does/treats/handles a field that is marked as multiValued ? Solr 内部做什么/处理/处理标记为multiValued的字段?

What is the difference in indexing in Solr between a field that is multiValued and those that are not? Solr中的多值字段与非多值字段之间的索引有何区别?

Can somebody explain with some good example?有人可以用一些很好的例子来解释吗?

Doc says:医生说:

multiValued=true|false多值=真|假

True if this field may contain multiple values per document, ie if it can appear multiple times in a document如果此字段在每个文档中可能包含多个值,即如果它可以在文档中出现多次,则为真

A multivalued field is useful when there are more than one value present for the field.当字段存在多个值时,多值字段很有用。 An easy example would be tags, there can be multiple tags that need to be indexed.一个简单的例子是标签,可能有多个标签需要被索引。 so if we have tags field as multivalued then solr response will return a list instead of a string value.因此,如果我们将标签字段设置为多值,则 solr 响应将返回一个列表而不是字符串值。 One point to note is that you need to submit multiple lines for each value of the tags like:需要注意的一点是,您需要为标签的每个值提交多行,例如:

<field name="tags">tag1</tags>
<field name="tags">tag2</tags>
...
<field name="tags">tagn</tags>

Once you have all the values index you can search or filter results by any value, e,g.拥有所有值索引后,您可以按任何值搜索或过滤结果,例如you can find all documents with tag1 using query like您可以使用以下查询找到所有带有 tag1 的文档

q=tags:tag1

or use the tags to filter out results like或使用标签过滤掉结果,如

q=query&fq=tags:tag1

multiValued defined in the schema whether the field is allowed to have more than one value. multiValued 在模式中定义是否允许字段具有多个值。

For instance:例如:
if I have a fieldType called ID which is multiValued=false indexing a document such as this:如果我有一个名为 ID 的 fieldType,它是 multiValued=false 索引文档,例如:

doc {
  id : [ 1, 2]
  ...
}

would cause an exception to be thrown in the indexing thread and the document will not be indexed (schema validation will fail).会导致在索引线程中抛出异常并且文档不会被索引(模式验证将失败)。

On the other hand if I do have multiple values for a field I would want to set multiValued=true in order to guarantee that indexing is done correctly, for example:另一方面,如果我确实有一个字段的多个值,我想设置 multiValued=true 以保证索引正确完成,例如:

doc {
  id : 1
  keywords: [ hello, world ]
  ...
}

In this case you would define "keywords" as a multiValued field.在这种情况下,您可以将“关键字”定义为多值字段。

I use multiple value fields only with copyfields, so think this way, say all fields will be single valued unless it's a copyfield, for example I have following fields:我只对复制字段使用多个值字段,所以这样想,说所有字段都是单值的,除非它是一个复制字段,例如我有以下字段:

<field name="id" type="string" indexed="true" stored="true"/>
<field name="name" type="string" indexed="true" stored="true"/>
<field name="subject" type="string" indexed="true" stored="true"/>
<field name="location" type="string" indexed="true" stored="true"/>

I want to query one field only and possibly to search all 4 fields above, then we need to use copyfield.我只想查询一个字段,可能要搜索上面的所有 4 个字段,那么我们需要使用 copyfield。 first to create a new field call 'all', then copy everything into 'all'首先创建一个新字段调用'all',然后将所有内容复制到'all'

<field name="all" type="text" indexed="true" stored="true" multiValued="true"/>
<copyField source="*" dest="all"/>

Now field 'all' need to be multi-valued.现在字段'all'需要是多值的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM