I'm new to solr. I've gone through a couple of blogs on solr integration into a web project. In my current project, the different java entities are stored in the solr index as space separated serialized string. Like, firstname + " " + lastname + " " + email....and so on. All the disparate entities are stored like this with classname_primaryId as the unique key. Is this the standard way of storing the different entities in solr? How should I go about it? Can I keep these entities separately in solr? Any guidance/help is appreciated. I'm already short on time!!!!
Asked
Active
Viewed 207 times
0
-
By different entites I mean, say Person and Address entities in java. – jay Jul 13 '15 at 18:39
1 Answers
0
Solr is a document search engine, so you should think about your data in those terms.
If you want to make the entities searchable, I believe that the best way would be to serialize the Java entities into documents (objects represented in JSON), and then add specialized fields (such as a copyField that contains data from all other fields that you want to search when field name is not specified) on top of that. You don't need to do the space separated representation at your application side, Solr handles that automatically when you use a copyField in the schema.
In this way you have the ability to search on per field basis, and when required search on all fields at once by targetting the copy field.

Fuu
- 3,424
- 4
- 33
- 49
-
Currently, I've the schema.xml with fields- `
id `. The _entityData_ has all the space separated data for an entity. As per your suggestion, does that mean that I need to create a copyField for _entityData_ and that will have all the data, including the nested entities in an entity? If yes, then what can I store in _entityData_? – jay Jul 14 '15 at 14:12 -
There is another requirement that, I need to Import the data from database into the solr. I've read that, DataImportHandler could be used for it. If I go with the json approach, then I'll have to create JSONs for all the records and then upload them. Also, is there a way, by which I can convert the solr result to the respective java objects? – jay Jul 14 '15 at 14:20
-
You would have fields defined in the schema for all the entity properties that you want to index, and copyField with a wildcard in the source so that it matches all the desired source fields. Solr returns JSON, and you can use your favourite JSON library to convert them back into objects. – Fuu Jul 14 '15 at 22:19