我是lucene的新手 我面临一个问题,即 我只需要使用最新的versionIds为VersionPrimaryKey编制索引。 所有版本都使用以下定义的桥类建立索引。如果对象在数据库中有10个版本,则将全部索引。因此,当我搜索时所有返回。 我只需要最新版本。如何更新桥类以仅索引每个对象的最新版本? 我的班级定义如下
@Entity
public abstract class SuSEntity implements Versionable, Serializable {
@EmbeddedId
@IndexedEmbedded
@FieldBridge ( impl = VersionKeyFieldBridge.class )
private VersionPrimaryKey composedId;
}
public class VersionKeyFieldBridge implements TwoWayFieldBridge {
/**
* {@inheritDoc}
*/
@Override
public void set( String name, Object value, Document document, LuceneOptions luceneOptions ) {
if ( value != null ) {
VersionPrimaryKey versionPrimaryKey = ( VersionPrimaryKey ) value;
luceneOptions.addFieldToDocument( name, objectToString( versionPrimaryKey ), document );
}
}
/**
* {@inheritDoc}
*/
@Override
public Object get( String name, Document document ) {
String versionPrimaryKey = document.get( name );
return JsonUtils.jsonToObject( versionPrimaryKey, VersionPrimaryKey.class );
}
/**
* {@inheritDoc}
*/
@Override
public String objectToString( Object object ) {
VersionPrimaryKey versionPrimaryKey = ( VersionPrimaryKey ) object;
return JsonUtils.toJson( versionPrimaryKey );
}
}
@Embeddable
public class VersionPrimaryKey implements Serializable {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = 1L;
/** The id of object .Database primary key */
@Column ( name = "id" )
@Type ( type = "uuid-char" )
private UUID id;
/** The version id of object.Database primary key */
@GeneratedValue ( strategy = GenerationType.AUTO )
@Column ( name = "version_id" )
private int versionId;
@Override
public boolean equals( Object object ) {
if ( this == object ) {
return true;
}
if ( !( object instanceof VersionPrimaryKey ) ) {
return false;
}
final VersionPrimaryKey otherObject = ( VersionPrimaryKey ) object;
return Objects.equals( id, otherObject.id ) && Objects.equals( versionId, otherObject.versionId );
}
@Override
public int hashCode() {
return id.hashCode() * versionId;
}
有任何帮助。