简体   繁体   中英

Solr - what is the difference between multivalued string field and single valued string with multi values?

If I need to index a set of values under a single field name, should I use multivalued field or should I use a singlevalued field and have all the values in this field seperated by a whitespace?

the field type is string.

thanks.

you can think of multivalued field as an array or a list... and for your question it depends what kind of operations will you run on that field.

if you will keep adding some stuff to that field frequently, you should go with multivalued field. instead of setting single string field each time you get a new item to add, you can simply add it to the multivalued field. Also if you multivalued field, you wont need to know the whole list while updating it. but for a single field, you need to know the old values in it..

to make it more clear;

lets say that you need to index "aaa bbb ccc".. if you put them into single field it will be something like

<str>aaa bbb ccc</str>

and if you need add ddd to this field, then you need to add aaa bbb ccc ddd to the field actually (I asssume you wouldnt want to check the old values of the field each time you are updating it)

but if you go with multivalued field, for aaa bbb ccc it will be something like

<field><str>aaa</str><str>bbb</str><str>ccc</str></field>

for this case, when you need to add ddd, you dont have to know the old values, just add ddd and you are done...

but if there will be removals from the field too, you should go with single field, as solr doesnt support deletions from a multivalued field (though you can do it with ease by hacking the source code )

i hope it helps... as the information you have given is some kinda too little to have a clear answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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