Могу ли я использовать Solr DocumentObjectBinder и аннотацию Field для создания рекурсивно вложенных документов? - PullRequest
0 голосов
/ 24 октября 2018

Мы используем Solr версии 6.4.

Отправляя документы через веб-интерфейс Solr, я могу добавлять документы в наш индекс Solr, которые вложены в произвольную глубину.Мы заинтересованы только в добавлении документов, вложенных в уровень внука, так как запросы к вложенным документам становятся довольно сложными.Пример документа будет выглядеть следующим образом.

{
  "record_type_id": 1,
  "title": "Really good book",
  "author": "Jane Doe",
  "_childDocuments_": [
    {
      "record_type_id": 2,
      "section_title": "A section title"
      "_childDocuments_": [
        {
          "record_type_id": 3,
          "section_title": "A subsection title"
        },
        {
          "record_type_id": 3,
          "section_title": "Another subsection title"
        }
      ]
    }
}

Тогда у нас есть несколько объектов Java, таких как:

public class SolrRootDoc {
    private Integer recordTypeId;
    private String title;
    private String author;

    @Field(child = true)
    private List<SolrChildDoc> childDocuments;

    public Integer getRecordTypeId() {
        return recordTypeId;
    }

    @Field("record_type_id")
    public void setRecordTypeId(final Integer recordTypeId) {
        this.recordTypeId = recordTypeId;
    }

    public String getTitle() {
        return title;
    }

    @Field("title")
    public void setTitle(final String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }

    @Field("author")
    public void setAuthor(final String author) {
        this.author = author;
    }

    public List<SolrChildDoc> getChildDocuments() {
        return childDocuments;
    }

    public void setChildDocuments(final List<SolrChildDoc> childDocuments) {
        this.childDocuments = childDocuments;
    }
}


public class SolrChildDoc {
    private Integer recordTypeId;
    private String sectionTitle;

    @Field(child = true)
    private List<SolrChildDoc> childDocuments;

    public Integer getRecordTypeId() {
        return recordTypeId;
    }

    @Field("record_type_id")
    public void setRecordTypeId(final Integer recordTypeId) {
        this.recordTypeId = recordTypeId;
    }

    public String setSectionTitle() {
        return sectionTitle;
    }

    @Field("section_title")
    public void setSectionTitle(final String sectionTitle) {
        this.sectionTitle = sectionTitle;
    }

    public List<SolrChildDoc> getChildDocuments() {
        return childDocuments;
    }

    public void setChildDocuments(final List<SolrChildDoc> childDocuments) {
        this.childDocuments = childDocuments;
    }
}

Когда я запускаю модульный тест, который пытается загрузить эти классы с DocumentObjectBinder.Я получаю следующую ошибку.

java.lang.StackOverflowError в java.security.AccessController.doPrivileged (собственный метод) в org.apache.solr.client.solrj.beans.DocumentObjectBinder.collectInfo (DocumentObjectBinder).java: 143) в org.apache.solr.client.solrj.beans.DocumentObjectBinder.getDocFields (DocumentObjectBinder.java:123) в org.apache.solr.client.solrj.beans.DocumentObjectBinder.access $ 400 (DocumentObjectBinder.j:38) в org.apache.solr.client.solrj.beans.DocumentObjectBinder $ DocField.populateChild (DocumentObjectBinder.java:317) в org.apache.solr.client.solrj.beans.DocumentObjectBinder $ DocField.storeTybb:243) at org.apache.solr.client.solrj.beans.DocumentObjectBinder $ DocField. (DocumentObjectBinder.java:183)

Строки "at" в этой ошибке повторяются.Кажется, довольно ясно, что рекурсия поглощает стек.Если я удалю свойство childDocuments из класса SolrChildDoc, ошибка исчезнет.

Можно ли представить документы Solr, вложенные в произвольный уровень, с помощью аннотации @Field и DocumentObjectBinder?Как бы я это сделал, не вызывая StackOverflowError?

...