Examples of ILuceneClient


Examples of net.sf.katta.lib.lucene.ILuceneClient

  }

  @Test
  public void testSearch() throws Exception {
    deploy3Indices();
    ILuceneClient client = new LuceneClient(_miniCluster.getZkConfiguration());
    final Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("foo: bar");
    final Hits hits = client.search(query, new String[] { INDEX3, INDEX2 });
    assertNotNull(hits);
    for (final Hit hit : hits.getHits()) {
      writeToLog(hit);
    }
    assertEquals(8, hits.size());
    assertEquals(8, hits.getHits().size());
    client.close();
  }
View Full Code Here

Examples of net.sf.katta.lib.lucene.ILuceneClient

    IndexState indexState = deployClient.addIndex(indexName, sortIndex1.getParentFile().getAbsolutePath(), 1)
            .joinDeployment();
    assertEquals(IndexState.DEPLOYED, indexState);

    // query and compare results
    ILuceneClient client = new LuceneClient(_miniCluster.getZkConfiguration());
    Sort sort = new Sort(new SortField[] { new SortField("timesort", SortField.LONG) });

    // query both documents
    Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("text:ab*");
    Hits hits = client.search(query, new String[] { indexName }, 20, sort);
    assertEquals(2, hits.size());

    // query only one document
    query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("text:abc2");
    hits = client.search(query, new String[] { indexName }, 20, sort);
    assertEquals(1, hits.size());

    // query only one document on one node
    _miniCluster.shutdownNode(0);
    TestUtil.waitUntilIndexBalanced(_protocol, indexName);
    query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("text:abc2");
    hits = client.search(query, new String[] { indexName }, 20, sort);
    assertEquals(1, hits.size());
    client.close();
  }
View Full Code Here

Examples of net.sf.katta.lib.lucene.ILuceneClient

    IndexState indexState = deployClient.addIndex(sortIndex.getName(), sortIndex.getParentFile().getAbsolutePath(), 1)
            .joinDeployment();
    assertEquals(IndexState.DEPLOYED, indexState);

    // query and compare results
    ILuceneClient client = new LuceneClient(_miniCluster.getZkConfiguration());
    final Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse(textFieldName + ": "
            + queryTerm);
    Sort sort = new Sort(new SortField[] { new SortField("sortField", SortField.INT) });
    final Hits hits = client.search(query, new String[] { sortIndex.getName() }, 20, sort);
    assertNotNull(hits);
    List<Hit> hitsList = hits.getHits();
    for (final Hit hit : hitsList) {
      writeToLog(hit);
    }
    assertEquals(9, hits.size());
    assertEquals(9, hitsList.size());
    assertEquals(1, hitsList.get(0).getSortFields().length);
    for (int i = 0; i < hitsList.size() - 1; i++) {
      int compareTo = hitsList.get(i).getSortFields()[0].compareTo(hitsList.get(i + 1).getSortFields()[0]);
      assertTrue("results not after field", compareTo == 0 || compareTo == -1);
    }
    client.close();
  }
View Full Code Here

Examples of net.sf.katta.lib.lucene.ILuceneClient

  }

  @Test
  public void testSearchLimit() throws Exception {
    deploy3Indices();
    ILuceneClient client = new LuceneClient(_miniCluster.getZkConfiguration());
    final Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("foo: bar");
    final Hits hits = client.search(query, new String[] { INDEX3, INDEX2 }, 1);
    assertNotNull(hits);
    for (final Hit hit : hits.getHits()) {
      writeToLog(hit);
    }
    assertEquals(8, hits.size());
    assertEquals(1, hits.getHits().size());
    for (final Hit hit : hits.getHits()) {
      LOG.info(hit.getNode() + " -- " + hit.getScore() + " -- " + hit.getDocId());
    }
    client.close();
  }
View Full Code Here

Examples of net.sf.katta.lib.lucene.ILuceneClient

  @Test
  public void testKatta20SearchLimitMaxNumberOfHits() throws Exception {
    deployTestIndices(1, getNodeCount());
    final Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("foo: bar");
    ILuceneClient client = new LuceneClient(_miniCluster.getZkConfiguration());
    final Hits expectedHits = client.search(query, new String[] { INDEX_NAME }, 4);
    assertNotNull(expectedHits);
    LOG.info("Expected hits:");
    for (final Hit hit : expectedHits.getHits()) {
      writeToLog(hit);
    }
    assertEquals(4, expectedHits.getHits().size());

    for (int i = 0; i < 100; i++) {
      // Now we redo the search, but limit the max number of hits. We expect the
      // same ordering of hits.
      for (int maxHits = 1; maxHits < expectedHits.size() + 1; maxHits++) {
        final Hits hits = client.search(query, new String[] { INDEX_NAME }, maxHits);
        assertNotNull(hits);
        assertEquals(maxHits, hits.getHits().size());
        for (int j = 0; j < hits.getHits().size(); j++) {
          // writeToLog("expected: ", expectedHits.getHits().get(j));
          // writeToLog("actual : ", hits.getHits().get(j));
          assertEquals(expectedHits.getHits().get(j).getScore(), hits.getHits().get(j).getScore(), 0.0);
        }
      }
    }
    client.close();
  }
View Full Code Here

Examples of net.sf.katta.lib.lucene.ILuceneClient

  }

  @Test
  public void testSearchSimiliarity() throws Exception {
    deploy3Indices();
    ILuceneClient client = new LuceneClient(_miniCluster.getZkConfiguration());
    final Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("foo: bar");
    final Hits hits = client.search(query, new String[] { INDEX2 });
    assertNotNull(hits);
    assertEquals(4, hits.getHits().size());
    for (final Hit hit : hits.getHits()) {
      LOG.info(hit.getNode() + " -- " + hit.getScore() + " -- " + hit.getDocId());
    }
    client.close();
  }
View Full Code Here

Examples of net.sf.katta.lib.lucene.ILuceneClient

  }

  @Test
  public void testNonExistentShard() throws Exception {
    final Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("foo: bar");
    ILuceneClient client = new LuceneClient(_miniCluster.getZkConfiguration());
    try {
      client.search(query, new String[] { "doesNotExist" });
      fail("Should have failed.");
    } catch (KattaException e) {
      assertEquals("Index [pattern(s)] '[doesNotExist]' do not match to any deployed index: []", e.getMessage());
    }
    client.close();
  }
View Full Code Here

Examples of net.sf.katta.lib.lucene.ILuceneClient

  }

  @Test
  public void testIndexPattern() throws Exception {
    deploy3Indices();
    ILuceneClient client = new LuceneClient(_miniCluster.getZkConfiguration());
    final Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("foo: bar");
    final Hits hits = client.search(query, new String[] { "index[2-3]+" });
    assertNotNull(hits);
    for (final Hit hit : hits.getHits()) {
      writeToLog(hit);
    }
    assertEquals(8, hits.size());
    assertEquals(8, hits.getHits().size());
    client.close();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.