List of usage examples for org.apache.solr.client.solrj SolrQuery SolrQuery
public SolrQuery(String q)
From source file:com.ngdata.hbaseindexer.indexer.IndexerIT.java
License:Apache License
@Test public void testMorphline() throws Exception { createTable("table1", "family1"); HTable table = new HTable(conf, "table1"); StringBuilder indexerConf = new StringBuilder(); indexerConf.append("<indexer table='table1' mapper='" + MorphlineResultToSolrMapper.class.getName() + "'>"); indexerConf.append(" <param name='morphlineFile'" + " value='../hbase-indexer-morphlines/src/test/resources/test-morphlines/extractHBaseCell.conf'/>"); indexerConf.append("</indexer>"); createIndexer1(indexerConf.toString()); SepTestUtil.waitOnReplicationPeerReady(peerId("indexer1")); Put put = new Put(Bytes.toBytes("cry baby")); put.add(b("family1"), b("field1"), Bytes.toBytes(4279)); table.put(put);/*from w w w.ja v a2 s . c o m*/ SepTestUtil.waitOnReplication(conf, 60000L); collection1.commit(); QueryResponse response = collection1.query(new SolrQuery("*:*")); assertEquals(1, response.getResults().size()); SolrDocument doc = response.getResults().get(0); assertEquals("4279", doc.getFirstValue("field1_s")); table.close(); }
From source file:com.ngdata.hbaseindexer.indexer.IndexerIT.java
License:Apache License
@Test public void testMorphlineWithWildcardInputFieldMix() throws Exception { createTable("table1", "family1"); HTable table = new HTable(conf, "table1"); StringBuilder indexerConf = new StringBuilder(); indexerConf.append("<indexer table='table1' mapper='" + MorphlineResultToSolrMapper.class.getName() + "'>"); indexerConf.append(" <param name='morphlineFile'" + " value='../hbase-indexer-morphlines/src/test/resources/test-morphlines/extractHBaseCellWithWildcardInputFieldMix.conf'/>"); indexerConf.append("</indexer>"); createIndexer1(indexerConf.toString()); SepTestUtil.waitOnReplicationPeerReady(peerId("indexer1")); Put put = new Put(Bytes.toBytes("cry baby")); put.add(b("family1"), b("field1"), Bytes.toBytes(4279)); put.add(b("family1"), b("field0"), Bytes.toBytes(1234)); table.put(put);/*from w w w .java 2 s . c om*/ SepTestUtil.waitOnReplication(conf, 60000L); collection1.commit(); QueryResponse response = collection1.query(new SolrQuery("*:*")); assertEquals(1, response.getResults().size()); SolrDocument doc = response.getResults().get(0); assertEquals("4279", doc.getFirstValue("field1_s")); assertEquals(Arrays.asList("1234", "4279"), doc.getFieldValues("field0_ss")); table.close(); }
From source file:com.ngdata.hbaseindexer.indexer.IndexerIT.java
License:Apache License
@Test public void testColumnMappingAndRowAndFamilySolrFields() throws Exception { createTable("table1", "family1"); HTable table = new HTable(conf, "table1"); StringBuilder indexerConf = new StringBuilder(); indexerConf.append("<indexer table='table1'"); indexerConf.append(" unique-key-field='id'"); indexerConf.append(" row-field='row_s'"); indexerConf.append(" column-family-field='family_s'"); indexerConf.append(" mapping-type='column'>"); // one cell can map to a solr doc with multiple fields indexerConf.append(" <field name='cell_s' value='family1:*' type='string'/>"); indexerConf.append(" <field name='cell_qualifier_s' value='family1:*' source='qualifier' type='string'/>"); indexerConf.append("</indexer>"); createIndexer1(indexerConf.toString()); SepTestUtil.waitOnReplicationPeerReady(peerId("indexer1")); Put put = new Put(Bytes.toBytes("the row")); put.add(b("family1"), b("col1"), b("value1")); table.put(put);/*from ww w .jav a2 s . c o m*/ put = new Put(Bytes.toBytes("the row")); put.add(b("family1"), b("col2"), b("value2")); table.put(put); // 2 columns added in one call should still be mapped individually put = new Put(Bytes.toBytes("the row")); put.add(b("family1"), b("col3"), b("value3")); put.add(b("family1"), b("col4"), b("value4")); table.put(put); SepTestUtil.waitOnReplication(conf, 60000L); collection1.commit(); QueryResponse response = collection1.query(new SolrQuery("*:*")); assertEquals(4, response.getResults().size()); response = collection1.query(new SolrQuery("+row_s:\"the row\"")); assertEquals(4, response.getResults().size()); response = collection1.query(new SolrQuery("+row_s:\"the row\" +family_s:family1")); assertEquals(4, response.getResults().size()); for (String col : Lists.newArrayList("col1", "col2", "col3", "col4")) { response = collection1.query(new SolrQuery("+cell_qualifier_s:" + col)); assertEquals(1, response.getResults().size()); } response = collection1.query(new SolrQuery("+cell_s:value1")); assertEquals(1, response.getResults().size()); table.close(); }
From source file:com.ngdata.hbaseindexer.indexer.IndexerIT.java
License:Apache License
/** * This test verifies that when two updates are applied to a row, of which the first one is an update * that only contains irrelevant fields (fields that do not need to be indexed), that the second update * is not ignored but indexed. There was a bug at some point (#39) that made this didn't work (knowing that * usually when this test is run, both SEP events will be delivered as a single batch). *///from www . ja v a2 s.c o m @Test public void testMixedIrrelevantAndRelevantUpdates() throws Exception { createTable("table1", "family1"); HTable table = new HTable(conf, "table1"); StringBuilder indexerConf = new StringBuilder(); indexerConf.append("<indexer table='table1'>"); indexerConf.append(" <field name='field1_s' value='family1:field1' type='string'/>"); indexerConf.append("</indexer>"); createIndexer1(indexerConf.toString()); SepTestUtil.waitOnReplicationPeerReady(peerId("indexer1")); byte[] rowkey = new byte[] { 0, 0, 0, 0 }; // First do a row update whereby we only set irrelevant fields (fields that do not need to be indexed) Put put = new Put(rowkey); put.add(b("family1"), b("irrelevant_field"), b("value1")); table.put(put); // Then update same row and set a field that does need to be indexed // (It is not per se important that it is the same row, but since the SEP splits events over // multiple threads, partitioned on row key, it is easiest to just do an update on the same row) put = new Put(rowkey); put.add(b("family1"), b("field1"), b("value1")); table.put(put); SepTestUtil.waitOnReplication(conf, 60000L); collection1.commit(); QueryResponse response = collection1.query(new SolrQuery("*:*")); assertEquals(1, response.getResults().size()); SolrDocument doc = response.getResults().get(0); assertEquals("#0;#0;#0;#0;", doc.getFirstValue("id").toString()); table.close(); }
From source file:com.ngdata.hbaseindexer.indexer.IndexerIT.java
License:Apache License
/** * A variant of {@link #testMixedIrrelevantAndRelevantUpdates} which triggers the same situation * using updates to different rows instead of the same. Note that we need to make changes to a number * of rows larger than the number of SEP threads. *///w ww .j av a 2 s. c om @Test public void testManyMixedIrrelevantAndRelevantUpdates() throws Exception { createTable("table1", "family1"); HTable table = new HTable(conf, "table1"); StringBuilder indexerConf = new StringBuilder(); indexerConf.append("<indexer table='table1'>"); indexerConf.append(" <field name='field1_s' value='family1:field1' type='string'/>"); indexerConf.append("</indexer>"); createIndexer1(indexerConf.toString()); SepTestUtil.waitOnReplicationPeerReady(peerId("indexer1")); int expectedRows = 0; List<Put> puts = Lists.newArrayList(); for (int i = 0; i < 100; i++) { Put put = new Put(Bytes.toBytes(String.valueOf(i))); put.add(b("family1"), b("irrelevant_field"), b("value1")); if (Math.random() >= 0.5d) { put.add(b("family1"), b("field1"), b("value1")); expectedRows++; } puts.add(put); } table.put(puts); SepTestUtil.waitOnReplication(conf, 60000L); collection1.commit(); SolrQuery params = new SolrQuery("*:*"); params.setRows(100); QueryResponse response = collection1.query(params); assertEquals(expectedRows, response.getResults().size()); table.close(); }
From source file:com.ngdata.hbaseindexer.indexer.IndexerIT.java
License:Apache License
/** * A variant of {@link #testMixedIrrelevantAndRelevantUpdates} using multiput. */// ww w . jav a 2 s . co m @Test public void testMixedIrrelevantAndRelevantUpdatesInSameMultiput() throws Exception { createTable("table1", "family1"); HTable table = new HTable(conf, "table1"); StringBuilder indexerConf = new StringBuilder(); indexerConf.append("<indexer table='table1'>"); indexerConf.append(" <field name='field1_s' value='family1:field1' type='string'/>"); indexerConf.append("</indexer>"); createIndexer1(indexerConf.toString()); SepTestUtil.waitOnReplicationPeerReady(peerId("indexer1")); byte[] rowkey = new byte[] { 0, 0, 0, 0 }; List<Put> puts = Lists.newArrayList(); Put put = new Put(rowkey); put.add(b("family1"), b("irrelevant_field"), b("value1")); puts.add(put); put = new Put(rowkey); put.add(b("family1"), b("field1"), b("value1")); puts.add(put); table.put(puts); SepTestUtil.waitOnReplication(conf, 60000L); collection1.commit(); QueryResponse response = collection1.query(new SolrQuery("*:*")); assertEquals(1, response.getResults().size()); SolrDocument doc = response.getResults().get(0); assertEquals("#0;#0;#0;#0;", doc.getFirstValue("id").toString()); table.close(); }
From source file:com.ngdata.hbaseindexer.indexer.IndexerIT.java
License:Apache License
private void waitForSolrDocumentCount(int count) throws Exception { long waitUntil = System.currentTimeMillis() + 60000L; int resultSize = 0; while (resultSize != count) { collection1.commit();//from w w w . ja va 2 s. c o m QueryResponse response = collection1.query(new SolrQuery("*:*")); resultSize = response.getResults().size(); if (System.currentTimeMillis() > waitUntil) { fail("Document not indexed in Solr within timeout"); } else { System.out.println("Waiting on document to be available in Solr..."); } Thread.sleep(20); } }
From source file:com.ngdata.hbaseindexer.mr.HBaseMapReduceIndexerToolDirectWriteTest.java
License:Apache License
@After public void tearDown() throws IOException, SolrServerException { HBASE_ADMIN.disableTable(TEST_TABLE_NAME); HBASE_ADMIN.deleteTable(TEST_TABLE_NAME); recordTable.close();/*from ww w . j a v a 2s . co m*/ COLLECTION1.deleteByQuery("*:*"); COLLECTION1.commit(); COLLECTION2.deleteByQuery("*:*"); COLLECTION2.commit(); // Be extra sure Solr is empty now QueryResponse response = COLLECTION1.query(new SolrQuery("*:*")); assertTrue(response.getResults().isEmpty()); }
From source file:com.ngdata.hbaseindexer.mr.HBaseMapReduceIndexerToolDirectWriteTest.java
License:Apache License
/** * Execute a Solr query on a specific collection. */// ww w . j av a 2 s . c om private SolrDocumentList executeSolrQuery(CloudSolrServer collection, String queryString) throws SolrServerException { QueryResponse response = collection.query(new SolrQuery(queryString)); return response.getResults(); }
From source file:com.ngdata.hbaseindexer.mr.HBaseMapReduceIndexerToolGoLiveTest.java
License:Apache License
@After public void tearDown() throws IOException, SolrServerException { COLLECTION1.deleteByQuery("*:*"); COLLECTION1.commit();//w ww.j a v a 2 s. c o m // Be extra sure Solr is empty now QueryResponse response = COLLECTION1.query(new SolrQuery("*:*")); assertTrue(response.getResults().isEmpty()); }