@Test public void testIndexEntryVerificationIndex() throws Exception { final String INDEX_NAME = "indexEntryVerification"; IndexManager indexManager = new IndexManager(TEST_UTIL.getConfiguration()); IndexDefinition indexDef = new IndexDefinition(INDEX_NAME, INDEX_NAME); indexDef.addStringField("stringfield"); indexDef.addFloatField("floatfield"); indexManager.createIndex(indexDef); Index index = indexManager.getIndex(INDEX_NAME, INDEX_NAME); IndexEntry entry = new IndexEntry(); entry.addField("nonexistingfield", "foobar"); try { index.addEntry(entry, Bytes.toBytes("key")); fail("Expected a MalformedIndexEntryException."); } catch (MalformedIndexEntryException e) { // ok } entry = new IndexEntry(); entry.addField("stringfield", new Integer(55)); try { index.addEntry(entry, Bytes.toBytes("key")); fail("Expected a MalformedIndexEntryException."); } catch (MalformedIndexEntryException e) { // ok } entry = new IndexEntry(); entry.addField("floatfield", "hello world"); try { index.addEntry(entry, Bytes.toBytes("key")); fail("Expected a MalformedIndexEntryException."); } catch (MalformedIndexEntryException e) { // ok } }
@Test public void testSingleFloatFieldIndex() throws Exception { final String INDEX_NAME = "singleFloatField"; IndexManager indexManager = new IndexManager(TEST_UTIL.getConfiguration()); IndexDefinition indexDef = new IndexDefinition(INDEX_NAME, INDEX_NAME); indexDef.addFloatField("field1"); indexManager.createIndex(indexDef); Index index = indexManager.getIndex(INDEX_NAME, INDEX_NAME); float[] values = {55.45f, 63.88f, 55.46f, 55.47f, -0.3f}; for (int i = 0; i < values.length; i++) { IndexEntry entry = new IndexEntry(); entry.addField("field1", values[i]); index.addEntry(entry, Bytes.toBytes("key" + i)); } Query query = new Query(); query.setRangeCondition("field1", new Float(55.44f), new Float(55.48f)); QueryResult result = index.performQuery(query); assertResultIds(result, "key0", "key2", "key3"); }