Search in sources :

Example 1 with TestObject

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");
}
Also used : HashMap(java.util.HashMap) Region(org.apache.geode.cache.Region) TestObject(org.apache.geode.cache.lucene.test.TestObject) KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with TestObject

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");
}
Also used : HashMap(java.util.HashMap) Region(org.apache.geode.cache.Region) TestObject(org.apache.geode.cache.lucene.test.TestObject) KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with TestObject

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();
    }
}
Also used : HashMap(java.util.HashMap) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) TestObject(org.apache.geode.cache.lucene.test.TestObject) Analyzer(org.apache.lucene.analysis.Analyzer) LuceneRawIndexFactory(org.apache.geode.cache.lucene.internal.LuceneRawIndexFactory) LuceneIndexImplFactory(org.apache.geode.cache.lucene.internal.LuceneIndexImplFactory) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with TestObject

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);
}
Also used : HashMap(java.util.HashMap) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) TestObject(org.apache.geode.cache.lucene.test.TestObject) Analyzer(org.apache.lucene.analysis.Analyzer) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 5 with TestObject

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");
}
Also used : TestObject(org.apache.geode.cache.lucene.test.TestObject)

Aggregations

TestObject (org.apache.geode.cache.lucene.test.TestObject)13 Region (org.apache.geode.cache.Region)11 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)11 Test (org.junit.Test)11 HashMap (java.util.HashMap)6 LocalRegion (org.apache.geode.internal.cache.LocalRegion)6 Analyzer (org.apache.lucene.analysis.Analyzer)6 KeywordAnalyzer (org.apache.lucene.analysis.core.KeywordAnalyzer)4 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)4 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 TimeUnit (java.util.concurrent.TimeUnit)1 Parameters (junitparams.Parameters)1 CacheLoader (org.apache.geode.cache.CacheLoader)1 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)1 LoaderHelper (org.apache.geode.cache.LoaderHelper)1 RegionShortcut (org.apache.geode.cache.RegionShortcut)1 LuceneIntegrationTest (org.apache.geode.cache.lucene.LuceneIntegrationTest)1 InternalLuceneIndex (org.apache.geode.cache.lucene.internal.InternalLuceneIndex)1