I’ve created a TypeBridge but for some reason the fields which are declared within the binding and the values set in the bridge do not seem to exist.
When I start up the application I can debug through my binding, so the code is used. When I look at my tomcat logs I can see
- operation: apply type bridge
bridge: SimpleBeanHolder[instance=package.and.class.of.my.binding]
with no further details. Right after that entry it states
- operation: process property
handle:....
The fields I declared in the binding are not shown in the log.
Next, as soon as I do a search against one of the declared fields I receive the error message
org.hibernate.search.util.common.SearchException: HSEARCH600000: Unknown field ....
although I create the field in the following way:
context.typeFactory().asString().searchable(Searchable.YES).projectable(Projectable.YES).sortable(Sortable.YES).aggregable(Aggregable.YES).toIndexFieldType()
So right now I guess I’m missing something. Please give me a hint what that could be!
thx in advance
Nor should they.
- This log displays a static view of what will be executed when indexing. It’s logged on startup, not when indexing happens, so it doesn’t have any field values to display.
- When it comes to custom bridges, Hibernate Search doesn’t know what they do when indexing, so it cannot give you more details than “I will execute this bridge”.
If you want more details in this log, implement toString()
on your bridge.
This doesn’t create a field, this creates a field type. If you think about it, you didn’t pass a name, so there’s no way Hibernate Search could create a field.
I suggest you start with an example from the documentation (e.g. this one) and adapt it to your needs. Examples in the documentation are actually tested, so you can be sure they include everything needed.
Thx for the fast reply and the clarification about the logs!
Concerning the field definition you are right, this is just the body of a method I use and created in a base class:
protected IndexFieldType<String> aggregableProjectableSortableSearchableCharacterFieldType(){
return context.typeFactory().asString().searchable(Searchable.YES).projectable(Projectable.YES).sortable(Sortable.YES).aggregable(Aggregable.YES).toIndexFieldType();
}
within the binding I call it the following way:
…..
@Override
public void bind(TypeBindingContext context) {
super.bind(context);
context.dependencies()
.use(….;
Bridge bridge = new Bridge();
IndexSchemaElement schema = context.indexSchemaElement();
bridge.setMyFieldTextField(schema.field("myField", aggregableProjectableSortableSearchableCharacterFieldType()).toReference());
context.bridge(
MyClass.class,
bridge
);
}
class Bridge implements TypeBridge<MyClass> {
private IndexFieldReference<String> myFieldTextField;
@Override
public void write(DocumentElement target, MyClass myClass, TypeBridgeWriteContext context) {
target.addValue(myFieldTextField, myClass.getSomeStringValue());
}
public void setMyFieldTextField(IndexFieldReference<String> myFieldTextField) {
this.myFieldTextField = myFieldTextField;
}
}
I followed the steps in the documentation and would expect to be able to search against the field “myField".
I concur.
What happens we you try to search?
If there are no results, you probably need to reindex your database.
If there is an error, please show the stack trace.