在 Solr 中“ multiValue”字段类型有什么用?

我是 Apache Solr 的新手。甚至在阅读了 文件部分之后,我发现很难清楚地理解 multiValued字段类型属性的功能和用法。

Solr 在内部对标记为 多值的字段执行/处理/处理哪些操作?

在 Solr,一个字段是 多值,而另一个字段不是 多值,这两者在索引方面有什么不同?

有人能举个好例子解释一下吗?

多克表示:

MultiValue = true | false

如果这是真的 字段可能包含每个 文件,即如果它可以出现 在一个文档中多次出现

85364 次浏览

multiValued defined in the schema whether the field is allowed to have more than one value.

For instance:
if I have a fieldType called ID which is multiValued=false indexing a document such as this:

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:

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

In this case you would define "keywords" as a multiValued field.

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. 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

q=tags:tag1

or use the tags to filter out results like

q=query&fq=tags:tag1

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. first to create a new field call 'all', then copy everything into 'all'

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

Now field 'all' need to be multi-valued.