以下是我的代码的基本概要:
@Entity
@Indexed
public class Document {
@IndexedEmbedded
@OneToMany(cascade = { PERSIST, MERGE }, mappedBy = "owner")
private final Set<Issue> issues = new LinkedHashSet<Issue>();
}
@Entity
public class Issue {
@ManyToOne
@JoinColumn(name = "owner_id")
@ContainedIn
private final Document owner;
@IndexedEmbedded
@OneToOne(cascade = ALL, optional = false)
@JoinColumn(name = "name_id")
@ForeignKey(name = "FK_issue__name_id__text_element")
private final TextElement name = new TextElement();
}
@Entity
public class TextElement {
@OneToMany(cascade = { CascadeType.ALL })
@JoinTable(
name = "text_element_paragraph",
joinColumns = { @JoinColumn(name = "text_element_id") },
inverseJoinColumns = { @JoinColumn(name = "paragraph_id") },
uniqueConstraints = {
@UniqueConstraint(
name = "UX_text_element_paragraph__paragraph_id",
columnNames = "paragraph_id"
)
}
)
@ForeignKey(
name = "FK_text_element_paragraph__text_element_id__text_element",
inverseName = "FK_text_element_paragraph__paragraph_id__paragraph"
)
@IndexedEmbedded
private List<Paragraph> paragraphs = new LinkedList<Paragraph>();
}
@Entity
public class Paragraph {
@Field(name = "data", analyze = Analyze.YES)
@Column(name = "s_data", nullable = false)
private String data;
}
我认为lucene会将段落中的数据编入索引,但是当我打开Luke时,它会显示&#34; issues.name.id&#34; (id来自一个Document扩展的类)。为什么不对数据编制索引?谢谢:))
我还应该注意,我刚从CRUD服务中的update方法中删除了一个手动索引器。之后一切都停止了,可能是我的配置吗?
答案 0 :(得分:0)
通过在TextElement中添加以下内容,我能够进行搜索工作:
@ContainedIn
private Document owner
答案 1 :(得分:-1)
我认为所有实体都必须注释为@Indexed
,否则@IndexEmbedded
将无法识别要编入索引的实体。
顺便说一下:深度遍历可能会导致重新索引出现问题。您需要使用@ContainedIn
...