2 Replies Latest reply on Feb 28, 2013 7:23 PM by jeetu

    Infinispan query - null values in the query results

    jeetu

      Hi,

       

      I have been trying to get the infinispan querying work for my POC. I am using the infinispan 5.1.8.Final for my implementation.

       

      I have an object called QCInventory.java which is indexed and has @providedId annotation.

       

      There are some fields in the pojo which are annotated with @Field and all of them are set to no anlyzing. I dont want to be analyzed as my requirement is to match the values as provided in the input.

       

      I ran some queries by putting 10 QCInventory.java objects in cache with the key as the serviceId ( a field value in QCInventory pojo and is unique for each pojo) and value as the corresponding QCInventory object.

       

      When the query is serviceId:123485 which should match exactly one pojo, the result size of CacheQuery is 1 but when i try to display that match using .list() method, it gives me a null value.

       

      Similarly when the query is enterpriseId:24769 ( all the pojos in cache has the same enterpriseId value), the result size is 10, but when i list them using the .list() method, 7 of them are null values and 3 of them are the pojos.

       

      Need to know why am i getting those null values as part of the .list() method. The QcInventory pojo looks like this.

       

      @Indexed

      @ProvidedId

      public class Qcinventory implements Serializable{

         

         

           /**

           *

           */

          private static final long serialVersionUID = 146546358216584L;

         

          

           @Field(analyze = Analyze.NO) String serviceId;

          

           @Field(analyze = Analyze.NO) String enterpriseId;

      }

       

      I am calling the query like this:

       

                SearchManager sm = Search.getSearchManager(cache);

                QueryBuilder qb = sm.buildQueryBuilderForClass(Qcinventory.class).get();

          

                  Query q = new QueryParser(Version.LUCENE_35, "serviceId", new StandardAnalyzer(Version.LUCENE_35)).parse("serviceId:123485");

                  CacheQuery cq = sm.getQuery(q, Qcinventory.class);

                  //then  loop through the objects from cq.list()

       

      Any kind of suggestion or help will be highly appreciated.

       

      We are evaluating infinispan querying to be used for our inventory searching capabilities. A major decision is pending on the outcome of this POC. So, expecting help as soon as possible.

        • 1. Re: Infinispan query - null values in the query results
          sannegrinovero

          Hi,

          since you need exact matches, you are correct you should not Analyze the field, but you need to not apply the analyzer to the Query too.

          The QueryParser API expects an Analyzer, the easiest solution is to avoid the parser and use a TermQuery

           

          TermQuery q = new TermQuery( new Term( "serviceId", "123485" ) );

          CacheQuery cq = sm.getQuery(q, Qcinventory.class);

          • 2. Re: Infinispan query - null values in the query results
            jeetu

            Thanks Sanne for your response. I resolved it. It was my bad.

             

            The null values were coming becuase those cache entries were no longer in cache, but were available in the index. It was because of my max entries in the cache configuration being kept low. After i have increased them to a considerable amount, i no longer have the issue.

             

            Jithendra