Author: epbernard
Date: 2009-04-08 19:19:54 -0400 (Wed, 08 Apr 2009)
New Revision: 16284
Modified:
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/impl/MappingModelMetadataProvider.java
search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java
Log:
HSEARCH-352 add boost for class level on programmatic mapping
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java 2009-04-08
23:11:28 UTC (rev 16283)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/EntityDescriptor.java 2009-04-08
23:19:54 UTC (rev 16284)
@@ -12,6 +12,7 @@
private Map<String, Object> indexed;
private Map<PropertyKey, PropertyDescriptor> properties = new
HashMap<PropertyKey, PropertyDescriptor>();
private Map<String, Object> similarity;
+ private Map<String, Object> boost;
public Map<String, Object> getIndexed() {
return indexed;
@@ -47,6 +48,14 @@
return similarity;
}
+ public void setBoost(Map<String, Object> boost) {
+ this.boost = boost;
+ }
+
+ public Map<String, Object> getBoost() {
+ return boost;
+ }
+
private static class PropertyKey {
private String name;
private ElementType type;
Modified: search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java
===================================================================
--- search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java 2009-04-08
23:11:28 UTC (rev 16283)
+++ search/trunk/src/main/java/org/hibernate/search/cfg/EntityMapping.java 2009-04-08
23:19:54 UTC (rev 16284)
@@ -30,6 +30,13 @@
return this;
}
+ public EntityMapping boost(float boost) {
+ final Map<String, Object> boostAnn = new HashMap<String, Object>();
+ boostAnn.put( "value", boost );
+ entity.setBoost(boostAnn);
+ 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-04-08
23:11:28 UTC (rev 16283)
+++
search/trunk/src/main/java/org/hibernate/search/impl/MappingModelMetadataProvider.java 2009-04-08
23:19:54 UTC (rev 16284)
@@ -305,7 +305,6 @@
annotations.put( Fields.class, AnnotationFactory.create( fieldsAnnotation ) );
}
- //TODO add something around Similarity
private void createIndexed(EntityDescriptor entity) {
Class<? extends Annotation> annotationType = Indexed.class;
AnnotationDescriptor annotation = new AnnotationDescriptor( annotationType );
@@ -319,8 +318,16 @@
for ( Map.Entry<String, Object> entry : entity.getSimilarity().entrySet() ) {
annotation.setValue( entry.getKey(), entry.getValue() );
}
- annotations.put( annotationType, AnnotationFactory.create( annotation ) );
+ annotations.put( Similarity.class, AnnotationFactory.create( annotation ) );
}
+
+ if ( entity.getBoost() != null ) {
+ annotation = new AnnotationDescriptor( Boost.class );
+ for ( Map.Entry<String, Object> entry : entity.getBoost().entrySet() ) {
+ annotation.setValue( entry.getKey(), entry.getValue() );
+ }
+ annotations.put( Boost.class, AnnotationFactory.create( annotation ) );
+ }
}
private void populateAnnotationArray() {
Modified:
search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java
===================================================================
---
search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java 2009-04-08
23:11:28 UTC (rev 16283)
+++
search/trunk/src/test/java/org/hibernate/search/test/configuration/ProgrammaticMappingTest.java 2009-04-08
23:19:54 UTC (rev 16284)
@@ -10,6 +10,7 @@
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.queryParser.MultiFieldQueryParser;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.search.DefaultSimilarity;
import org.hibernate.search.cfg.SearchMapping;
import org.hibernate.search.cfg.ConcatStringBridge;
@@ -165,6 +166,8 @@
.param( "maxGramSize", "3" )
.indexedClass( Address.class )
+ .similarity( DefaultSimilarity.class )
+ .boost( 2 )
.property( "addressId", ElementType.FIELD ).documentId().name(
"id" )
.property( "street1", ElementType.FIELD )
.field()
Show replies by date