Solrj: how to store and retrieve a <POJO> list through a multi-valued field in an index

My use case is an index that contains the names of online media. The data provider associates a category list with each heading. I use SolrJ to populate an index through an annotated POJO class

eg.

@Field("title") private String title; @Field("categories") private List<Category> categoryList; 

Related POJO

 public class Category { private Long id; private String name; ... 

}

My question has two parts:

a) is this possible through SolrJ - the documents contain only the @Field example using List of String, so I assume serialization / sorting only supports simple types?

b) how to configure the scheme for its storage. I have a naive guess, I just need to set multiValued = true in the right field, and all this will work by magic.

I'm just starting to implement this, so any answer would be much appreciated.

+6
source share
1 answer

The answer is what you thought:

a) Only simple types are available. This way you will have a list of the same type, for example. Line. The point is that you cannot represent complex types inside a lucene document, so you will not deserialize them either.

b) The problem is that you are trying to imagine relational thinking in a "document repository." This will probably only work until a certain point. If you want to represent categories inside a lucene document, just use the line, there is no need to store the identifier.

The only item for storing the identifier is also: if you want to distract the search on RDBMS. If you want to do this, you need to make sure that the category identifier and name are not related. This does not work for every 1: n ratio. (Any 1: n ratio, where the n related table consists only of required fields, is possible. If you have an optional field, you need to put something like filling an empty constant in the field, if possible).

However, if these 1: n relationships are not sparse, this is possible if you maintain the order of adding fields to the document. Thus, a case with a category relationship can be presented if you do not sort the lists.

You can implement a method that returns this Category if you create it with values ​​in position 0 ... n. Thus, the solution would be if you would like the first category to be at position 0 of each list belonging to this category.

+8
source

Source: https://habr.com/ru/post/892381/


All Articles