-
Notifications
You must be signed in to change notification settings - Fork 246
HSEARCH-3319 Type-safe field references / HSEARCH-5300 Annotation processor for the Search static metamodel #4156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
de353a5
to
aaf4fff
Compare
...e/src/main/java/org/hibernate/search/engine/search/predicate/dsl/SearchPredicateFactory.java
Outdated
Show resolved
Hide resolved
mapper/orm/src/main/java/org/hibernate/search/mapper/orm/scope/SearchScope.java
Outdated
Show resolved
Hide resolved
8555146
to
296c173
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @yrodiere 😃 the approach we discussed last Friday seems to work well so far. (see the new inline comments or just take a look at the FieldReferenceIT
)
One thing I'm not sure how to deal with is named predicates. They are defined in binders, where there's no notion of search scope. Since binders would define the index structure, does it make sense to use the generated metamodel in them? as its generation depends on the binder ... 🤔 🙈
...tion/src/test/java/org/hibernate/search/documentation/search/predicate/FieldReferenceIT.java
Outdated
Show resolved
Hide resolved
...tion/src/test/java/org/hibernate/search/documentation/search/predicate/FieldReferenceIT.java
Show resolved
Hide resolved
...tion/src/test/java/org/hibernate/search/documentation/search/predicate/FieldReferenceIT.java
Outdated
Show resolved
Hide resolved
So, in the new commit, I've tried adding a Maven plugin that would generate things. The approach I've taken here is to have model+ search config classes in their own jar that is passed as a dependency to the Maven plugin. The plugin then starts the Search. I've used some of our test helpers to start things since, well, it's just to test how it'll work. It generates something like: package org.hibernate.search.metamodel.generator.model;
class MyEntity__ {
public String text;
} package org.hibernate.search.metamodel.generator.model;
class MyProgrammaticEntity__ {
public String number;
public String text;
} And since it happens on the generate sources phase, these are getting compiled automatically by Maven itself. As for the plugin configuration: <configuration>
<annotatedTypes>
<type>org.hibernate.search.metamodel.generator.model.MyEntity</type>
<type>org.hibernate.search.metamodel.generator.model.MyProgrammaticEntity</type>
</annotatedTypes>
<properties>
<hibernate.search.mapping.configurer>org.hibernate.search.metamodel.generator.model.MyConfigurer</hibernate.search.mapping.configurer>
</properties>
</configuration> There's a way to pass any properties that should be "forwarded" to the Search through now.... next thing I'd want to try is to run the plugin in the same module that the model is. From what I've seen so far, it is easy to get the source root, and the dependencies (things that were missing in the AP approach). |
0c8366e
to
30f9d6a
Compare
5789bc7
to
159347c
Compare
baae623
to
b8ad37a
Compare
b8ad37a
to
b5a16ea
Compare
Thanks for your pull request! This pull request appears to follow the contribution rules. › This message was automatically generated. |
b5a16ea
to
cbfcec9
Compare
|
f04af13
to
e3a9d5a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @yrodiere,
I've added the AP experiments to this branch as in the end we'd want to use the interfaces introduced here to generate that model.... as if the PR wasn't big enough already 😄, but the experiments are all in a single commit, and I've added comments to the places I think are of interest. There's a lot of boring code similar to the one we have in the annotation processors, as these just work with a different model.
the next steps, as I see it, are:
- keep adding the missing bits (e.g. type level binders etc.). As I encounter some new code example from the docs, or just when I remember some missing part, I add it to the test and then see what has to be added to the processor to get it working.
- write a simple class from the model.
- take care of "various backends". I think that we'd just add all backends (lucene,elasticsearch) and have a config property for the annotation processor to let the user specify the backend to use (or even both).
- deal with the ORM mapper. I don't think that it would be feasible to make ORM somehow generate the model from
javax.lang.model.element
types. Hence, my thinking here is to add a specific processor that reads the ORM's@Id
and treats them as@DocumentId
; ignore the access type for now 🙈
...org/hibernate/search/metamodel/processor/impl/IndexedEntityMetamodelAnnotationProcessor.java
Outdated
Show resolved
Hide resolved
...org/hibernate/search/metamodel/processor/impl/IndexedEntityMetamodelAnnotationProcessor.java
Outdated
Show resolved
Hide resolved
...essor/src/main/java/org/hibernate/search/metamodel/processor/impl/ProcessorElementUtils.java
Outdated
Show resolved
Hide resolved
...g/hibernate/search/metamodel/processor/mapping/ProcessorPojoModelsBootstrapIntrospector.java
Outdated
Show resolved
Hide resolved
...te/search/metamodel/processor/annotation/processing/impl/ProcessorKeywordFieldProcessor.java
Outdated
Show resolved
Hide resolved
...search/metamodel/processor/annotation/processing/impl/ProcessorPropertyBindingProcessor.java
Outdated
Show resolved
Hide resolved
...search/metamodel/processor/annotation/processing/impl/ProcessorPropertyBindingProcessor.java
Outdated
Show resolved
Hide resolved
...ate/search/metamodel/processor/annotation/processing/impl/ProcessorVectorFieldProcessor.java
Outdated
Show resolved
Hide resolved
Hey. I'm finally having a look, but first some answers
Backends should be in the user classpath already, no? If you rely on that, you can make the annotation processor work without any configuration for the most common case (only one backend type in the classpath).
Makes sense. Except...
As stated, I agree. But:
Critically, this task can even be extracted to a separate issue, and we can ask someone who knows this AccessType stuff to help with a first solution that just implements this stuff directly in Hibernate Search :)
That's a very reasonable temporary solution. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No complaints, everything seems very reasonable :)
Maybe now would be the time to start merging things? It looks like we're going to go ahead with this solution, so it's not like we're going to revert it entirely. You'll just keep adding/updating code from now on, I believe?
@@ -354,7 +373,7 @@ PredicateFinalStep withParameters( | |||
* @return A new predicate factory using the given object field as root. | |||
*/ | |||
@Incubating | |||
SearchPredicateFactory withRoot(String objectFieldPath); | |||
SearchPredicateFactory<SR> withRoot(String objectFieldPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be...
SearchPredicateFactory<SR> withRoot(String objectFieldPath); | |
SearchPredicateFactory<?> withRoot(String objectFieldPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh, this one had been pending on your PR for quite some time. Sorry about that.
...org/hibernate/search/metamodel/processor/impl/IndexedEntityMetamodelAnnotationProcessor.java
Outdated
Show resolved
Hide resolved
...org/hibernate/search/metamodel/processor/impl/IndexedEntityMetamodelAnnotationProcessor.java
Outdated
Show resolved
Hide resolved
...essor/src/main/java/org/hibernate/search/metamodel/processor/impl/ProcessorElementUtils.java
Outdated
Show resolved
Hide resolved
...g/hibernate/search/metamodel/processor/mapping/ProcessorPojoModelsBootstrapIntrospector.java
Outdated
Show resolved
Hide resolved
...te/search/metamodel/processor/annotation/processing/impl/ProcessorKeywordFieldProcessor.java
Outdated
Show resolved
Hide resolved
...search/metamodel/processor/annotation/processing/impl/ProcessorPropertyBindingProcessor.java
Outdated
Show resolved
Hide resolved
...search/metamodel/processor/annotation/processing/impl/ProcessorPropertyBindingProcessor.java
Outdated
Show resolved
Hide resolved
...ate/search/metamodel/processor/annotation/processing/impl/ProcessorVectorFieldProcessor.java
Outdated
Show resolved
Hide resolved
0cd1cc0
to
3981dcb
Compare
6bbabbd
to
3c6ad42
Compare
documentation/src/main/asciidoc/public/reference/_static-metamodel-overview.adoc
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't review it all unfortunately, but here are a few comments on the documentation.
Great stuff :)
documentation/src/main/asciidoc/public/reference/_static-metamodel.adoc
Outdated
Show resolved
Hide resolved
documentation/src/main/asciidoc/public/reference/_static-metamodel-overview.adoc
Outdated
Show resolved
Hide resolved
documentation/src/main/asciidoc/public/reference/_static-metamodel-overview.adoc
Outdated
Show resolved
Hide resolved
documentation/src/main/asciidoc/public/reference/_static-metamodel-overview.adoc
Outdated
Show resolved
Hide resolved
documentation/src/main/asciidoc/public/reference/_static-metamodel-overview.adoc
Outdated
Show resolved
Hide resolved
documentation/src/main/asciidoc/public/reference/_static-metamodel-overview.adoc
Outdated
Show resolved
Hide resolved
documentation/src/test/java/org/hibernate/search/documentation/search/metamodel/Author__.java
Outdated
Show resolved
Hide resolved
...mentation/src/test/java/org/hibernate/search/documentation/search/metamodel/MetamodelIT.java
Show resolved
Hide resolved
.../main/java/org/hibernate/search/engine/search/aggregation/dsl/RangeAggregationFieldStep.java
Outdated
Show resolved
Hide resolved
5120cbd
to
b5467d0
Compare
b5467d0
to
c92216e
Compare
|
https://hibernate.atlassian.net/browse/HSEARCH-3319
https://hibernate.atlassian.net/browse/HSEARCH-5300
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license
and can be relicensed under the terms of the LGPL v2.1 license in the future at the maintainers' discretion.
For more information on licensing, please check here.