0

I have an Indexed enum with multiple values Active, Pending, Pulled. I was to devise a query that will get only Active and Pulled, but not Pending.

junction = junction.must(
                    qb.keyword().onField("itemStatus").ignoreFieldBridge()
                            .matching("active pulled").createQuery());

the query above is my first stab at it, but this doesn't return anything unless I change the query to only active or change the junction to a should. I basically want a must with an and condition...

1 Answer 1

1

You will need to separate the two queries for the different matching status:

Query itemStatusQuery = queryBuilder
    .bool()             
        .should(queryBuilder.keyword().onField("itemStatus").matching("active").createQuery())
        .should(queryBuilder.keyword().onField("itemStatus").matching("pulled").createQuery())
    .createQuery();

 junction = junction.must(itemStatusQuery);

Alternatively you might be able to use a must().not(). See also http://docs.jboss.org/hibernate/search/5.1/reference/en-US/html_single/#_combining_queries

Sign up to request clarification or add additional context in comments.

1 Comment

I tried this but I have a third criteria that is in it that is a must. so what ends up happening is the should in the itemStatus statements work but the query also returns all items that match the third criteria which returns pending items, but I don't want pending items. The selection is variable too.. sometimes I want active, pending, or sometimes just pending. It depends on what the user selected.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.