Search code examples
javasolrsolrj

Solr 5.2 How to define a List or collection of Strings


I am new to Solr and really like it thus far.

I have been able to define in the Schema.xml my data types for indexing and using Solrj Bean annotations @field on my solr domain objects I have my Java application calling solrClient and saving them which is great.

Unfortunately I am unable to see or understand how I would model a collections of Strings in ether Schema.xml or the Java object.

What I would like to do is something like this:

@field
private String someField;
@field
private String anotherField;
@field   
private List<String> someCollectionOfFields;

I don't understand how I should model this scenario, At first I though of flattening out the collection as a comma separated list and defining it as a String but don't understand how Solr will treat it?

So if I have the following "Big Bus", "Big Red Bus", "Big Red Car" I wold like the 3 strings indexed as separate terms and not just the word Big causing all 3 to be returned.

Should I be doing something like this?

I am struggling to find how to model collections in the docs, all I see is Date Fields, Money Fields and others but no collections, any help would be great.

Thanks Marc


Solution

  • Solution for your problem is Solr field type with property multiValued=true

    define a field as below

    <field name="bustypes" type="string" indexed="true" stored="true" multiValued="true"/>
    

    This will allow as to send multiple values for the same field for the same doc.

    Say

    <add>
        <doc>
            <field name="id">1234</field>
            <field name="bustypes">Big Bus</field>
            <field name="bustypes">Big Red Bus</field>
            <field name="bustypes">Big Red Car</field>
        </doc>
    </add>