DATAGEODE-101 - Add support for setting a LuceneSerializer on LuceneIndex creation.

This commit is contained in:
John Blum
2018-04-27 14:08:58 -07:00
parent 251f1f12e0
commit d16bbc8d28
6 changed files with 148 additions and 19 deletions

View File

@@ -53,22 +53,27 @@ class LuceneIndexParser extends AbstractSingleBeanDefinitionParser {
*/
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
super.doParse(element, parserContext, builder);
ParsingUtils.setCacheReference(element, builder);
ParsingUtils.setPropertyValue(element, builder, "name", "indexName");
ParsingUtils.setPropertyValue(element, builder, "destroy");
ParsingUtils.setPropertyReference(element, builder, "lucene-service-ref", "luceneService");
ParsingUtils.setPropertyValue(element, builder, "name", "indexName");
ParsingUtils.setPropertyReference(element, builder, "region-ref", "region");
ParsingUtils.setPropertyValue(element, builder, "region-path");
Optional.ofNullable(element.getAttribute("fields")).filter(StringUtils::hasText).ifPresent((fields) -> {
builder.addPropertyValue("fields", Arrays.stream(fields.split(","))
.map(String::trim).collect(Collectors.toList()));
});
Optional.ofNullable(element.getAttribute("fields"))
.filter(StringUtils::hasText)
.ifPresent(fields -> builder.addPropertyValue("fields",
Arrays.stream(fields.split(",")).map(String::trim).collect(Collectors.toList())));
Optional.ofNullable(DomUtils.getChildElementByTagName(element, "field-analyzers"))
.ifPresent((fieldAnalyzersElement) -> builder.addPropertyValue("fieldAnalyzers",
.ifPresent(fieldAnalyzersElement -> builder.addPropertyValue("fieldAnalyzers",
ParsingUtils.parseRefOrSingleNestedBeanDeclaration(fieldAnalyzersElement, parserContext, builder)));
Optional.ofNullable(DomUtils.getChildElementByTagName(element, "lucene-serializer"))
.ifPresent(luceneSerializerElement -> builder.addPropertyValue("luceneSerializer",
ParsingUtils.parseRefOrSingleNestedBeanDeclaration(luceneSerializerElement, parserContext, builder)));
}
}

View File

@@ -36,6 +36,7 @@ import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.lucene.LuceneIndex;
import org.apache.geode.cache.lucene.LuceneIndexFactory;
import org.apache.geode.cache.lucene.LuceneSerializer;
import org.apache.geode.cache.lucene.LuceneService;
import org.apache.geode.cache.lucene.LuceneServiceProvider;
import org.apache.lucene.analysis.Analyzer;
@@ -84,7 +85,8 @@ public class LuceneIndexFactoryBean extends AbstractFactoryBeanSupport<LuceneInd
@Override
public void configure(String beanName, LuceneIndexFactoryBean bean) {
nullSafeCollection(indexConfigurers).forEach(indexConfigurer -> indexConfigurer.configure(beanName, bean));
nullSafeCollection(indexConfigurers)
.forEach(indexConfigurer -> indexConfigurer.configure(beanName, bean));
}
};
@@ -92,6 +94,8 @@ public class LuceneIndexFactoryBean extends AbstractFactoryBeanSupport<LuceneInd
private LuceneIndex luceneIndex;
private LuceneSerializer luceneSerializer;
private LuceneService luceneService;
private Map<String, Analyzer> fieldAnalyzers;
@@ -190,6 +194,8 @@ public class LuceneIndexFactoryBean extends AbstractFactoryBeanSupport<LuceneInd
indexFactory.setFields(fieldAnalyzers);
}
Optional.ofNullable(getLuceneSerializer()).ifPresent(indexFactory::setLuceneSerializer);
indexFactory = postProcess(indexFactory);
indexFactory.create(indexName, regionPath);
@@ -607,7 +613,32 @@ public class LuceneIndexFactoryBean extends AbstractFactoryBeanSupport<LuceneInd
}
/**
* Sets a reference to the {@link LuceneService} used by this {@link FactoryBean} to create the {@link LuceneIndex}.
* Configures a reference to the {@link LuceneSerializer} used to convert {@link Object objects}
* to Lucene documents for the {@link LuceneIndex} created by this {@link LuceneIndexFactoryBean}.
*
* @param luceneSerializer {@link LuceneSerializer} used to convert {@link Object objects}
* to Lucene documents for the {@link LuceneIndex}.
* @see org.apache.geode.cache.lucene.LuceneSerializer
*/
public void setLuceneSerializer(LuceneSerializer luceneSerializer) {
this.luceneSerializer = luceneSerializer;
}
/**
* Returns a reference to the {@link LuceneSerializer} used to convert {@link Object objects}
* to Lucene documents for the {@link LuceneIndex} created by this {@link LuceneIndexFactoryBean}.
*
* @return a {@link LuceneSerializer} used to convert {@link Object objects}
* to Lucene documents for the {@link LuceneIndex}.
* @see org.apache.geode.cache.lucene.LuceneSerializer
*/
protected LuceneSerializer getLuceneSerializer() {
return this.luceneSerializer;
}
/**
* Configures a reference to the {@link LuceneService} used by this {@link FactoryBean}
* to create the {@link LuceneIndex}.
*
* @param luceneService {@link LuceneService} used to create the {@link LuceneIndex}.
* @see org.apache.geode.cache.lucene.LuceneService

View File

@@ -2433,10 +2433,19 @@ Defines a GemFire Lucene index.
<xsd:element name="field-analyzers" type="beanDeclarationType" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation><![CDATA[
Mapping of field names to Lucene (per field) Analyzers.
Mapping of field names to Lucene (per field) org.apache.lucene.analysis.Analyzers.
]]></xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="lucene-serializer" type="beanDeclarationType" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation><![CDATA[
Registers a bean as a LuceneSerializer with this Lucene Index bean definition, which will be used to convert objects
into Lucene documents for this index. The bean must implement org.apache.geode.cache.lucene.LuceneSerializer
and may be nested or referred to as a reference.
]]></xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string">
<xsd:annotation>