Examples of LuceneClient


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

public class DeployUndeploySearchInLoop {

  private static Logger LOG = Logger.getLogger(DeployUndeploySearchInLoop.class);

  public static void main(String[] args) throws Exception {
    LuceneClient luceneClient = new LuceneClient();
    ZkConfiguration zkConfig = new ZkConfiguration();
    DeployClient deployClient = new DeployClient(ZkKattaUtil.startZkClient(zkConfig, 60000), zkConfig);

    QueryParser parser = new QueryParser(Version.LUCENE_30, "field", new KeywordAnalyzer());
    Query query = parser.parse("foo: b*");

    int runThroughs = 2;
    while (true) {
      try {
        String indexName = "index" + runThroughs;
        LOG.info("deploying index '" + indexName + "'");
        deployClient.addIndex(indexName, "/Users/jz/Documents/workspace/ms/katta/src/test/testIndexA", 1)
                .joinDeployment();
      } catch (Exception e) {
        logException("deploy", e);
      }

      try {
        String indexName = "index" + (runThroughs - 1);
        LOG.info("undeploying index '" + indexName + "'");
        deployClient.removeIndex(indexName);
      } catch (Exception e) {
        logException("undeploy", e);
      }

      try {
        Hits search = luceneClient.search(query, new String[] { "*" });
        LOG.info(runThroughs + ": got " + search.size() + " results");
      } catch (Exception e) {
        logException("search", e);
      }
      Thread.sleep(5000);
      runThroughs++;
      LOG.info(luceneClient.getClient().getSelectionPolicy());
    }
  }
View Full Code Here

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

    super(2);
  }

  @Test
  public void testAddRemoveIndices() throws Exception {
    ILuceneClient client = new LuceneClient(_protocol);
    IDeployClient deployClient = new DeployClient(_protocol);

    int listenerCountBeforeDeploys = _protocol.getRegisteredListenerCount();
    deployClient.addIndex("newIndex1", INDEX_FILE.getAbsolutePath(), 1).joinDeployment();
    deployClient.addIndex("newIndex2", INDEX_FILE.getAbsolutePath(), 1).joinDeployment();
    deployClient.addIndex("newIndex3", INDEX_FILE.getAbsolutePath(), 1).joinDeployment();
    final Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("content: the");
    client.search(query, new String[] { "newIndex1" }, 10);

    deployClient.removeIndex("newIndex1");
    deployClient.removeIndex("newIndex2");
    deployClient.removeIndex("newIndex3");
    Thread.sleep(2000);
View Full Code Here

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

    assertEquals(listenerCountBeforeDeploys, _protocol.getRegisteredListenerCount());
  }

  @Test
  public void testInstantiateClientBeforeIndex() throws Exception {
    ILuceneClient client = new LuceneClient(_miniCluster.getZkConfiguration());
    deployTestIndices(1, getNodeCount());
    List<Node> nodes = _miniCluster.getNodes();
    for (Node node : nodes) {
      TestUtil.waitUntilNodeServesShards(_protocol, node.getName(), SHARD_COUNT);
    }
    Thread.sleep(2000);

    final Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("content: the");
    client.count(query, new String[] { INDEX_NAME });
    client.close();
  }
View Full Code Here

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

  }

  @Test
  public void testCount() throws Exception {
    deployTestIndices(1, 1);
    ILuceneClient client = new LuceneClient(_miniCluster.getZkConfiguration());
    final Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("content: the");
    final int count = client.count(query, new String[] { INDEX_NAME });
    assertEquals(937, count);
    client.close();
  }
View Full Code Here

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

  }

  @Test
  public void testGetDetails() throws Exception {
    deployTestIndices(1, 1);
    ILuceneClient client = new LuceneClient(_miniCluster.getZkConfiguration());
    final Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("content: the");
    final Hits hits = client.search(query, new String[] { INDEX_NAME }, 10);
    assertNotNull(hits);
    assertEquals(10, hits.getHits().size());
    for (final Hit hit : hits.getHits()) {
      final MapWritable details = client.getDetails(hit);
      final Set<Writable> keySet = details.keySet();
      assertFalse(keySet.isEmpty());
      assertNotNull(details.get(new Text("path")));
      assertNotNull(details.get(new Text("category")));
    }
    client.close();
  }
View Full Code Here

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

  }

  @Test
  public void testGetDetailsWithFieldNames() throws Exception {
    deployTestIndices(1, 1);
    ILuceneClient client = new LuceneClient(_miniCluster.getZkConfiguration());
    final Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("content: the");
    final Hits hits = client.search(query, new String[] { INDEX_NAME }, 10);
    assertNotNull(hits);
    assertEquals(10, hits.getHits().size());
    for (final Hit hit : hits.getHits()) {
      final MapWritable details = client.getDetails(hit, new String[] { "path" });
      final Set<Writable> keySet = details.keySet();
      assertFalse(keySet.isEmpty());
      assertNotNull(details.get(new Text("path")));
      assertNull(details.get(new Text("category")));
    }
    client.close();
  }
View Full Code Here

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

    DeployClient deployClient = new DeployClient(_miniCluster.getProtocol());
    IndexState indexState = deployClient.addIndex(index.getName(), index.getParentFile().getAbsolutePath(), 1)
            .joinDeployment();
    assertEquals(IndexState.DEPLOYED, indexState);

    ILuceneClient client = new LuceneClient(_miniCluster.getZkConfiguration());
    final Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse(textFieldName + ": "
            + textFieldContent);
    final Hits hits = client.search(query, new String[] { index.getName() }, 10);
    assertNotNull(hits);
    assertEquals(1, hits.getHits().size());
    final Hit hit = hits.getHits().get(0);
    final MapWritable details = client.getDetails(hit);
    final Set<Writable> keySet = details.keySet();
    assertEquals(1, keySet.size());
    final Writable writable = details.get(new Text(binaryFieldName));
    assertNotNull(writable);
    assertThat(writable, instanceOf(BytesWritable.class));
    BytesWritable bytesWritable = (BytesWritable) writable;
    bytesWritable.setCapacity(bytesWritable.getLength());// getBytes() returns
    // the full array
    assertArrayEquals(bytesFieldContent, bytesWritable.getBytes());
    client.close();
  }
View Full Code Here

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

  }

  @Test
  public void testGetDetailsConcurrently() throws KattaException, ParseException, InterruptedException {
    deployTestIndices(1, 1);
    ILuceneClient client = new LuceneClient(_miniCluster.getZkConfiguration());
    final Query query = new QueryParser(Version.LUCENE_30, "", new KeywordAnalyzer()).parse("content: the");
    final Hits hits = client.search(query, new String[] { INDEX_NAME }, 10);
    assertNotNull(hits);
    assertEquals(10, hits.getHits().size());
    List<MapWritable> detailList = client.getDetails(hits.getHits());
    assertEquals(hits.getHits().size(), detailList.size());
    for (int i = 0; i < detailList.size(); i++) {
      final MapWritable details1 = client.getDetails(hits.getHits().get(i));
      final MapWritable details2 = detailList.get(i);
      assertEquals(details1.entrySet(), details2.entrySet());
      final Set<Writable> keySet = details2.keySet();
      assertFalse(keySet.isEmpty());
      final Writable writable = details2.get(new Text("path"));
      assertNotNull(writable);
    }
    client.close();
  }
View Full Code Here

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

  }

  @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.LuceneClient

    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
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.