use of org.apache.geode.cache.lucene.test.TestObject in project geode by apache.
the class LuceneQueriesIntegrationTest method shouldAllowNullInFieldValue.
@Test()
public void shouldAllowNullInFieldValue() throws Exception {
Map<String, Analyzer> fields = new HashMap<String, Analyzer>();
fields.put("field1", null);
fields.put("field2", null);
luceneService.createIndexFactory().setFields(fields).create(INDEX_NAME, REGION_NAME);
Region region = cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
// Put two values with some of the same tokens
String value1 = "one three";
region.put("A", new TestObject(value1, null));
luceneService.waitUntilFlushed(INDEX_NAME, REGION_NAME, 60000, TimeUnit.MILLISECONDS);
verifyQuery("field1:one", DEFAULT_FIELD, "A");
}
use of org.apache.geode.cache.lucene.test.TestObject in project geode by apache.
the class LuceneQueriesIntegrationTest method soundexQueryReturnExpectedTruePositiveAndFalsePositive.
@Test()
public void soundexQueryReturnExpectedTruePositiveAndFalsePositive() throws Exception {
Map<String, Analyzer> fields = new HashMap<String, Analyzer>();
fields.put("field1", new DoubleMetaphoneAnalyzer());
fields.put("field2", null);
luceneService.createIndexFactory().setFields(fields).create(INDEX_NAME, REGION_NAME);
Region region = cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
region.put("A", new TestObject("Stefan", "soundex"));
region.put("B", new TestObject("Steph", "soundex"));
region.put("C", new TestObject("Stephen", "soundex"));
region.put("D", new TestObject("Steve", "soundex"));
region.put("E", new TestObject("Steven", "soundex"));
region.put("F", new TestObject("Stove", "soundex"));
region.put("G", new TestObject("Stuffin", "soundex"));
luceneService.waitUntilFlushed(INDEX_NAME, REGION_NAME, 60000, TimeUnit.MILLISECONDS);
verifyQuery("field1:Stephen", DEFAULT_FIELD, "A", "C", "E", "G");
}
use of org.apache.geode.cache.lucene.test.TestObject in project geode by apache.
the class LuceneIndexCreationIntegrationTest method shouldCreateRawIndexIfSpecifiedItsFactory.
@Test
public void shouldCreateRawIndexIfSpecifiedItsFactory() throws BucketNotFoundException, InterruptedException {
Map<String, Analyzer> analyzers = new HashMap<>();
final RecordingAnalyzer field1Analyzer = new RecordingAnalyzer();
final RecordingAnalyzer field2Analyzer = new RecordingAnalyzer();
analyzers.put("field1", field1Analyzer);
analyzers.put("field2", field2Analyzer);
LuceneServiceImpl.luceneIndexFactory = new LuceneRawIndexFactory();
try {
luceneService.createIndexFactory().setFields(analyzers).create(INDEX_NAME, REGION_NAME);
Region region = createRegion();
final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
assertThat(index).isInstanceOf(LuceneRawIndex.class);
region.put("key1", new TestObject());
verifyIndexFinishFlushing(cache, INDEX_NAME, REGION_NAME);
assertEquals(analyzers, index.getFieldAnalyzers());
assertEquals(Arrays.asList("field1"), field1Analyzer.analyzedfields);
assertEquals(Arrays.asList("field2"), field2Analyzer.analyzedfields);
} finally {
LuceneServiceImpl.luceneIndexFactory = new LuceneIndexImplFactory();
}
}
use of org.apache.geode.cache.lucene.test.TestObject in project geode by apache.
the class LuceneIndexCreationIntegrationTest method shouldCreateIndexWriterWithAnalyzersWhenSettingPerFieldAnalyzers.
@Test
public void shouldCreateIndexWriterWithAnalyzersWhenSettingPerFieldAnalyzers() throws BucketNotFoundException, InterruptedException {
Map<String, Analyzer> analyzers = new HashMap<>();
final RecordingAnalyzer field1Analyzer = new RecordingAnalyzer();
final RecordingAnalyzer field2Analyzer = new RecordingAnalyzer();
analyzers.put("field1", field1Analyzer);
analyzers.put("field2", field2Analyzer);
luceneService.createIndexFactory().setFields(analyzers).create(INDEX_NAME, REGION_NAME);
Region region = createRegion();
final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
region.put("key1", new TestObject());
verifyIndexFinishFlushing(cache, INDEX_NAME, REGION_NAME);
assertEquals(analyzers, index.getFieldAnalyzers());
assertEquals(Arrays.asList("field1"), field1Analyzer.analyzedfields);
assertEquals(Arrays.asList("field2"), field2Analyzer.analyzedfields);
}
use of org.apache.geode.cache.lucene.test.TestObject in project geode by apache.
the class LuceneQueriesIntegrationTest method addValuesAndCreateQuery.
private LuceneQuery<Object, Object> addValuesAndCreateQuery(int pagesize) throws InterruptedException {
luceneService.createIndexFactory().setFields("field1", "field2").create(INDEX_NAME, REGION_NAME);
region = cache.createRegionFactory(RegionShortcut.PARTITION).create(REGION_NAME);
final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
// Put two values with some of the same tokens
String value1 = "one three";
String value2 = "one two three";
String value3 = "one@three";
region.put("A", new TestObject(value1, value1));
region.put("B", new TestObject(value2, value2));
region.put("C", new TestObject(value3, value3));
region.put("D", new TestObject(value1, value1));
region.put("E", new TestObject(value2, value2));
region.put("F", new TestObject(value3, value3));
region.put("G", new TestObject(value1, value2));
luceneService.waitUntilFlushed(INDEX_NAME, REGION_NAME, 60000, TimeUnit.MILLISECONDS);
return luceneService.createLuceneQueryFactory().setPageSize(pagesize).create(INDEX_NAME, REGION_NAME, "one", "field1");
}
Aggregations