Search code examples
javaspringquerydsl

QueryDSL case insensitive filter in array


Consider the following Java class:

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.List;

@Document(collection = "Doc")
public class Doc {

    @Id
    private String id;

    private List<String> tags;
}

I have generated a query type QDoc for it because I want to easily filter by case insensitive tag names.

/**
 * QDoc is a Querydsl query type for Doc
 */
@Generated("com.querydsl.codegen.EntitySerializer")
public class QDoc extends EntityPathBase<Doc> {

    private static final long serialVersionUID = 602371596L;

    private static final PathInits INITS = PathInits.DIRECT2;

    public static final QDoc doc = new QDoc("doc");

    public final StringPath id = createString("id");

    public final ListPath<String, StringPath> tags = this.<String, StringPath>createList("tags", String.class, StringPath.class, PathInits.DIRECT2);

   ...
}

Currently, I accomplish the case sensitive filtering with the following lines of code:

QDoc qDoc = QDoc.doc;
BooleanBuilder where = new BooleanBuilder();
where.and(qDoc.tags.contains("Tag name to filter for"));

How is the case insensitive filtering done for a ListPath<String, StringPath> ?

Best,

Philipp


Solution

  • You can check case insensitive data via any() method as follows:

    QDoc qDoc = QDoc.doc;
    BooleanBuilder where = new BooleanBuilder();
    where.and(qDoc.tags.any().equalsIgnoreCase("Tag name to filter for"));
    

    It works for me.