fraf
October 13, 2021, 1:24pm
1
Hi everyone,
I just need to query if a given value is contained in a list of value. In SQL we simply use the IN operator :
…where entity.id in (1,2,3)
Can we have the same operator for Hibernate search, this allows to less code for us :
For instance :
List<ChoixMentionMicen> unmatchingList = Arrays.asList(ChoixMentionMicen.MENTION_EXECUTOIRE_A_ORDRE, ChoixMentionMicen.MENTION_EXECUTOIRE_NOMINATIVE, ChoixMentionMicen.NOTE_SIMPLE_INFORMATION, ChoixMentionMicen.MENTION_RECTIFICATIVE);
PredicateFinalStep b = fa.bool(b0 -> b0.mustNot(fa.match().field(MentionMicen_.NATURE).matching(unmatchingList, ValueConvert.NO)));
Of course, the HSearch gurus gave the solution here :
Is there a preferred way in the predicate DSL to match any in a list of enums? This is to match a state field that is annotated as @GenericField. In the search form, the users can select on one or more states to match. I see for .id() there is the concept of matchingAny, but I don’t see that available for anything else. Is this correct? Is so, what is the preferred method? I could build a SimpleQueryString or dynamically construct a must with a series of shoulds, etc. Thanks, Keith
But I hope that the IN operator should be provided…of course, we could extend this kind of need to be closer to JPA API (coalesce(), between, disjunction, etc.)
Less user code = less bug.
Thanks.
I think you want the terms
predicate , which was added in Hibernate Search 6.1.0.Alpha1. So you just have to upgrade
fraf
October 13, 2021, 1:34pm
3
Yes you’re right, I saw the ticket : [HSEARCH-2589] Add syntactic sugar to the QueryDSL for simple multiple-term keyword matches - Hibernate JIRA
But here at work, we prefer final version :).
We are still at 6.0.0 Final … but soon I will remove a part of my QueryDSLHelper so. Good news !