Skip to content

DATAMONGO-1245 - Add support for Query By Example. #341

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

Closed
wants to merge 14 commits into from

Conversation

christophstrobl
Copy link
Member

We now support querying documents by providing a sample of the given object holding compare values.

Example<Person> example = newExampleOf(new Person("dAVe", "Matth"))
    .ignoreNullValues()
    .matchStringsStartingWith()
    .matchStringsWithIgnoreCase()
    .get();

Page<Person> page = repository.findAllByExample(example, new PageRequest(0, 10));

For the sake of partial matching we flatten out nested structures (depending on the configured NullHandler) so we can create different queries for matching like:

{ _id : 1, nested : { value : "conflux" } }
{ _id : 1, nested.value : { "conflux" } }

This is useful when you want so search using a only partially filled nested document.

Usage of StringMatcher allows usage of $regex operator.
DBRefs and geo structures such as Point or GeoJsonPoint are converted to their according structure.


Requires: spring-projects/spring-data-commons#153 (DATACMNS-810)

christophstrobl and others added 7 commits January 28, 2016 13:37
!!! ATTENTION !!!

This is just an explorative approach to QBE trying find possibilities and limitations.
Since o.s.d.domain.Example needs to be in spring-data-commons one has to run the build with bundlor disabled '-Dbundlor.enabled=false'.

!!! ATTENTION !!!

We now support querying documents by providing a sample of the given object holding compare values.

For the sake of partial matching we flatten out nested structures so we can create different queries for matching like:
{ _id : 1, nested : { value : "conflux" } }
{ _id : 1, nested.value : { "conflux" } }

This is useful when you want so search using a only partially filled nested document.

String matching can be configured to wrap strings with $regex which creates { firstname : { $regex : "^foo", $options: "i" } } when using StringMatchMode.STARTING along with the ignoreCaseOption.

DBRefs and geo structures such as Point or GeoJsonPoint is converted to their according structure.
Rename methods on Example and introduce PropertySpecifiers.
Move mapping to separate class.
Introduced MongoRegexCreator.
Added some javadoc.

Still need to do reference documentation.
@mp911de
Copy link
Member

mp911de commented Feb 23, 2016

@gregturn Can you have a look on the docs pls?

* Query predicates are combined using the `AND` keyword
* No support for nested/grouped property constraints like `firstname = ?0 or (firstname = ?1 and lastname = ?2)`
* Limited to starts/contains/ends/regex matching for strings and exact matching for other property types

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of repeating "Limited to...", say "Only supports..."

Adopt changes from query by example API refactoring.

Related ticket: DATACMNS-810.
@mp911de mp911de force-pushed the issue/DATAMONGO-1245 branch from 1fd87ed to 34a58e0 Compare February 26, 2016 14:04
@mp911de mp911de force-pushed the issue/DATAMONGO-1245 branch from 34a58e0 to 1692268 Compare February 29, 2016 08:49
@mp911de mp911de force-pushed the issue/DATAMONGO-1245 branch from 1f6f0d2 to 333ef65 Compare March 1, 2016 10:33
@mp911de mp911de force-pushed the issue/DATAMONGO-1245 branch from 333ef65 to 6be07ad Compare March 1, 2016 10:37
@@ -254,8 +261,8 @@ protected DBObject getMappedKeyword(Field property, Keyword keyword) {
boolean needsAssociationConversion = property.isAssociation() && !keyword.isExists();
Object value = keyword.getValue();

Object convertedValue = needsAssociationConversion ? convertAssociation(value, property)
Copy link
Member

Choose a reason for hiding this comment

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

Seems to be formatting only.

@mp911de mp911de force-pushed the issue/DATAMONGO-1245 branch from 798d153 to c9b6344 Compare March 1, 2016 16:29
odrotbohm pushed a commit that referenced this pull request Mar 17, 2016
An explorative approach to QBE trying find possibilities and limitations. We now support querying documents by providing a sample of the given object holding compare values. For the sake of partial matching we flatten out nested structures so we can create different queries for matching like:

{ _id : 1, nested : { value : "conflux" } }
{ _id : 1, nested.value : { "conflux" } }

This is useful when you want so search using a only partially filled nested document. String matching can be configured to wrap strings with $regex which creates { firstname : { $regex : "^foo", $options: "i" } } when using StringMatchMode.STARTING along with the ignoreCaseOption. DBRefs and geo structures such as Point or GeoJsonPoint is converted to their according structure.

Related tickets: DATACMNS-810.
Original pull request: #341.
odrotbohm pushed a commit that referenced this pull request Mar 17, 2016
Adopt changes from query by example API refactoring.

Related tickets: DATACMNS-810.
Original pull request: #341.
odrotbohm added a commit that referenced this pull request Mar 17, 2016
Adapt to API changes in Spring Data Commons.

Related tickets: DATACMNS-810.
Original pull request: #341.
@odrotbohm odrotbohm closed this Mar 17, 2016
@odrotbohm odrotbohm deleted the issue/DATAMONGO-1245 branch March 17, 2016 17:39
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.

4 participants