Skip to content
This repository has been archived by the owner on Mar 19, 2021. It is now read-only.

HQLPARSER-72 Upgrade to search 5.6.0.Final #40

Merged
merged 3 commits into from
Jan 31, 2017

Conversation

DavideD
Copy link
Member

@DavideD DavideD commented Jan 31, 2017

https://hibernate.atlassian.net/browse/HQLPARSER-72

Can you guys have a quick look at it?

I tried to stick to the existing code although it looks a weird in a couple of places (where we use the unwrap)

@DavideD DavideD self-assigned this Jan 31, 2017
Copy link
Member

@yrodiere yrodiere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My two cents... All in all, I feel like this whole field bridge introspection should disappear in favor of proper retrieval of the encoding from the metadata. But maybe it's not possible for some reason... ?

if ( fieldBridge instanceof NullEncodingTwoWayFieldBridge ) {
fieldBridge = ( (NullEncodingTwoWayFieldBridge) fieldBridge ).unwrap();
if ( fieldBridge instanceof BridgeAdaptor ) {
fieldBridge = ( (BridgeAdaptor) fieldBridge ).unwrap( NumericFieldBridge.class );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit dangerous, because if the field bridge is an adaptor over something else than a NumericFieldBridge, the field bridge will be null from there on. It'll work, but it's not obvious why.

Anyway... Inspecting bridges is a bit tricky. Since you seem to have access to metadata here, why don't you simply use org.hibernate.search.engine.metadata.impl.DocumentFieldMetadata.getNumericEncodingType() to retrieve the numeric encoding? It's also accessible through the public metadata API, mind you.

@@ -111,24 +111,24 @@ public void shouldCreateQueryWithUnqualifiedPropertyReferences() {
public void shouldCreateNegatedQuery() {
assertLuceneQuery(
"from IndexedEntity e where NOT e.name = 'same'",
"-name:same *:*" );
"-name:same #*:*" );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "#" seems weird. Why did you add this? Where did you find documentation about this syntax?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the query generated when I upgrade the library and I don't change anything else. I thought it was due to the upgraded library and didn't think too much of it but it seems nobody knows why it is happening.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have an in-depth look

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's the syntax for a "FILTER" clause type of Boolean Query. Looks correct 👍

indexedEntityBridges.put( "position", NumericFieldBridge.LONG_FIELD_BRIDGE );
indexedEntityBridges.put( "code", new NullEncodingTwoWayFieldBridge( NumericFieldBridge.LONG_FIELD_BRIDGE, "_null_" ) );

indexedEntityBridges.put( "code", new NullEncodingTwoWayFieldBridge( NumericFieldBridge.LONG_FIELD_BRIDGE, stringNullCodec ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about what was going on previously here, but I know that we currently do not support having a non-numeric null marker on an otherwise numeric field. At least the default numeric field bridges will only create numeric null markers. So this kind of setup ("_null_" used as a marker on a numeric field) cannot happen in practice when you're using Hibernate Search.

To be in line with real-world use cases, you should use a LuceneLongNullMarkerCodec here, since code seems to be a numeric (long) field. Also, the null marker should be retrieved from the bridge itself. Something like NumericFieldBridge.LONG_FIELD_BRIDGE.createNullMarker( "-1" ).

The related code in Hibernate Search is in org.hibernate.search.engine.nulls.impl.LuceneMissingValueStrategy.createNullMarkerCodec(Class<?>, DocumentFieldPath, NullMarker) and org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.createNullMarker(FieldBridge, String, DocumentFieldPath) (both called by org.hibernate.search.engine.metadata.impl.AnnotationMetadataProvider.determineNullMarkerCodec(FieldBridge, Field, ConfigContext, ParseContext, Class<?>, DocumentFieldPath)).

@@ -73,10 +73,10 @@ private Object convertToPropertyType(String entityType, List<String> propertyPat
//Order matters! Some types are subclasses of others
//TODO expose something in Hibernate Search so that we can avoid this horrible code
if ( bridge instanceof NullEncodingTwoWayFieldBridge ) {
return convertToPropertyType( entityType, propertyPath, value, ( (NullEncodingTwoWayFieldBridge) bridge ).unwrap() );
return convertToPropertyType( entityType, propertyPath, value, ( (NullEncodingTwoWayFieldBridge) bridge ).unwrap( NullEncodingTwoWayFieldBridge.class ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will most likely result in a null unwrapped bridge, since BridgeAdaptor.unwrap doesn't take the adaptor itself into account.

Anyway... here too, can't we simply use the metadata? Add an abstract getNumericEncoding method instead of introspecting field bridges? It would seem simpler and easier to maintain...

@DavideD
Copy link
Member Author

DavideD commented Jan 31, 2017

@yrodiere I did some refactoring and tried to applied what you suggested.

@Sanne Sanne merged commit 6f1fd9b into hibernate:master Jan 31, 2017
@Sanne
Copy link
Member

Sanne commented Jan 31, 2017

merged, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants