Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of "multiValued" field type in Solr?

I'm new to 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.

What internally Solr does/treats/handles a field that is marked as multiValued?

What is the difference in indexing in Solr between a field that is multiValued and those that are not?

Can somebody explain with some good example?

Doc says:

multiValued=true|false

True if this field may contain multiple values per document, i.e. if it can appear multiple times in a document

like image 542
Gnanam Avatar asked Apr 27 '11 07:04

Gnanam


People also ask

What is multivalued field in Solr?

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.

What is a multivalued field?

A multivalued field (MVF) allows for the storage of more than one value in a database field. MVFs are somewhat controversial, with many arguing that they violate one of the very sacred tenets of database design as laid out by E.F.

What is the purpose of field analysis in Solr?

Field analysis tells Solr what to do with incoming data when building an index. A more accurate name for this process would be processing or even digestion, but the official name is analysis.

What is field type in Solr?

The field type defines how Solr should interpret data in a field and how the field can be queried. There are many field types included with Solr by default, and they can also be defined locally.


3 Answers

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
like image 59
Umar Avatar answered Oct 23 '22 00:10

Umar


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.

like image 41
Asaf Avatar answered Oct 23 '22 02:10

Asaf


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.

like image 12
waynet Avatar answered Oct 23 '22 02:10

waynet