Author: epbernard
Date: 2009-12-21 10:12:12 -0500 (Mon, 21 Dec 2009)
New Revision: 18301
Removed:
search/trunk/src/main/java/org/hibernate/search/cfg/DynamicEntityBoostMapping.java
search/trunk/src/main/java/org/hibernate/search/cfg/DynamicFieldBoostMapping.java
Modified:
search/trunk/src/main/docbook/en-US/modules/mapping.xml
search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java
search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java
search/trunk/src/main/java/org/hibernate/search/cfg/FieldMapping.java
search/trunk/src/main/java/org/hibernate/search/cfg/IndexedMapping.java
search/trunk/src/main/java/org/hibernate/search/cfg/PropertyDescriptor.java
search/trunk/src/main/java/org/hibernate/search/cfg/PropertyMapping.java
search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java
search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticSearchMappingFactory.java
Log:
HSEARCH-411 improve dynamicboost mapping
Modified: search/trunk/src/main/docbook/en-US/modules/mapping.xml
===================================================================
--- search/trunk/src/main/docbook/en-US/modules/mapping.xml 2009-12-21 13:58:50 UTC (rev
18300)
+++ search/trunk/src/main/docbook/en-US/modules/mapping.xml 2009-12-21 15:12:12 UTC (rev
18301)
@@ -2236,9 +2236,9 @@
.property("libraryId", ElementType.FIELD)
.documentId().name("id")
.property("name", ElementType.FIELD)
+ <emphasis>.dynamicBoost(CustomFieldBoostStrategy.class)</emphasis>;
.field()
.store(Store.YES)
- <emphasis>.dynamicBoost(CustomFieldBoostStrategy.class)</emphasis>;
cfg.getProperties().put( "hibernate.search.model_mapping", mapping
);</programlisting>
Deleted:
search/trunk/src/main/java/org/hibernate/search/cfg/DynamicEntityBoostMapping.java
===================================================================
---
search/trunk/src/main/java/org/hibernate/search/cfg/DynamicEntityBoostMapping.java 2009-12-21
13:58:50 UTC (rev 18300)
+++
search/trunk/src/main/java/org/hibernate/search/cfg/DynamicEntityBoostMapping.java 2009-12-21
15:12:12 UTC (rev 18301)
@@ -1,47 +0,0 @@
-package org.hibernate.search.cfg;
-
-import java.lang.annotation.ElementType;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.solr.analysis.TokenizerFactory;
-import org.hibernate.search.engine.BoostStrategy;
-
-public class DynamicEntityBoostMapping {
-
- private final SearchMapping mapping;
- private final Map<String,Object> dynamicEntityBoost;
- private final EntityDescriptor entity;
- private final EntityMapping entityMapping;
-
- public DynamicEntityBoostMapping(SearchMapping mapping, Class<? extends
BoostStrategy> impl, EntityDescriptor entity, EntityMapping entityMapping) {
- this.mapping = mapping;
- this.entity = entity;
- this.entityMapping = entityMapping;
- this.dynamicEntityBoost = new HashMap<String, Object>();
- this.entity.setDynamicEntityBoost(dynamicEntityBoost);
- this.dynamicEntityBoost.put("impl", impl);
-
- }
-
- public FullTextFilterDefMapping fullTextFilterDef(String name, Class<?> impl) {
- return new FullTextFilterDefMapping(mapping,name, impl);
- }
-
- public PropertyMapping property(String name, ElementType type) {
- return new PropertyMapping(name, type, entity, mapping);
- }
-
- public AnalyzerDefMapping analyzerDef(String name, Class<? extends
TokenizerFactory> tokenizerFactory) {
- return new AnalyzerDefMapping(name, tokenizerFactory, mapping);
- }
-
- public EntityMapping entity(Class<?> entityType) {
- return new EntityMapping(entityType, mapping);
- }
-
- public ClassBridgeMapping classBridge(Class<?> impl) {
- return new ClassBridgeMapping(mapping, entity, impl, entityMapping);
- }
-
-}
Deleted:
search/trunk/src/main/java/org/hibernate/search/cfg/DynamicFieldBoostMapping.java
===================================================================
---
search/trunk/src/main/java/org/hibernate/search/cfg/DynamicFieldBoostMapping.java 2009-12-21
13:58:50 UTC (rev 18300)
+++
search/trunk/src/main/java/org/hibernate/search/cfg/DynamicFieldBoostMapping.java 2009-12-21
15:12:12 UTC (rev 18301)
@@ -1,59 +0,0 @@
-package org.hibernate.search.cfg;
-
-import java.lang.annotation.ElementType;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.solr.analysis.TokenizerFactory;
-import org.hibernate.search.annotations.Resolution;
-import org.hibernate.search.engine.BoostStrategy;
-
-public class DynamicFieldBoostMapping {
-
- private final SearchMapping mapping;
- private final EntityDescriptor entity;
- private final Map<String,Object> dynamicFieldBoost;
- private final PropertyDescriptor property;
-
- public DynamicFieldBoostMapping(SearchMapping mapping, Class<? extends
BoostStrategy> impl, PropertyDescriptor property, EntityDescriptor entity) {
- this.mapping = mapping;
- this.property = property;
- this.entity = entity;
- dynamicFieldBoost = new HashMap<String, Object>();
- this.property.setDynamicFieldBoost(dynamicFieldBoost);
- dynamicFieldBoost.put("impl", impl);
- }
-
- public FieldMapping field() {
- return new FieldMapping(property, entity, mapping);
- }
-
- public PropertyMapping property(String name, ElementType type) {
- return new PropertyMapping(name, type, entity, mapping);
- }
-
- public DateBridgeMapping dateBridge(Resolution resolution) {
- return new DateBridgeMapping(mapping, entity, property, resolution);
- }
-
- public AnalyzerDefMapping analyzerDef(String name, Class<? extends
TokenizerFactory> tokenizerFactory) {
- return new AnalyzerDefMapping(name, tokenizerFactory, mapping);
- }
-
- public EntityMapping entity(Class<?> entityType) {
- return new EntityMapping(entityType, mapping);
- }
-
- public CalendarBridgeMapping calendarBridge(Resolution resolution) {
- return new CalendarBridgeMapping(mapping,entity,property, resolution);
- }
-
- public IndexEmbeddedMapping indexEmbedded() {
- return new IndexEmbeddedMapping(mapping,property,entity);
- }
-
- public ContainedInMapping containedIn() {
- return new ContainedInMapping(mapping, property, entity);
- }
-
-}
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java 2009-12-21
13:58:50 UTC (rev 18300)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java 2009-12-21
15:12:12 UTC (rev 18301)
@@ -43,7 +43,7 @@
private Set<Map<String, Object>> fullTextFilterDefs = new
HashSet<Map<String, Object>>();
private Map<String,Object> providedId;
private Set<Map<String,Object>> classBridges = new
HashSet<Map<String,Object>>();
- private Map<String, Object> dynamicEntityBoost;
+ private Map<String, Object> dynamicBoost;
public Map<String, Object> getIndexed() {
return indexed;
@@ -120,12 +120,12 @@
return this.providedId;
}
- public void setDynamicEntityBoost(Map<String, Object> dynamicEntityBoost) {
- this.dynamicEntityBoost = dynamicEntityBoost;
+ public void setDynamicBoost(Map<String, Object> dynamicEntityBoost) {
+ this.dynamicBoost = dynamicEntityBoost;
}
- public Map<String, Object> getDynamicEntityBoost() {
- return this.dynamicEntityBoost;
+ public Map<String, Object> getDynamicBoost() {
+ return this.dynamicBoost;
}
private static class PropertyKey {
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java 2009-12-21
13:58:50 UTC (rev 18300)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java 2009-12-21
15:12:12 UTC (rev 18301)
@@ -62,6 +62,14 @@
return this;
}
+
+ public EntityMapping dynamicBoost(Class<? extends BoostStrategy> impl) {
+ final Map<String, Object> dynamicBoost = new HashMap<String, Object>();
+ dynamicBoost.put("impl", impl);
+ entity.setDynamicBoost(dynamicBoost);
+ return this;
+ }
+
public EntityMapping analyzerDiscriminator(Class<? extends Discriminator>
discriminator) {
final Map<String, Object> discriminatorAnn = new HashMap<String,
Object>();
discriminatorAnn.put( "impl", discriminator );
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/FieldMapping.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/FieldMapping.java 2009-12-21
13:58:50 UTC (rev 18300)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/FieldMapping.java 2009-12-21
15:12:12 UTC (rev 18301)
@@ -77,6 +77,7 @@
field.put( "boost", boostAnn );
return this;
}
+
public FieldBridgeMapping bridge(Class<?> impl) {
return new FieldBridgeMapping( impl, field, this, property, entity, mapping );
@@ -120,8 +121,4 @@
return new CalendarBridgeMapping(mapping,entity,property, resolution);
}
- public DynamicFieldBoostMapping dynamicBoost(Class<? extends BoostStrategy> impl)
{
- return new DynamicFieldBoostMapping(mapping, impl, property, entity);
- }
-
}
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/IndexedMapping.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/IndexedMapping.java 2009-12-21
13:58:50 UTC (rev 18300)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/IndexedMapping.java 2009-12-21
15:12:12 UTC (rev 18301)
@@ -30,7 +30,6 @@
import org.apache.solr.analysis.TokenizerFactory;
import org.hibernate.search.analyzer.Discriminator;
-import org.hibernate.search.engine.BoostStrategy;
public class IndexedMapping {
@@ -93,9 +92,5 @@
public ProvidedIdMapping providedId() {
return new ProvidedIdMapping(mapping,entity);
}
-
- public DynamicEntityBoostMapping dynamicBoost(Class<? extends BoostStrategy> impl)
{
- return new DynamicEntityBoostMapping(mapping, impl, entity, entityMapping);
- }
}
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/PropertyDescriptor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/PropertyDescriptor.java 2009-12-21
13:58:50 UTC (rev 18300)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/PropertyDescriptor.java 2009-12-21
15:12:12 UTC (rev 18301)
@@ -44,7 +44,7 @@
private Map<String, Object> documentId;
private Map<String, Object> analyzerDiscriminator;
- private Map<String, Object> dynamicFieldBoost;
+ private Map<String, Object> dynamicBoost;
public PropertyDescriptor(String name, ElementType type) {
this.name = name;
@@ -106,12 +106,11 @@
this.containedIn = containedIn;
}
- public void setDynamicFieldBoost(Map<String, Object> dynamicFieldBoost) {
- this.dynamicFieldBoost = dynamicFieldBoost;
+ public void setDynamicBoost(Map<String, Object> dynamicBoostAnn) {
+ this.dynamicBoost = dynamicBoostAnn;
}
- public Map<String,Object> getDynamicFieldBoost() {
- return this.dynamicFieldBoost;
+ public Map<String,Object> getDynamicBoost() {
+ return this.dynamicBoost;
}
-
}
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/PropertyMapping.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/PropertyMapping.java 2009-12-21
13:58:50 UTC (rev 18300)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/PropertyMapping.java 2009-12-21
15:12:12 UTC (rev 18301)
@@ -32,6 +32,7 @@
import org.hibernate.search.analyzer.Discriminator;
import org.hibernate.search.annotations.Resolution;
+import org.hibernate.search.engine.BoostStrategy;
/**
* @author Emmanuel Bernard
@@ -69,6 +70,13 @@
property.setAnalyzerDiscriminator(analyzerDiscriminatorAnn);
return this;
}
+
+ public PropertyMapping dynamicBoost(Class<? extends BoostStrategy> impl) {
+ final Map<String, Object> dynamicBoostAnn = new HashMap<String, Object>();
+ dynamicBoostAnn.put("impl", impl);
+ property.setDynamicBoost(dynamicBoostAnn);
+ return this;
+ }
public PropertyMapping property(String name, ElementType type) {
return new PropertyMapping(name, type, entity, mapping);
Modified:
search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java
===================================================================
---
search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java 2009-12-21
13:58:50 UTC (rev 18300)
+++
search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java 2009-12-21
15:12:12 UTC (rev 18301)
@@ -316,16 +316,6 @@
}
}
- private void createDynamicFieldBoost(PropertyDescriptor property) {
- if (property.getDynamicFieldBoost() != null) {
- AnnotationDescriptor dynamicBoostAnn = new AnnotationDescriptor( DynamicBoost.class
);
- Set<Entry<String,Object>> entrySet =
property.getDynamicFieldBoost().entrySet();
- for (Entry<String, Object> entry : entrySet) {
- dynamicBoostAnn.setValue(entry.getKey(), entry.getValue());
- }
- annotations.put(DynamicBoost.class, AnnotationFactory.create( dynamicBoostAnn ));
- }
- }
private void createDateBridge(PropertyDescriptor property) {
Map<String, Object> map = property.getDateBridge();
@@ -367,6 +357,7 @@
}
}
+
private void createFields(PropertyDescriptor property) {
final Collection<Map<String,Object>> fields = property.getFields();
List<org.hibernate.search.annotations.Field> fieldAnnotations =
@@ -405,7 +396,7 @@
}
}
fieldAnnotation.setValue( "bridge", AnnotationFactory.create(
bridgeAnnotation ) );
- }
+ }
else {
fieldAnnotation.setValue( entry.getKey(), entry.getValue() );
}
@@ -422,10 +413,20 @@
annotations.put( Fields.class, AnnotationFactory.create( fieldsAnnotation ) );
createDateBridge(property);
createCalendarBridge(property);
- createDynamicFieldBoost(property);
+ createDynamicBoost(property);
+
}
-
+ private void createDynamicBoost(PropertyDescriptor property) {
+ if (property.getDynamicBoost() != null) {
+ AnnotationDescriptor dynamicBoostAnn = new AnnotationDescriptor( DynamicBoost.class
);
+ Set<Entry<String,Object>> entrySet =
property.getDynamicBoost().entrySet();
+ for (Entry<String, Object> entry : entrySet) {
+ dynamicBoostAnn.setValue(entry.getKey(), entry.getValue());
+ }
+ annotations.put(DynamicBoost.class, AnnotationFactory.create( dynamicBoostAnn ));
+ }
+ }
private void createContainedIn(PropertyDescriptor property) {
if (property.getContainedIn() != null) {
Map<String, Object> containedIn = property.getContainedIn();
@@ -500,9 +501,9 @@
annotations.put(ClassBridges.class, AnnotationFactory.create( classBridgesAnn ));
}
- if (entity.getDynamicEntityBoost() != null) {
+ if (entity.getDynamicBoost() != null) {
AnnotationDescriptor dynamicBoostAnn = new AnnotationDescriptor( DynamicBoost.class
);
- Set<Entry<String,Object>> entrySet =
entity.getDynamicEntityBoost().entrySet();
+ Set<Entry<String,Object>> entrySet =
entity.getDynamicBoost().entrySet();
for (Entry<String, Object> entry : entrySet) {
dynamicBoostAnn.setValue(entry.getKey(), entry.getValue());
}
Modified:
search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticSearchMappingFactory.java
===================================================================
---
search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticSearchMappingFactory.java 2009-12-21
13:58:50 UTC (rev 18300)
+++
search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticSearchMappingFactory.java 2009-12-21
15:12:12 UTC (rev 18301)
@@ -80,13 +80,13 @@
.property("productCatalog", ElementType.FIELD)
.containedIn()
.entity(DynamicBoostedDescLibrary.class)
+ .dynamicBoost(CustomBoostStrategy.class)
.indexed()
- .dynamicBoost(CustomBoostStrategy.class)
.property("libraryId", ElementType.FIELD)
.documentId().name("id")
.property("name", ElementType.FIELD)
+ .dynamicBoost(CustomFieldBoostStrategy.class)
.field().store(Store.YES)
- .dynamicBoost(CustomFieldBoostStrategy.class)
.entity(Departments.class)
.classBridge(CatDeptsFieldsClassBridge.class)
.name("branchnetwork")