2 Replies Latest reply on Jun 16, 2015 2:28 AM by smoers

    Index problem object not found after change

    smoers

      Hello,

       

      I have created a cache with 500 objects. When I send a search on object content everything works correctly, the object is found.

      If I read a specific object into the cache and that I change the value of one parameter of this one, then I refill this one into the cache. This new value can not be use to retrieve the specific object.

       

      Can you indicate to the correct method ?

       

      Many thanks,

      Serge

       

      import java.lang.annotation.ElementType;
      import java.util.Hashtable;
      import java.util.Properties;
      import java.util.UUID;
      import java.util.Map.Entry;
      import org.apache.lucene.search.Query;
      import org.hibernate.search.Environment;
      import org.hibernate.search.cfg.SearchMapping;
      import org.hibernate.search.query.dsl.QueryBuilder;
      import org.infinispan.Cache;
      import org.infinispan.configuration.cache.Configuration;
      import org.infinispan.configuration.cache.ConfigurationBuilder;
      import org.infinispan.manager.DefaultCacheManager;
      import org.infinispan.manager.EmbeddedCacheManager;
      import org.infinispan.query.CacheQuery;
      import org.infinispan.query.ResultIterator;
      import org.infinispan.query.SearchManager;
      import org.infinispan.query.Search;
      
      public class Inf_14 {
      
      
        public static void main(String[] args) {
        // TODO Auto-generated method stub
      
        EmbeddedCacheManager manager = new DefaultCacheManager();
        ConfigurationBuilder cb = new ConfigurationBuilder();
        SearchMapping mapping = new SearchMapping();
      
        mapping.entity(AuthorInfinispan.class).indexed().providedId()
        .property("lastname", ElementType.METHOD)
        .property("firstname", ElementType.METHOD)
        .property("authoralias", ElementType.METHOD);
      
      
      
        mapping.entity(CycleInfinispan.class).indexed().providedId()
        .property("cycletitle", ElementType.METHOD);
      
        mapping.entity(BookInfinispan.class).indexed().providedId()
        .property("title", ElementType.METHOD)
        .property("style", ElementType.METHOD);
      
        Properties properties = new Properties();
        properties.put(Environment.MODEL_MAPPING, mapping);
        //properties.put("hibernate.search.default.directory_provide", "filesystem");
        //properties.put("hibernate.search.default.indexBase", "D:/infinispan/Indexes/");
      
        Configuration c = cb
        .indexing()
        .enable()
        .indexLocalOnly(true)
        .withProperties(properties)
        .persistence()
        .passivation(false)
        .addSingleFileStore()
        .preload(true)
        .shared(false)
        .fetchPersistentState(true)
        .ignoreModifications(false)
        .purgeOnStartup(false)
        .location("D:/infinispan")
        .build();
      
        manager.defineConfiguration("book012015", c);
      
        Cache<UUID, IAuthor> cache = manager.getCache("book012015"); 
      
        SearchManager sm = Search.getSearchManager(cache);
      
        IAuthor authorch = cache.get(UUID.fromString("09586ce5-5763-471d-bbca-30b7cf78712e"));
        authorch.setFirstName("TEST");
        cache.put(authorch.getID(), authorch);
        sm.getMassIndexer().start();
      
        QueryBuilder qb = sm.buildQueryBuilderForClass(AuthorInfinispan.class).get();
        Query q = qb.keyword().wildcard().onField("firstname").matching("TEST*").createQuery();
        CacheQuery cq = sm.getQuery(q, AuthorInfinispan.class);
        System.out.println(cq.getResultSize());
      
      
        ResultIterator it = cq.iterator();
        while(it.hasNext()){
      
        IAuthor author = (IAuthor) it.next();
        System.out.println("Key : " + author.getID());
        System.out.println("Author : " + author.getFirstName() + " " + author.getLastName());
        System.out.println("Date de création : " + author.getCreationDate());
        System.out.println("Nbr de Cycle : " + author.getListCycle().size());
        System.out.println("Site Web : " + author.getWebSite());
        System.out.println("Born Date : " + author.getBornDate());
      
        Hashtable<UUID, ICycle> listcycle = author.getListCycle();
        for(Entry<UUID, ICycle> entrycycle : listcycle.entrySet()){
        ICycle cycle = entrycycle.getValue();
        System.out.println("--Cycle : " + cycle.getCycleTitle());
      
        Hashtable<UUID, IBook> listbook = cycle.getListBook();
        for(Entry<UUID, IBook> entrybook : listbook.entrySet()){
        IBook book = entrybook.getValue();
        System.out.println("----Book : " + book.getTitle());
        }
      
        }
      
      
        System.out.println("-------------------------------------------------------------------");
      
        }
      
      
        it.close();
        cache.stop();
        manager.stop();
      
      
        }
      
      
      }
      

       

      juin 09, 2015 1:26:47 PM org.infinispan.factories.GlobalComponentRegistry start

      INFO: ISPN000128: Infinispan version: Infinispan 'Infinium' 6.0.0.Final

      juin 09, 2015 1:26:49 PM org.infinispan.query.impl.LifecycleManager cacheStarting

      INFO: ISPN014003: Registering Query interceptor

      juin 09, 2015 1:26:49 PM org.hibernate.search.Version <clinit>

      INFO: HSEARCH000034: Hibernate Search 4.4.0.Final

      juin 09, 2015 1:26:49 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>

      INFO: HCANN000001: Hibernate Commons Annotations {4.0.4.Final}

      juin 09, 2015 1:26:49 PM org.hibernate.search.impl.ConfigContext getLuceneMatchVersion

      WARN: HSEARCH000075: Configuration setting hibernate.search.lucene_version was not specified, using LUCENE_CURRENT.

      juin 09, 2015 1:26:51 PM org.infinispan.transaction.lookup.GenericTransactionManagerLookup useDummyTM

      WARN: ISPN000104: Falling back to DummyTransactionManager from Infinispan

      juin 09, 2015 1:26:51 PM org.infinispan.jmx.CacheJmxRegistration start

      INFO: ISPN000031: MBeans were successfully registered to the platform MBean server.

      juin 09, 2015 1:26:51 PM org.infinispan.jmx.CacheJmxRegistration start

      INFO: ISPN000031: MBeans were successfully registered to the platform MBean server.

      juin 09, 2015 1:26:53 PM org.infinispan.query.impl.massindex.DefaultMassIndexerProgressMonitor printStatusMessage

      INFO: HSEARCH000030: 50 documents indexed in 33 ms

      juin 09, 2015 1:26:53 PM org.infinispan.query.impl.massindex.DefaultMassIndexerProgressMonitor printStatusMessage

      INFO: HSEARCH000030: 100 documents indexed in 51 ms

      juin 09, 2015 1:26:53 PM org.infinispan.query.impl.massindex.DefaultMassIndexerProgressMonitor printStatusMessage

      INFO: HSEARCH000030: 150 documents indexed in 67 ms

      juin 09, 2015 1:26:53 PM org.infinispan.query.impl.massindex.DefaultMassIndexerProgressMonitor printStatusMessage

      INFO: HSEARCH000030: 200 documents indexed in 80 ms

      juin 09, 2015 1:26:53 PM org.infinispan.query.impl.massindex.DefaultMassIndexerProgressMonitor printStatusMessage

      INFO: HSEARCH000030: 250 documents indexed in 91 ms

      juin 09, 2015 1:26:53 PM org.infinispan.query.impl.massindex.DefaultMassIndexerProgressMonitor printStatusMessage

      INFO: HSEARCH000030: 300 documents indexed in 104 ms

      juin 09, 2015 1:26:53 PM org.infinispan.query.impl.massindex.DefaultMassIndexerProgressMonitor printStatusMessage

      INFO: HSEARCH000030: 350 documents indexed in 114 ms

      juin 09, 2015 1:26:53 PM org.infinispan.query.impl.massindex.DefaultMassIndexerProgressMonitor printStatusMessage

      INFO: HSEARCH000030: 400 documents indexed in 125 ms

      juin 09, 2015 1:26:53 PM org.infinispan.query.impl.massindex.DefaultMassIndexerProgressMonitor printStatusMessage

      INFO: HSEARCH000030: 450 documents indexed in 143 ms

      juin 09, 2015 1:26:54 PM org.infinispan.query.impl.massindex.DefaultMassIndexerProgressMonitor printStatusMessage

      INFO: HSEARCH000030: 500 documents indexed in 168 ms

      Result

        • 1. Re: Index problem object not found after change
          gustavonalle

          Hi,

           

          your mapping configuration is not specifying any fields to be indexed, you should do something like:

           

          mapping.entity(AuthorInfinispan.class).indexed().providedId()

          .property("firstname", ElementType.METHOD)

                    .field()

          more details on [1].

           

          You should also specify the analyzers to be used with the field, that will affect directly the query matching. For example, if you simply use the suggested configuration above (default analyzer), a entity with firstname="TEST" will

          be saved into the index as a lucene document having firstname="test", since the default analyzer does lowercasing, breaking on whitespaces and removal of punctuation. Thus the query

           

          qb.keyword().wildcard().onField("firstname").matching("TEST*").createQuery();

           

          will not bring any results, but "test", "tes*", "t*" will.

           

          Also, you should not call the MassIndexer after changing an entity to be able to see the changes, since it will re-index your whole cache. Simply doing a put is enough to have only that single entity reindexed.

           

           

          [1] Hibernate Search

          • 2. Re: Index problem object not found after change
            smoers

            Hi Gustavo,

             

            It's working perfectly !

             

             

            Many thanks,