Package org.infinispan.query

Examples of org.infinispan.query.SearchManager


      team.setLocation( "Atlanta" );
      team.setName( "ATL team" );

      // persist and index the test object
      cache.put("id", team);
      SearchManager searchManager = Search.getSearchManager(cache);

      // execute several search to show that the right tokenizers were applies
      TermQuery query = new TermQuery( new Term( "description", "D\u00E0scription" ) );
      assertEquals(
            "iso latin filter should work.  � should be a now", 0, searchManager.getQuery( query ).list().size()
      );

      query = new TermQuery( new Term( "description", "is" ) );
      assertEquals(
            "stop word filter should work. is should be removed", 0, searchManager.getQuery( query ).list().size()
      );

      query = new TermQuery( new Term( "description", "dascript" ) );
      assertEquals(
            "snowball stemmer should work. 'dascription' should be stemmed to 'dascript'",
            1,
            searchManager.getQuery( query ).list().size()
      );
   }
View Full Code Here


    * Tests the analyzers defined on {@link Team}.
    *
    * @throws Exception in case the test fails.
    */
   public void testAnalyzers() throws Exception {
      SearchManager search = Search.getSearchManager(cache);

      Analyzer analyzer = search.getSearchFactory().getAnalyzer( "standard_analyzer" );
      String text = "This is just FOOBAR's";
      Token[] tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
      assertTokensEqual( tokens, new String[] { "This", "is", "just", "FOOBAR's" } );

      analyzer = search.getSearchFactory().getAnalyzer( "html_standard_analyzer" );
      text = "This is <b>foo</b><i>bar's</i>";
      tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
      assertTokensEqual( tokens, new String[] { "This", "is", "foobar's" } );

      analyzer = search.getSearchFactory().getAnalyzer( "html_whitespace_analyzer" );
      text = "This is <b>foo</b><i>bar's</i>";
      tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
      assertTokensEqual( tokens, new String[] { "This", "is", "foobar's" } );

      analyzer = search.getSearchFactory().getAnalyzer( "length_analyzer" );
      text = "ab abc abcd abcde abcdef";
      tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
      assertTokensEqual( tokens, new String[] { "abc", "abcd", "abcde" } );

      analyzer = search.getSearchFactory().getAnalyzer( "length_analyzer" );
      text = "ab abc abcd abcde abcdef";
      tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
      assertTokensEqual( tokens, new String[] { "abc", "abcd", "abcde" } );

      analyzer = search.getSearchFactory().getAnalyzer( "porter_analyzer" );
      text = "bikes bikes biking";
      tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
      assertTokensEqual( tokens, new String[] { "bike", "bike", "bike" } );

      analyzer = search.getSearchFactory().getAnalyzer( "word_analyzer" );
      text = "CamelCase";
      tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
      assertTokensEqual( tokens, new String[] { "Camel", "Case" } );

      analyzer = search.getSearchFactory().getAnalyzer( "synonym_analyzer" );
      text = "ipod cosmos";
      tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
      assertTokensEqual( tokens, new String[] { "ipod", "i-pod", "universe", "cosmos" } );

      analyzer = search.getSearchFactory().getAnalyzer( "shingle_analyzer" );
      text = "please divide this sentence into shingles";
      tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
      assertTokensEqual(
            tokens,
            new String[] {
                  "please",
                  "please divide",
                  "divide",
                  "divide this",
                  "this",
                  "this sentence",
                  "sentence",
                  "sentence into",
                  "into",
                  "into shingles",
                  "shingles"
            }
      );

      analyzer = search.getSearchFactory().getAnalyzer( "pattern_analyzer" );
      text = "foo,bar";
      tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
      assertTokensEqual( tokens, new String[] { "foo", "bar" } );

      // CharStreamFactories test
      analyzer = search.getSearchFactory().getAnalyzer( "mapping_char_analyzer" );
      text = "CORA\u00C7\u00C3O DE MEL\u00C3O";
      tokens = AnalyzerUtils.tokensFromAnalysis( analyzer, "name", text );
      assertTokensEqual( tokens, new String[] { "CORACAO", "DE", "MELAO" } );
   }
View Full Code Here

            new DynamicPropertiesEntity()
               .set("name", "JavaOne 2011")
               .set("city", "San Francisco")
               .set("awards", "Duke Award to Arquillian")
               );
      SearchManager qf = Search.getSearchManager(cache);
      QueryBuilder queryBuilder = qf.buildQueryBuilderForClass(DynamicPropertiesEntity.class).get();

      // Searching for a specific entity:
      Query query = queryBuilder
            .phrase()
               .onField("city")
               .sentence("London")
            .createQuery();

      List list = qf.getQuery(query).list();
      assert list.size() == 1;
      DynamicPropertiesEntity result = (DynamicPropertiesEntity) list.get(0);
      assert result.getProperties().get("name").equals("JUDCon London 2011");

      // Search for all of them:
      Query dateQuery = queryBuilder
            .phrase()
               .onField("name")
               .sentence("2011")
            .createQuery();

      list = qf.getQuery(dateQuery).list();
      assert list.size() == 3;

      // Now search for a property define on a single entity only:
      Query awardsQuery = queryBuilder
            .phrase()
               .onField("awards")
               .sentence("Duke")
            .createQuery();

      list = qf.getQuery(awardsQuery).list();
      assert list.size() == 1;
      result = (DynamicPropertiesEntity) list.get(0);
      assert result.getProperties().get("city").equals("San Francisco");
   }
View Full Code Here

      return TestCacheManagerFactory.createCacheManager( cfg );
   }

   @Test
   public void timeoutExceptionIsThrownAndIsProducedByMyFactory() throws Exception {
      SearchManager searchManager = Search.getSearchManager( cache );
      searchManager.setTimeoutExceptionFactory( new MyTimeoutExceptionFactory() );
      Query query = searchManager.buildQueryBuilderForClass( Foo.class ).get()
            .keyword().onField( "bar" ).matching( "1" )
            .createQuery();

      CacheQuery cacheQuery = searchManager.getQuery( query );
      cacheQuery.timeout( 1, TimeUnit.NANOSECONDS );

      try {
         cacheQuery.list();
         fail( "Expected MyTimeoutException" );
View Full Code Here

      cache1 = caches.get(0);
   }

   @Test(expectedExceptions = UnsupportedOperationException.class, expectedExceptionsMessageRegExp = "Clustered queries do not support timeouts yet.")
   public void testClusteredQueryCacheTimeout() throws Exception {
      SearchManager searchManager = Search.getSearchManager(cache1);

      QueryParser queryParser = createQueryParser("bar");

      org.apache.lucene.search.Query luceneQuery = queryParser.parse("fakebar");
      CacheQuery query = searchManager.getClusteredQuery(luceneQuery, Foo.class);
      query.timeout( 1, TimeUnit.NANOSECONDS );
   }
View Full Code Here

      AssertJUnit.assertEquals(1, found.size());
   }

   public void testPutMap() throws Exception {
      prepareTestData();
      SearchManager searchManager = Search.getSearchManager(cache2);
      QueryBuilder queryBuilder = searchManager
            .buildQueryBuilderForClass(Person.class)
            .get();
      Query allQuery = queryBuilder.all().createQuery();
      assert searchManager.getQuery(allQuery, Person.class).list().size() == 3;

      Map<String,Person> allWrites = new HashMap<String,Person>();
      allWrites.put(key1, person1);
      allWrites.put(key2, person2);
      allWrites.put(key3, person3);

      cache2.putAll(allWrites);
      List found = searchManager.getQuery(allQuery, Person.class).list();
      AssertJUnit.assertEquals(3, found.size());

      cache2.putAll(allWrites);
      found = searchManager.getQuery(allQuery, Person.class).list();
      AssertJUnit.assertEquals(3, found.size());
   }
View Full Code Here

   public void testSearchKeyTransformer() throws Exception {
      Cache cache1 = caches().get(0);
      Cache cache2 = caches().get(1);

      SearchManager manager = Search.getSearchManager(cache1);
      SearchManager manager1 = Search.getSearchManager(cache2);
      manager.registerKeyTransformer(CustomKey3.class, CustomKey3Transformer.class);
      manager1.registerKeyTransformer(CustomKey3.class, CustomKey3Transformer.class);

      prepareTestedObjects();

      TransactionManager transactionManager = cache1.getAdvancedCache().getTransactionManager();
View Full Code Here

      ProtobufValueWrapper wrapper2 = new ProtobufValueWrapper(createMarshalledUser("John", "Batman"));

      cache.put(1, wrapper1);   //todo how do we index if the key is a byte array?
      cache.put(2, wrapper2);

      SearchManager sm = Search.getSearchManager(cache);

      SearchFactoryImplementor searchFactory = (SearchFactoryImplementor) sm.getSearchFactory();
      assertNotNull(searchFactory.getIndexManagerHolder().getIndexManager(ProtobufValueWrapper.class.getName()));

      Query luceneQuery = sm.buildQueryBuilderForClass(ProtobufValueWrapper.class)
            .get()
            .keyword()
            .onField("name")
            .ignoreFieldBridge()
            .ignoreAnalyzer()
            .matching("Adrian")
            .createQuery();

      List<Object> list = sm.getQuery(luceneQuery).list();
      assertEquals(1, list.size());

      // an alternative approach ...

      Query luceneQuery2 = searchFactory.buildQueryBuilder().forEntity(ProtobufValueWrapper.class).get()
View Full Code Here

      ProtobufValueWrapper wrapper2 = new ProtobufValueWrapper(createMarshalledUser("John", "Batman"));

      cache.put(1, wrapper1);   //todo how do we index if the key is a byte array?
      cache.put(2, wrapper2);

      SearchManager sm = Search.getSearchManager(cache);

      SearchFactoryImplementor searchFactory = (SearchFactoryImplementor) sm.getSearchFactory();
      assertNotNull(searchFactory.getIndexManagerHolder().getIndexManager(ProtobufValueWrapper.class.getName()));

      Query luceneQuery = sm.buildQueryBuilderForClass(ProtobufValueWrapper.class)
            .get()
            .keyword()
            .onField("name")
            .ignoreFieldBridge()
            .ignoreAnalyzer()
            .matching("Adrian")
            .createQuery();

      List<Object> list = sm.getQuery(luceneQuery).list();
      assertEquals(1, list.size());

      // an alternative approach ...

      Query luceneQuery2 = searchFactory.buildQueryBuilder().forEntity(ProtobufValueWrapper.class).get()
View Full Code Here

                     "Paolo Perrotta",
                     "The Pragmatic Programmers"));

      CountingClassLoader classLoader = new CountingClassLoader();
      AdvancedCache<Object, Object> applicationCache = cache.getAdvancedCache().with(classLoader);
      SearchManager qf = Search.getSearchManager(applicationCache);

      assert classLoader.countInvocations.get() == 0;

      Query query = qf.buildQueryBuilderForClass(Book.class)
         .get()
            .phrase()
               .onField("title")
               .sentence("in action")
            .createQuery();

      List<Object> list = qf.getQuery(query).list();
      assert list.size() == 2;
      int invocationsCount = classLoader.countInvocations.get();
      assert invocationsCount >= 1 : "Received instead " + invocationsCount + " invocations";
   }
View Full Code Here

TOP

Related Classes of org.infinispan.query.SearchManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.