Skip to content

Conversation

@marko-bekhta
Copy link
Member

https://hibernate.atlassian.net/browse/HSEARCH-4489

  • add matchNone() to DSL
  • update documentation to mention new predicate

I wasn't able to think of some simple yet, at the same time, meaningful use case for this new predicate, hence if anyone has some suggestions would be happy to add more tests around it.

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.

Well this is a nice surprise, thanks!

I added a few comments below.

include::{sourcedir}/org/hibernate/search/documentation/search/predicate/PredicateDslIT.java[tags=matchNone]
----
====

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I didn't include the original use case in the ticket; here it is: https://discourse.hibernate.org/t/fail-fast-predicate/6062?u=yrodiere

The best solution to avoid running a search query is simply to not call .fetch() at all, but in some cases people will have methods dedicated to the creation of inner predicates, and will not be able to prevent the query to run; in that case, they can just create a matchNone predicate and the end result will be the same (though it will unfortunately involve some pointless I/O).

So, as you can see, it's a very specific use case, for advanced users. I'm not sure we need further explanation than what you did here, but if you think you can add something clear and concise, feel free to give it a shot :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, that's an interesting case... Knew of match_all usage within dynamic filters but not the match_none. nice 😃
As for the text, I gave it a try ... aaaand the text becomes too cumbersome 😄 but as you've said - it's for advanced users. So those who need it would know its meaning, and others are probably safer without using it 😃

* Match none of the documents.
*
* @return The initial step of a DSL where the "match none" predicate can be defined.
* @see MatchAllPredicateOptionsStep
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* @see MatchAllPredicateOptionsStep
* @see MatchNonePredicateFinalStep

Comment on lines +45 to +51
@Test
public void matchNone() {
assertThatQuery( index.query()
.where( SearchPredicateFactory::matchNone ) )
.hasNoHits();
}

Copy link
Member

Choose a reason for hiding this comment

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

Maybe just add another test with a bool predicate containing one predicate that does match a document, and also the matchNone predicate, to check that the resulting bool predicate won't match anything?

- add matchNone() to DSL
- update documentation to mention new predicate
@marko-bekhta
Copy link
Member Author

haha, well I thought that the links update is not a significant enough change to add, so found this ticket 😄

applied the suggested changes and rebased the branch.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

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.

LGTM. Merging. Thanks again!

@yrodiere yrodiere merged commit edbff0b into hibernate:main Mar 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants