@SuppressWarnings("unchecked")
  private CapedwarfLogQueryResult fetchCapedwarfRequestLogs(CapedwarfLogQuery logQuery) {
    List<CapedwarfRequestLogs> list;
    int resultCount;
    List<String> requestIds = logQuery.getQuery().getRequestIds();
    if (requestIds.isEmpty()) {
      CacheQuery cacheQuery = createRequestLogsQuery(logQuery);
      list = (List<CapedwarfRequestLogs>) (List) cacheQuery.list();
      resultCount = cacheQuery.getResultSize();
    } else {
      list = new ArrayList<>(requestIds.size());
      for (String requestId : requestIds) {
        CapedwarfRequestLogs requestLogs = (CapedwarfRequestLogs) store.get(requestId);
        if (requestLogs != null) {
          list.add(requestLogs);
        }
      }
      resultCount = list.size();
    }
    for (int i = 0; i < list.size(); i++) {
      CapedwarfRequestLogs capedwarfRequestLogs = list.get(i);
      list.set(i, capedwarfRequestLogs.clone());
    }

    return new CapedwarfLogQueryResult(list, resultCount);
  }
예제 #2
0
  public void testPrimitiveAndStringKeys() {
    String key1 = "key1";
    int key2 = 2;
    byte key3 = (byte) 3;
    float key4 = (float) 4;
    long key5 = (long) 5;
    short key6 = (short) 6;
    boolean key7 = true;
    double key8 = (double) 8;
    char key9 = '9';

    cache.put(key1, person1);
    cache.put(key2, person1);
    cache.put(key3, person1);
    cache.put(key4, person1);
    cache.put(key5, person1);
    cache.put(key6, person1);
    cache.put(key7, person1);
    cache.put(key8, person1);
    cache.put(key9, person1);

    // Going to search the 'blurb' field for 'owns'
    Term term = new Term("blurb", "owns");
    CacheQuery cacheQuery = new QueryFactory(cache, qh).getQuery(new TermQuery(term));
    assert cacheQuery.getResultSize() == 9;

    List<Object> found = cacheQuery.list();
    for (int i = 0; i < 9; i++) {
      assert found.get(i).equals(person1);
    }
  }
 private List searchByName(String name, Cache c) {
   SearchManager sm = Search.getSearchManager(c);
   CacheQuery q = sm.getQuery(SEntity.searchByName(name), SEntity.class);
   int resultSize = q.getResultSize();
   List l = q.list();
   assert l.size() == resultSize;
   return q.list();
 }
예제 #4
0
  public void testOverwriteWithNonIndexedValue() {
    final long id = 10;

    cache.put(id, new TestEntity("name1", "surname1", id, "note"));
    CacheQuery q1 = queryByNameField("name1", TestEntity.class);
    assertEquals(1, q1.getResultSize());
    assertEquals(TestEntity.class, q1.list().get(0).getClass());

    Map<Object, Object> map = new HashMap<Object, Object>();
    map.put(id, new NotIndexedType("name2"));
    cache.putAll(map);

    CacheQuery q2 = queryByNameField("name1", TestEntity.class);
    assertEquals(0, q2.getResultSize());

    CacheQuery q3 = queryByNameField("name2", TestEntity.class);
    assertEquals(0, q3.getResultSize());
  }
 public void simpleIndexTest() throws ParseException {
   cache.put("1", new Person("A Person's Name", "A paragraph containing some text", 75));
   CacheQuery cq = TestQueryHelperFactory.createCacheQuery(cache, "name", "Person");
   assertEquals(1, cq.getResultSize());
   List<Object> l = cq.list();
   assertEquals(1, l.size());
   Person p = (Person) l.get(0);
   assertEquals("A Person's Name", p.getName());
   assertEquals("A paragraph containing some text", p.getBlurb());
   assertEquals(75, p.getAge());
 }
예제 #6
0
  public void testFullTextFilterOnOff() throws Exception {
    prepareTestData();
    queryParser = createQueryParser("blurb");
    Query luceneQuery = queryParser.parse("eats");

    CacheQuery query = Search.getSearchManager(cache1).getQuery(luceneQuery);
    FullTextFilter filter = query.enableFullTextFilter("personFilter");
    filter.setParameter("blurbText", "cheese");

    AssertJUnit.assertEquals(1, query.getResultSize());
    List result = query.list();

    Person person = (Person) result.get(0);
    AssertJUnit.assertEquals("MiniGoat", person.getName());
    AssertJUnit.assertEquals("Eats cheese", person.getBlurb());

    // Disabling the fullTextFilter.
    query.disableFullTextFilter("personFilter");
    AssertJUnit.assertEquals(2, query.getResultSize());
  }
  @Test
  public void testIndexAndQuery() throws Exception {
    SearchManager searchManager = Search.getSearchManager(cache);

    cache.put(123405, new Bond(new Date(System.currentTimeMillis()), 450L));
    assertEfficientIndexingUsed(searchManager.unwrap(SearchIntegrator.class), Bond.class);

    cache.put(123502, new Debenture("GB", 116d));
    assertEfficientIndexingUsed(searchManager.unwrap(SearchIntegrator.class), Debenture.class);

    cache.put(223456, new Bond(new Date(System.currentTimeMillis()), 550L));
    assertEfficientIndexingUsed(searchManager.unwrap(SearchIntegrator.class), Bond.class);

    CacheQuery query = searchManager.getQuery(new MatchAllDocsQuery(), Bond.class, Debenture.class);
    assertEquals(query.list().size(), 3);

    CacheQuery queryBond = searchManager.getQuery(new MatchAllDocsQuery(), Bond.class);
    assertEquals(queryBond.getResultSize(), 2);

    CacheQuery queryDeb = searchManager.getQuery(new MatchAllDocsQuery(), Debenture.class);
    assertEquals(queryDeb.getResultSize(), 1);
  }
예제 #8
0
  public void testCustomKeys() {
    CustomKey key1 = new CustomKey(1, 2, 3);
    CustomKey key2 = new CustomKey(900, 800, 700);
    CustomKey key3 = new CustomKey(1024, 2048, 4096);

    cache.put(key1, person1);
    cache.put(key2, person1);
    cache.put(key3, person1);

    Term term = new Term("blurb", "owns");
    CacheQuery cacheQuery = new QueryFactory(cache, qh).getQuery(new TermQuery(term));
    int i;
    assert (i = cacheQuery.getResultSize()) == 3 : "Expected 3, was " + i;
  }
예제 #9
0
  public void testClear() throws Exception {
    prepareTestData();
    queryParser = createQueryParser("blurb");
    luceneQuery = queryParser.parse("eats");
    cacheQuery = Search.getSearchManager(cache1).getQuery(luceneQuery);

    Query[] queries = new Query[2];
    queries[0] = luceneQuery;

    luceneQuery = queryParser.parse("playing");
    queries[1] = luceneQuery;

    Query luceneQuery = queries[0].combine(queries);
    CacheQuery cacheQuery = Search.getSearchManager(cache1).getQuery(luceneQuery);
    AssertJUnit.assertEquals(3, cacheQuery.getResultSize());

    cache2.clear();

    AssertJUnit.assertEquals(3, cacheQuery.getResultSize());
    cacheQuery = Search.getSearchManager(cache1).getQuery(luceneQuery);

    AssertJUnit.assertEquals(0, cacheQuery.getResultSize());
  }
 private void queryTest() {
   cache.put("jekyll", new TestEntity("Henry", "Jekyll", 1, "dissociate identity disorder"));
   cache.put("hyde", new TestEntity("Edward", "Hyde", 2, "dissociate identity disorder"));
   SearchManager sm = Search.getSearchManager(cache);
   Query query =
       sm.buildQueryBuilderForClass(TestEntity.class)
           .get()
           .keyword()
           .onField("name")
           .matching("Henry")
           .createQuery();
   CacheQuery q = sm.getQuery(query);
   assertEquals(1, q.getResultSize());
   assertEquals(TestEntity.class, q.list().get(0).getClass());
 }
예제 #11
0
  /** Execute Lucene index query. */
  private QueryResponse executeQuery(
      AdvancedCache<byte[], byte[]> cache, SerializationContext serCtx, QueryRequest request) {
    final SearchManager searchManager = Search.getSearchManager(cache);
    final SearchIntegrator searchFactory = searchManager.getSearchFactory();
    final QueryCache queryCache = ComponentRegistryUtils.getQueryCache(cache); // optional component

    LuceneQueryParsingResult parsingResult;
    Query luceneQuery;

    if (queryCache != null) {
      KeyValuePair<String, Class> queryCacheKey =
          new KeyValuePair<String, Class>(request.getJpqlString(), LuceneQueryParsingResult.class);
      parsingResult = queryCache.get(queryCacheKey);
      if (parsingResult == null) {
        parsingResult = parseQuery(cache, serCtx, request.getJpqlString(), searchFactory);
        queryCache.put(queryCacheKey, parsingResult);
      }
    } else {
      parsingResult = parseQuery(cache, serCtx, request.getJpqlString(), searchFactory);
    }

    luceneQuery = parsingResult.getQuery();

    if (!cache.getCacheConfiguration().compatibility().enabled()) {
      // restrict on entity type
      QueryBuilder qb =
          searchFactory.buildQueryBuilder().forEntity(parsingResult.getTargetEntity()).get();
      luceneQuery =
          qb.bool()
              .must(
                  qb.keyword()
                      .onField(TYPE_FIELD_NAME)
                      .ignoreFieldBridge()
                      .ignoreAnalyzer()
                      .matching(parsingResult.getTargetEntityName())
                      .createQuery())
              .must(luceneQuery)
              .createQuery();
    }

    CacheQuery cacheQuery = searchManager.getQuery(luceneQuery, parsingResult.getTargetEntity());

    if (parsingResult.getSort() != null) {
      cacheQuery = cacheQuery.sort(parsingResult.getSort());
    }

    int projSize = 0;
    if (parsingResult.getProjections() != null && !parsingResult.getProjections().isEmpty()) {
      projSize = parsingResult.getProjections().size();
      cacheQuery =
          cacheQuery.projection(parsingResult.getProjections().toArray(new String[projSize]));
    }
    if (request.getStartOffset() > 0) {
      cacheQuery = cacheQuery.firstResult((int) request.getStartOffset());
    }
    if (request.getMaxResults() > 0) {
      cacheQuery = cacheQuery.maxResults(request.getMaxResults());
    }

    List<?> list = cacheQuery.list();
    List<WrappedMessage> results =
        new ArrayList<WrappedMessage>(projSize == 0 ? list.size() : list.size() * projSize);
    for (Object o : list) {
      if (projSize == 0) {
        results.add(new WrappedMessage(o));
      } else {
        Object[] row = (Object[]) o;
        for (int j = 0; j < projSize; j++) {
          results.add(new WrappedMessage(row[j]));
        }
      }
    }

    QueryResponse response = new QueryResponse();
    response.setTotalResults(cacheQuery.getResultSize());
    response.setNumResults(list.size());
    response.setProjectionSize(projSize);
    response.setResults(results);

    return response;
  }
 protected int countIndex() {
   SearchManager searchManager = Search.getSearchManager(cache1);
   CacheQuery q = searchManager.getQuery(new MatchAllDocsQuery(), Transaction.class);
   return q.getResultSize();
 }