use of org.apache.lucene.analysis.Analyzer 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.lucene.analysis.Analyzer 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.lucene.analysis.Analyzer 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.lucene.analysis.Analyzer 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.lucene.analysis.Analyzer in project geode by apache.
the class LuceneIndexCreationProfileJUnitTest method getTwoAnalyzersLuceneIndexCreationProfile.
private LuceneIndexCreationProfile getTwoAnalyzersLuceneIndexCreationProfile() {
Map<String, Analyzer> fieldAnalyzers = new HashMap<>();
fieldAnalyzers.put("field1", new KeywordAnalyzer());
fieldAnalyzers.put("field2", new KeywordAnalyzer());
return new LuceneIndexCreationProfile(INDEX_NAME, REGION_NAME, new String[] { "field1", "field2" }, getPerFieldAnalyzerWrapper(fieldAnalyzers), fieldAnalyzers);
}
Aggregations