1

I am currently trying to utilize Querydsl in order to work with:

  1. Multiple Search Parameters
  2. Work with a direct match for a field
  3. Work in a contains fashion
  4. Utilize wildcards in the input string

How do I need to set my bindings to work like this? Is it even possible? Can I only have one or two of the above?

Our current setup utilizes the like binding (see below code). I have come across a lot of different things, some suggesting using multibinding but I don't believe that is the correct implementation of this (although it could be and I just don't understand the multibinding concept).

I am thinking that there could be something to do with the .first method utilized below.

@Override
default void customize(QuerydslBindings bindings, QApp root) {
    bindings.bind(root.name).first(StringExpression::like);
    bindings.bind(root.number).first(StringExpression::like);        
    bindings.bind(String.class).first((SingleValueBinding<StringPath, String>) StringExpression::containsIgnoreCase);
}

The wildcard functionality for a contains purpose is not working correctly. Input values in the url look something like: /user?name=%mora% and work very sporadically with different inputs. For instance something like /user?name=%ing% works and returns the proper result set of 2 records but /user?name=%ca% returns an empty result set, even though there is at least one record that fits that search criteria.

What we would like to have happen is all of these things work:

/user?name=Bob (returns all records that have the name Bob)
/user (returns all user records)
/user?name=%bo% (returns all records that have bo in the name field)
/user?name=Bob&number=53 (returns the record(s) with this name and number)
theshad83
  • 11
  • 3

1 Answers1

1

Try this:

    @Override
    default void customize(QuerydslBindings bindings, QPerson person) {
        bindings.bind(String.class).first((SingleValueBinding<StringPath, String>) StringExpression::containsIgnoreCase);
    }

It makes case-insensitive 'like' filter for all string properties.

More info is here

Cepr0
  • 28,144
  • 8
  • 75
  • 101