An update to first snippet, taking into account:
- the discussion (well, monologue) about encoding
- the requirement to handles multiple input source
- the custom bridge annotations mentioned in
HSEARCH-175 Open
- the fact that we want to know from the start which entity properties will be accessed by custom field bridges; this will enable more complete dirtiness resolution (
HSEARCH-2496 Open ), but also may help when using JSON as input (we'll be able to read the JSON as a stream, and only collect those values that are of interest to bridges)
- the fact we want to give access to the SearchIntegrator from within bridges (
HSEARCH-1306 Open )
- and
This is all very rough at the moment, for instance it doesn't take into account that, potentially, the multiple input sources could be in contained objects (myObject.someProperty.someOtherProperty), so there will be some challenge in controlling the scope of annotation parsing. Annotation:
@BridgeDefinition(impl = MyBridge.class)
public @interface MyBridgeAnnotation {
String foo();
@BridgeDefinition.Input @interface SubInputAnnotation1 {
String bar();
}
@BridgeDefinition.Input
@interface SubInputAnnotation2 {
}
}
Bridge:
public class MyBridge implements HibernateSearchComplexBridge<MyBridgeAnnotation> { private Input<MyEntity, ?> defaultInput; private Input<Date, SubInputAnnotation1> input1; private Input<String, SubInputAnnotation2> input2; private FieldDefinition<String> myField1; private FieldDefinition<Date> myField2; private FieldDefinition<Integer> myField3; public void initialize(SearchIntegrator integrator /*
HSEARCH-1306 Open */) { } public void configure(MyBridgeAnnotation annotation, Metadata metadata) String foo = annotation.foo(); // ... use foo to configure the bridge ... // Allows bridges to use field names such as "<defaultName>.foo" String defaultRelativeName = metadata.getDefaultRelativeName(); // Allows to bypass input registration (and thus disables automatic dirtiness detection) /*
- Ideally, bridges using mutable input from different entities than the one the
- annotation was applied to should not use this, and declare input explicitly
- as is done for input1 and input2 below.
*/ defaultInput = metadata.getDefaultInput( MyEntity.class );
input1 = metadata.getInput( Date.class, SubInputAnnotation1.class ); input2 = metadata.getInput( String.class, SubInputAnnotation2.class ); SubInputAnnotation1 confInput1 = input1.get( SubInputAnnotation1.class ); // ... use confInput1.bar() to configure how input1 will be handled... myField1 = metadata.addField("name1", MyEncodings.string().build() ); myField2 = metadata.addField("name2", MyEncodings.date().build() ).withImplementation( MyElasticsearchEncodings.date().withFormat( "yyy-mm-ddd" ).build() ); myField3 = metadata.addField("name3", MyEncodings.integer().build(); } public void set(InputSource inputSource, org.hibernate.search.Document document) { Date date = inputSource.get( input1 ); String string = inputSource.get( input2 ); // ... do some processing ... document.add(myField1, /* someValue */); document.add(myField2, /* someValue */); document.add(myField3, /* someValue */); } }
@MyBridgeAnnotation(foo = "foo") public class MyEntity { @MyBridgeAnnotation.SubInputAnnotation1 private String myProperty1; @MyBridgeAnnotation.SubInputAnnotation2 private String myProperty2; }
|