6 Replies Latest reply on Aug 27, 2010 5:46 AM by Thomas Fuller

    Infinispan Query is not working

    Thomas Fuller Newbie

      Hi,

       

      I have integrated the query module with an application I have and it's not working -- the exact problem as well as my setup are described here. Any thoughts on what I'm missing would be very helpful.

       

      The following code is in Groovy and running on the Grails platform.

       

      Thanks,

       

      Tom

       

      ----- Problem -----

       

      I think the problem is in the agent. If I set the @Indexed(index="name") I get the following result:

       

      When I start the application 46 agents are loaded into the cache with guns and 55 with fists only. The query returns 49 hits, which is incorrect, then a null pointer exception is thrown on def found = results.list().

       

      infinispantestapp.QueryAgentsController hits: 49
      errors.GrailsExceptionResolver null
      java.lang.NullPointerException
              at org.infinispan.query.impl.CacheQueryImpl.list(CacheQueryImpl.java:310
      )
              at infinispantestapp.QueryAgentsController$_closure1.doCall(QueryAgentsC
      ontroller.groovy:39)
              at infinispantestapp.QueryAgentsController$_closure1.doCall(QueryAgentsC
      ontroller.groovy)
              at java.lang.Thread.run(Thread.java:619)

       

      Changing the index to "weapon" or leaving it blank results in zero hits being returned.

       

      Keep in mind that searching by using a Lucene query seems to give me the same results:

       

      def term = new Term ("weapon", "gun")

      def termQuery = new TermQuery (term)
      def results = agentCache.query (Agent.class, termQuery)

       

      ----- Setup -----

       

      This is my configuration file:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <infinispan>
          <default>       
              <indexing enabled="true" indexLocalOnly="false" />
          </default>
      </infinispan>

       

      I have query capabilities mixed-in directly on the cache, however the precondition is that the developer sets the queryHelper before any object are loaded into the cache -- this is done in the BootStrap.groovy file as follows:

       

      agentCache.queryHelper = new QueryHelper (agentCache, new Properties (), Agent.class)

       

      The next step is to load the cache with Agents (from the movie The Matrix) -- this is also done in the BootStrap.groovy file as follows:

       

      def gunCtr = 0, fistCtr = 0
         
              for (ctr in 0..100) {
                             
                  String key = "agent $ctr"
                  String name = key
                 
                  def weapon = rand.nextBoolean () ? "gun" : "fist"
                     
                  if ("gun".equals (weapon)) gunCtr++ else fistCtr++
                     
                  def agent = new Agent (name:name, weapon:weapon)
                 
                  agentCache.put (key, agent)
              }

       

      Note that I keep track of the number of agents loaded that have guns or fists only, so I know the number available in the cache.

       

      The agent looks like this:

       

      import org.hibernate.search.annotations.ProvidedId
      import org.hibernate.search.annotations.Indexed

       

      @ProvidedId
      @Indexed(index="name")
      class Agent {
         
          String name
         
          String weapon
         
          String toString () {
              return "name: $name, weapon: $weapon"
          }
      }

       

      I perform the query as follows:

       

      def index = {


              def results = agentCache.query (Agent.class, "weapon", "gun")
             
              println "results: $results"
             
              def hits = results.getResultSize()
             
              log.info ("hits: $hits")
             
              def found = results.list()
             
              def eagerIterator = results.iterator();
             
              eagerIterator.each {
                  log.info ("agent: $it")
              }
          }

       

      Finally, my mixin looks like this:

       

      class QueryCapabilities {
         
          private static final def log = Logger.getInstance(QueryCapabilities.class)
         
          def queryHelper = null
         
          def query (Class clazz, String field, String search) {
             
              log.info ("query: method begins; queryHelper: $queryHelper, clazz: $clazz, field: $field, search: $search")
             
              def queryFactory = new QueryFactory((owner as Cache), queryHelper)
             
              def cacheQuery = queryFactory.getBasicQuery (field, search)
             
              log.info ("query: method ends; cacheQuery: $cacheQuery")
             
              return cacheQuery
          }
         
          def query (Class clazz, Query query) {
             
              log.info ("query: method begins; queryHelper: $queryHelper, clazz: $clazz, query: $query")
             
              def queryFactory = new QueryFactory((owner as Cache), queryHelper)
             
              def cacheQuery = queryFactory.getQuery (query)
             
              log.info ("query: method ends; cacheQuery: $cacheQuery")
             
              return cacheQuery
          }
      }

       

      The following jars are included in my project:

       

      Infinispan 4.1.0.CR3 (Radegast)

       

          * infinispan-core.jar
          * jboss-common-core-2.2.14.GA.jar
          * jgroups-2.10.0.GA.jar
          * marshalling-api-1.2.2.GA.jar
          * river-1.2.2.GA.jar

       

      Infinispan Query Module

       

          * hibernate-commons-annotations-3.2.0.Final.jar
          * hibernate-search-3.2.1.Final.jar
          * infinispan-query.jar
          * lucene-analyzers-2.9.3.jar
          * lucene-core-2.9.3.jar

       

      Hibernate Infinispan version 3.5.0-Final

       

          * hibernate-infinispan-3.5.0-Final.jar

        • 1. Re: Infinispan Query is not working
          Manik Surtani Master

          Have you tried this using a Java example?  I'm pretty sure it should work with Groovy as well, but that hasn't explicitly been tested.  All unit tests on this module pass fine.

          • 2. Re: Infinispan Query is not working
            Savin Seven Newbie

            Dear Thomas,

             

            I think you have missed the annotation "@Field(store = Store.YES)" before your field\attributes.
            That might also be the reason, It couldn't able to store the field values.

             

            Please add something below, in your Agent class as well..

             

            import org.hibernate.search.annotations.Field;
            import org.hibernate.search.annotations.Indexed;
            import org.hibernate.search.annotations.ProvidedId;
            import org.hibernate.search.annotations.Store;


            @Field(store = Store.YES)
            private String name;
            @Field(store = Store.YES)
            private String weapon;

             

            It will resolve your issue.

             

            Please try and let us know, whether it worked for you...

             

            Thanks & Regards,

            Savin

            • 3. Re: Infinispan Query is not working
              Thomas Fuller Newbie

              Hi Manik,

               

              Which example are you talking about?

               

              I've been going off of this:

               

              http://community.jboss.org/wiki/QueryingInfinispan#Sample_code__how_do_I_enable_and_use_the_Query_API

               

              and I've been poking around other resources but am unfamiliar with a working example, which could prove to be quite helpful.

               

              Thanks,

               

              Tom

              • 4. Re: Infinispan Query is not working
                Thomas Fuller Newbie

                Hi Savin,

                 

                Thanks for your response.

                 

                I tried this last night and it didn't seem to work; to be certain, I tried it again just now and here are the results (the "hits" seem to be constant):

                 

                When I add @Indexed (index="weapon") I get the following:

                 

                bootstrap.BootStrap Done. There are 46 agents with guns and 55 with fists only.
                infinispan.QueryCapabilities query: method begins; queryHelper: org.infinispan.query.backend.QueryHelper@44e906, clazz: class infinispantestapp.Agent, field: weapon, search: gun
                infinispantestapp.QueryAgentsController hits: 99
                errors.GrailsExceptionResolver null
                java.lang.NullPointerException
                        at org.infinispan.query.impl.CacheQueryImpl.list(CacheQueryImpl.java:310
                )
                        at infinispantestapp.QueryAgentsController$_closure1.doCall(QueryAgentsC
                ontroller.groovy:35)
                        at infinispantestapp.QueryAgentsController$_closure1.doCall(QueryAgentsC
                ontroller.groovy)
                        at java.lang.Thread.run(Thread.java:619)

                 

                When I add @Indexed (index="name") I get the following:

                 

                bootstrap.BootStrap Done. There are 55 agents with guns and 46 with fists only.
                infinispan.QueryCapabilities query: method begins; queryHelper: org.infinispan.query.backend.QueryHelper@1bee987, clazz: class infinispantestapp.Agent, field: weapon, search: gun
                infinispantestapp.QueryAgentsController hits: 104
                errors.GrailsExceptionResolver null
                java.lang.NullPointerException
                        at org.infinispan.query.impl.CacheQueryImpl.list(CacheQueryImpl.java:310
                )
                        at infinispantestapp.QueryAgentsController$_closure1.doCall(QueryAgentsC
                ontroller.groovy:35)
                        at infinispantestapp.QueryAgentsController$_closure1.doCall(QueryAgentsC
                ontroller.groovy)
                        at java.lang.Thread.run(Thread.java:619)

                 

                When I add @Indexed only I get zero hits:

                 

                infinispan.QueryCapabilities query: method ends; cacheQuery: org.infinispan.quer
                y.impl.CacheQueryImpl@13ddbdd
                results: org.infinispan.query.impl.CacheQueryImpl@13ddbdd
                infinispantestapp.QueryAgentsController hits: 0

                 

                ----- My agent looks like this at the moment -----

                 

                package infinispantestapp

                 

                import org.hibernate.search.annotations.ProvidedId
                import org.hibernate.search.annotations.Indexed
                import org.hibernate.search.annotations.Field;
                import org.hibernate.search.annotations.Store;

                 

                @ProvidedId
                @Indexed(index="weapon")
                class Agent {
                   
                    @Field(store = Store.YES)
                    private String name
                   
                    @Field(store = Store.YES)
                    private String weapon
                   
                    String toString () {
                        return "name: $name, weapon: $weapon"
                    }
                }

                • 5. Re: Infinispan Query is not working
                  Thomas Fuller Newbie

                  I have downloaded the Radegast source code and copied and then slightly modified the DeclarativeConfigTest unit test and think I see what the problem is. I'll need to verify this however and will post my findings as soon as I have something. Of course, the suspicion is that this is on my end.

                   

                  Tom

                  • 6. Re: Infinispan Query is not working
                    Thomas Fuller Newbie

                    The bug was definitely on my end.

                     

                    On a positive note, I can confirm that query functionality is working in Grails & Groovy; I'm planning to have another release later in the week.

                     

                    Tom