1 Reply Latest reply on Feb 18, 2010 8:38 AM by manik

    [infinispan-dev] Querying Infinispan -- Not fetching

      Hi,

      I am able to load data in cache and display. When I try to query, I am getting an empty list.
      Following is the code snippet. Please let me know what I am doing wrong.

      ---------------------
      TestRecord.java----------------
      @ProvidedId(bridge = @FieldBridge(impl = StringBridge.class))
      @Indexed(index = "testRecord")
      public class TestRecord implements Serializable {

      //    @Field(store = Store.YES)
          private Date today = new java.util.Date();
      //    @Field(store = Store.YES)
          private Timestamp time = new Timestamp(today.getTime());
          @Field(store = Store.YES)
           private String type;
          @Field(store = Store.YES)
          private String eventType;
          @Field(store = Store.YES)
          private int loggingLevel;
          @Field(store = Store.YES)
          private String message;
      //    @Field(store = Store.YES)
          private String logTime = time.toString();

      ...// getters and setters
      }

      -----TestQuery.java----------
      cache = cacheMgr.getCache();
      QueryHelper qh = new QueryHelper(cache, new Properties(), TestRecord.class);
      QueryFactory qf = new QueryFactory(cache, qh);
      CacheQuery cq = qf.getBasicQuery("message", searchText);
      auditLogRecordList = cq.list();
      int hits = cq.getResultSize();
      log.info("hits= "+ hits);
      --------------------------------------------

      The hits is appearing empty.

      Regards,
      Vidya
        • 1. Re: [infinispan-dev] Querying Infinispan -- Not fetching
          manik

          Note that you need to create and get the QueryFactory before you put anything into the cache, otherwise all of the earlier puts will not get indexed.

           

          E.g.,

           

          cache = cacheMgr.getCache();
          QueryHelper qh = new QueryHelper(cache, new Properties(), TestRecord.class);
          QueryFactory qf = new QueryFactory(cache, qh);
          
          cache.put(key, value); // repeat this multiple times.
          
          // NOW try your query.
          CacheQuery cq = qf.getBasicQuery("message", searchText);
          auditLogRecordList = cq.list();
          int hits = cq.getResultSize();
          

           

          As a general rule, if you intend to query stuff in the cache, you should create the QueryHelper and QueryFactory as soon as you create the cache, and before you use the cache for anything.