Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is SOLR support complex types like structure for multiValued fields?

I need to add multiValued field which will be structure. Something like:

where:

class ComplexPhone [
    String area;
    String number;
    String internal;
    String type;
]

I want to receive this data from SOLR in json in format like this:

{
  "responseHeader": {
    "status": 0,
    "QTime": 1,
    "params": {
      "indent": "true",
      "q": "*:*",
      "_": "1394008742077",
      "wt": "json"
    }
  },
  "response": {
    "numFound": 1,
    "start": 0,
    "docs": [
      {
        "first_name": "Funky",
        "last_name": "Koval",
        "phone": [
          {
             "area": "US",
             "number": "555-123-456-789",
             "internal": "011,
             "type": "S",

          },
          {
             "area": "UK",
             "number": "1234-5678",
             "internal": "9001",
             "type": "L",

          }
        ]
        "id": 1,
        "_version_": 1461724104955527200
      }
    ]
  }
}

This is only example ( I do not want to have only phone numbers ).

Most important for me is format of response from SOLR. I can add this data in any plain format like: Funky, Koval, UK; 1234-5678; 9001; L, US; 555-123-456-789; 011; S or

<doc>
<field name="first_name">Funky</field>
<field name="last_name">Koval</field>
<field name="phone">UK; 1234-5678; 9001; L</field>
<field name="phone">US; 555-123-456-789; 011; S</field>
<field name="id">1</field>
</doc>

It can be stored in SOLR as a string. All I need is response in more complicated format then flat structure mapped to JSON.

Any advice will be appreciated.

like image 598
THM Avatar asked Mar 05 '14 08:03

THM


People also ask

What are general properties in Solr?

General Properties Solr supports for any field type. Field Default Properties that can be specified on the field type that will be inherited by fields that use this type instead of the default behavior. The name of the fieldType.

What is a Solr field type?

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. Topics covered in this section:

Where does Solr point to a class of code?

Where you see class="solr.TextField", this is where Solr points to a class of code that processes Fields of that type, in this case text. There are 21 such classes provided by Solr version 7 listed below. 3. Options for the Different fieldType Classes in Apache Solr

What's wrong with Solr field-guessing?

The Solr field-guessing functionality added fields and fieldTypes as it built a schema for us. The end result was an index with unnecessary overlap. A bloated index like this would slow an application, for example, if we added hundreds or thousands of documents to it.


1 Answers

Solr supports multuValued fields. But it doesn't support multilevel data structure. You can not get the following type of response from Solr.

"phone": [
          {
             "area": "US",
             "number": "555-123-456-789",
             "internal": "011,
             "type": "S",

          },
          {
             "area": "UK",
             "number": "1234-5678",
             "internal": "9001",
             "type": "L",

          }

What multiValued field provides is like

"phone": [
          "UK",
          "1234-5678",
          "9001",
          "L"
        ]

Suggestions :

  1. You can design your data in a simpler manner so that, it can fit in Solr provided singlevalued/multivalued field.
  2. Keep your complex structured data in Solr as string or some suitable type of field. In your application parse the data to get the actual value.

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

like image 122
buddy86 Avatar answered Sep 22 '22 05:09

buddy86