我有两个班。
public Class Student
{
//primary key
private String id;
private String name;//name = Jonathan
....
private List<CustomField> customFields;
}
public Class CustomField
{
//primary key
private String id;
private String fieldName;
....
private String fieldValue;
}
customFields 由用户定义,可以是任何字段和值。例如:customFields 列表中有两个对象。它们是 [id = 001,fieldName = age,value = 30] [id=002,fieldName = score,value = 90]。(用户也可以在 customFields 列表中添加/更新一些必要的字段,customFields 是动态的)
因此,如果“学生”课程发送到我的网页,它将在网页上显示:姓名:[Jonathan] Age:[30] Score:[90]。
用户案例:用户可以按姓名、年龄、分数等字段进行搜索。所以这些字段应该被索引到 Lucene 文档中。如果使用 Hibernate 搜索索引自定义字段,我如何为动态字段编写索引注释?
所以我需要使用 Hibernate Search 索引和搜索动态 customFields,我可以实现它吗?你懂我的意思吗?
编辑:
public class CustomFieldBriddge implements FieldBridge
{
public void set(String name, Object value, Document document, LuceneOptions luceneOptions)
{
Field.Store store = luceneOptions.getStore();
Field.Index index = luceneOptions.getIndex();
Field.TermVector termVector = luceneOptions.getTermVector();
Float boost = luceneOptions.getBoost();
if (value != null)
{
List<CustomField> customFields = (List) value;
for (CustomField customField : customFields)
{
String fieldName = customField.getFiledName();
String fieldValue = customField.getFiledValue();
Field field = new Field(fieldName, fieldValue, store.YES, index.NOT_ANALYZED,
termVector); // is the field will index into Lucene document one by one?and it can be searched out? right?
field.setBoost(boost);
document.add(field); // is this operation will index the field into Lucuene Document?
}
}
}