2 Replies Latest reply on Apr 24, 2014 5:02 PM by Infi User

    infinispan query - assosication

    Infi User Newbie

      class Book {

      private String title;

      private Set<Author> authors;

      }

      class Author {

           private String firstName;

           private String lastName;

      }

       

      Let's say I have book with title "super book" with authors "John Right" and "Rober Smith" and query is

       

      queryFactory.from(Book.class).having("authors.firstName").eq("John").and().having("authors.lastName").eq("Smith").toBuilder();

       

      this Query is returning book with title "super book" , where as this book does not have "John Smith" as author, but authors have their one of the name matching.

       

      how to fix this query not to return objects like this.

       

      Thanks

        • 1. Re: infinispan query - assosication
          Sanne Grinovero Master

          Hi,

          the Lucene index inherently suffers from the limitation you just described; one way around is to change your model to have either a getter in Author like "getFullName" on which you disable Analyzer (so that it doesn't separate on spaces) or in which you implement it with a keyword separator for example "return firstName + '_' + lastName" and search for the same.

           

          Another common solution is to invert the relation:

           

          class Book {

          private String title;

          }

          class Author {

               private String firstName;

               private String lastName;

               private Book wrote;

          }

          and then target Author for queries.

          1 of 1 people found this helpful
          • 2. Re: infinispan query - assosication
            Infi User Newbie

            Thank you Sanne, This what I thought, but I can't find confirmation in any documentation. Thank a lot.

             

            -Naren