5 Replies Latest reply on Jan 22, 2015 9:35 AM by Adrian Nistor

    Query DSL: Struggling with filtering operator 'contains'

    Tobias Herrmann Newbie

      I have cached objects with a multivalued field like the following:

       

      @Indexed

      class Resource{

         @Field(analyze = Analyze.NO)

          private List<String> categories;

          ....

      }

       

      I want to search for all resources where the list categories contains a specific value.

       

      Currently I am trying it like this:

       

      QueryFactory factory=Search.getSearchManager(cache);

      Query query=queryFactory.from(Resource.class).having("categories").contains("foo").toBuilder().build();

      List<Resource> result=query.list();

       

      This results in the following exception:

      org.hibernate.search.bridge.BridgeException: Exception while calling bridge#set

        class: Resource

        path: categories

       

      What am I doing wrong. Do I need to special annotations for the categories field?

       

      Thanks in advance, Tobias

        • 1. Re: Query DSL: Struggling with filtering operator 'contains'
          Adrian Nistor Newbie

          Hi Tobias,

          A full stacktrace would help us find out the cause.

           

          Thanks!

          • 2. Re: Query DSL: Struggling with filtering operator 'contains'
            Tobias Herrmann Newbie

            I get the following stacktrace:

             

            org.hibernate.search.bridge.BridgeException: Exception while calling bridge#set

              class: Resource

              path: categories

              at org.hibernate.search.bridge.util.impl.ContextualExceptionBridgeHelper.buildBridgeException(ContextualExceptionBridgeHelper.java:84)

              at org.hibernate.search.bridge.util.impl.ContextualExceptionBridgeHelper$OneWayConversionContextImpl.set(ContextualExceptionBridgeHelper.java:113)

              at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.buildDocumentFields(DocumentBuilderIndexedEntity.java:432)

              at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.getDocument(DocumentBuilderIndexedEntity.java:359)

              at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.createUpdateWork(DocumentBuilderIndexedEntity.java:288)

              at org.hibernate.search.engine.spi.DocumentBuilderIndexedEntity.addWorkToQueue(DocumentBuilderIndexedEntity.java:230)

              at org.hibernate.search.engine.impl.WorkPlan$PerEntityWork.enqueueLuceneWork(WorkPlan.java:486)

              at org.hibernate.search.engine.impl.WorkPlan$PerClassWork.enqueueLuceneWork(WorkPlan.java:261)

              at org.hibernate.search.engine.impl.WorkPlan.getPlannedLuceneWork(WorkPlan.java:147)

              at org.hibernate.search.backend.impl.WorkQueue.prepareWorkPlan(WorkQueue.java:114)

              at org.hibernate.search.backend.impl.BatchedQueueingProcessor.prepareWorks(BatchedQueueingProcessor.java:56)

              at org.hibernate.search.backend.impl.TransactionalWorker.performWork(TransactionalWorker.java:85)

              at org.infinispan.query.backend.QueryInterceptor.performSearchWorks(QueryInterceptor.java:235)

              at org.infinispan.query.backend.QueryInterceptor.performSearchWork(QueryInterceptor.java:229)

              at org.infinispan.query.backend.QueryInterceptor.updateIndexes(QueryInterceptor.java:223)

              at org.infinispan.query.backend.QueryInterceptor.processPutKeyValueCommand(QueryInterceptor.java:446)

              at org.infinispan.query.backend.QueryInterceptor.visitPutKeyValueCommand(QueryInterceptor.java:164)

              at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:71)

              at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:98)

              at org.infinispan.interceptors.locking.AbstractLockingInterceptor.visitPutKeyValueCommand(AbstractLockingInterceptor.java:48)

              at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:71)

              at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:98)

              at org.infinispan.interceptors.base.CommandInterceptor.handleDefault(CommandInterceptor.java:112)

              at org.infinispan.commands.AbstractVisitor.visitPutKeyValueCommand(AbstractVisitor.java:35)

              at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:71)

              at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:98)

              at org.infinispan.interceptors.CacheMgmtInterceptor.updateStoreStatistics(CacheMgmtInterceptor.java:159)

              at org.infinispan.interceptors.CacheMgmtInterceptor.visitPutKeyValueCommand(CacheMgmtInterceptor.java:145)

              at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:71)

              at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:98)

              at org.infinispan.interceptors.InvocationContextInterceptor.handleAll(InvocationContextInterceptor.java:102)

              at org.infinispan.interceptors.InvocationContextInterceptor.handleDefault(InvocationContextInterceptor.java:71)

              at org.infinispan.commands.AbstractVisitor.visitPutKeyValueCommand(AbstractVisitor.java:35)

              at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:71)

              at org.infinispan.interceptors.InterceptorChain.invoke(InterceptorChain.java:333)

              at org.infinispan.cache.impl.CacheImpl.executeCommandAndCommitIfNeeded(CacheImpl.java:1578)

              at org.infinispan.cache.impl.CacheImpl.putInternal(CacheImpl.java:1056)

              at org.infinispan.cache.impl.CacheImpl.put(CacheImpl.java:1048)

              at org.infinispan.cache.impl.CacheImpl.put(CacheImpl.java:1649)

              at org.infinispan.cache.impl.CacheImpl.put(CacheImpl.java:246)

              at TestClass.writeResource(TestClass.java:183)

              Caused by: java.lang.ClassCastException: java.util.Collections$EmptyList cannot be cast to java.lang.String

              at org.hibernate.search.bridge.builtin.StringBridge.objectToString(StringBridge.java:27)

              at org.hibernate.search.bridge.builtin.impl.String2FieldBridgeAdaptor.set(String2FieldBridgeAdaptor.java:31)

              at org.hibernate.search.bridge.util.impl.ContextualExceptionBridgeHelper$OneWayConversionContextImpl.set(ContextualExceptionBridgeHelper.java:110)

              ... 80 more

            • 3. Re: Query DSL: Struggling with filtering operator 'contains'
              Adrian Nistor Newbie

              Hi Tobias,

               

              just add @FieldBridge(impl = BuiltinIterableBridge.class) to your 'categories' field and the error will disappear. The query will work too

               

              Adrian

              • 4. Re: Query DSL: Struggling with filtering operator 'contains'
                Tobias Herrmann Newbie

                Thanks, that helped. Do you know where to find a good documentation of these annotations? I googled quite a bit before posting here, but didn't find anything.

                 

                Regards, Tobias

                • 5. Re: Query DSL: Struggling with filtering operator 'contains'
                  Adrian Nistor Newbie

                  These are documented in the Hibernate Search Reference guide (Hibernate Search) but this particular one does not seem to be. Besides their user guide I find their unit tests to be very useful.