forked from docs/doc-exports
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-authored-by: Yang, Tong <yangtong2@huawei.com> Co-committed-by: Yang, Tong <yangtong2@huawei.com>
106 lines
6.0 KiB
HTML
106 lines
6.0 KiB
HTML
<a name="mrs_01_0493"></a><a name="mrs_01_0493"></a>
|
|
|
|
<h1 class="topictitle1">Supporting Full-Text Index</h1>
|
|
<div id="body8662426"><p id="mrs_01_0493__en-us_topic_0000001173789474_p731817329127">You can create tables and indexes using <strong id="mrs_01_0493__en-us_topic_0000001173789474_b167911229141410">createTable</strong> of <strong id="mrs_01_0493__en-us_topic_0000001173789474_b179120295142">org.apache.luna.client.LunaAdmin</strong> and specify table names, column family names, requests for creating indexes, as well as the directory path for storing mapping files. You can also add indexes to existing tables using <strong id="mrs_01_0493__en-us_topic_0000001173789474_b1866144181416">addCollection</strong> and obtain tables to perform a scan operation by using <strong id="mrs_01_0493__en-us_topic_0000001173789474_b16194552111417">getTable</strong> of <strong id="mrs_01_0493__en-us_topic_0000001173789474_b1319975214144">org.apache.luna.client.LunaAdmin</strong>.</p>
|
|
<p id="mrs_01_0493__en-us_topic_0000001173789474_p1973634161315">The column name and column family name of a table consist of letters, digits, and underscores (_) but cannot contain any special characters.</p>
|
|
<p id="mrs_01_0493__en-us_topic_0000001173789474_p13736154191316">HBase tables with a full-text index have the following limitations:</p>
|
|
<ul id="mrs_01_0493__en-us_topic_0000001173789474_ul252381021319"><li id="mrs_01_0493__en-us_topic_0000001173789474_li17460123121313">Disaster recovery, backup, and restoration are not supported.</li><li id="mrs_01_0493__en-us_topic_0000001173789474_li9421172816133">Rows and column families cannot be deleted.</li><li id="mrs_01_0493__en-us_topic_0000001173789474_li16219314451">Tight consistency is not supported by the query on Solr.</li></ul>
|
|
<div class="section" id="mrs_01_0493__en-us_topic_0000001173789474_section10642125451317"><h4 class="sectiontitle">Code Snippet Example</h4><p id="mrs_01_0493__en-us_topic_0000001173789474_p433710218148">The following code snippet belongs to the <strong id="mrs_01_0493__en-us_topic_0000001173789474_b0766191919159">testFullTextScan</strong> method in the <strong id="mrs_01_0493__en-us_topic_0000001173789474_b1077114195151">LunaSample</strong> class of the <strong id="mrs_01_0493__en-us_topic_0000001173789474_b7771101991517">hbase.examples</strong> package.</p>
|
|
<pre class="screen" id="mrs_01_0493__en-us_topic_0000001173789474_screen141207422188"> public static void testFullTextScan() throws Exception {
|
|
/**
|
|
* Create create request of Solr. Specify collection name, confset name,
|
|
* number of shards, and number of replication factor.
|
|
*/
|
|
Create create = new Create();
|
|
create.setCollectionName(COLLECTION_NAME);
|
|
create.setConfigName(CONFSET_NAME);
|
|
create.setNumShards(NUM_OF_SHARDS);
|
|
create.setReplicationFactor(NUM_OF_REPLICATIONFACTOR);
|
|
/**
|
|
* Create mapping. Specify index fields(mandatory) and non-index
|
|
* fields(optional).
|
|
*/
|
|
List<ColumnField> indexedFields = new ArrayList<ColumnField>();
|
|
indexedFields.add(new ColumnField("name", "f:n"));
|
|
indexedFields.add(new ColumnField("cat", "f:t"));
|
|
indexedFields.add(new ColumnField("features", "f:d"));
|
|
Mapping mapping = new Mapping(indexedFields);
|
|
/**
|
|
* Create table descriptor of HBase.
|
|
*/
|
|
HTableDescriptor desc = new HTableDescriptor(HBASE_TABLE);
|
|
desc.addFamily(new HColumnDescriptor(TABLE_FAMILY));
|
|
/**
|
|
* Create table and collection at the same time.
|
|
*/
|
|
LunaAdmin admin = null;
|
|
try {
|
|
admin = new AdminSingleton().getAdmin();
|
|
admin.deleteTable(HBASE_TABLE);
|
|
if (!admin.tableExists(HBASE_TABLE)) {
|
|
admin.createTable(desc, Bytes.toByteArrays(new String[] { "0", "1", "2", "3", "4" }),
|
|
create, mapping);
|
|
}
|
|
/**
|
|
* Put data.
|
|
*/
|
|
Table table = admin.getTable(HBASE_TABLE);
|
|
int i = 0;
|
|
while (i < 5) {
|
|
byte[] row = Bytes.toBytes(i + "+sohrowkey");
|
|
Put put = new Put(row);
|
|
put.addColumn(TABLE_FAMILY, Bytes.toBytes("n"), Bytes.toBytes("ZhangSan" + i));
|
|
put.addColumn(TABLE_FAMILY, Bytes.toBytes("t"), Bytes.toBytes("CO" + i));
|
|
put.addColumn(TABLE_FAMILY, Bytes.toBytes("d"), Bytes.toBytes("Male, Leader of M.O" + i));
|
|
table.put(put);
|
|
i++;
|
|
}
|
|
|
|
/**
|
|
* Scan table.
|
|
*/
|
|
Scan scan = new Scan();
|
|
SolrQuery query = new SolrQuery();
|
|
query.setQuery("name:ZhangSan1 AND cat:CO1");
|
|
Filter filter = new FullTextFilter(query, COLLECTION_NAME);
|
|
scan.setFilter(filter);
|
|
ResultScanner scanner = table.getScanner(scan);
|
|
LOG.info("-----------------records----------------");
|
|
for (Result r = scanner.next(); r != null; r = scanner.next()) {
|
|
for (Cell cell : r.rawCells()) {
|
|
LOG.info(Bytes.toString(CellUtil.cloneRow(cell)) + ":"
|
|
+ Bytes.toString(CellUtil.cloneFamily(cell)) + ","
|
|
+ Bytes.toString(CellUtil.cloneQualifier(cell)) + ","
|
|
+ Bytes.toString(CellUtil.cloneValue(cell)));
|
|
}
|
|
}
|
|
LOG.info("-------------------end------------------");
|
|
/**
|
|
* Delete collection.
|
|
*/
|
|
admin.deleteCollection(HBASE_TABLE, COLLECTION_NAME);
|
|
|
|
/**
|
|
* Delete table.
|
|
*/
|
|
admin.deleteTable(HBASE_TABLE);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
} finally {
|
|
/**
|
|
* When everything done, close LunaAdmin.
|
|
*/
|
|
admin.close();
|
|
}
|
|
}</pre>
|
|
</div>
|
|
<div class="section" id="mrs_01_0493__en-us_topic_0000001173789474_section4845633112312"><h4 class="sectiontitle">Precautions</h4><ul id="mrs_01_0493__en-us_topic_0000001173789474_ul1825538182311"><li id="mrs_01_0493__en-us_topic_0000001173789474_li72523852312">Tables and indexes to be created must be unique.</li><li id="mrs_01_0493__en-us_topic_0000001173789474_li17251384236">Use LunaAdmin only to obtain tables to perform a scan operation.</li></ul>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_0500.html">Using HBase</a></div>
|
|
</div>
|
|
</div>
|
|
|