Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HSEARCH-1088 Specifying an analyzer on an entity class bridge using the ... #277

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,7 @@ private void createFields(PropertyDescriptor property) {
AnnotationDescriptor fieldAnnotation = new AnnotationDescriptor( org.hibernate.search.annotations.Field.class );
for ( Map.Entry<String, Object> entry : field.entrySet() ) {
if ( entry.getKey().equals( "analyzer" ) ) {
AnnotationDescriptor analyzerAnnotation = new AnnotationDescriptor( Analyzer.class );
@SuppressWarnings("unchecked")
Map<String, Object> analyzer = (Map<String, Object>) entry.getValue();
for ( Map.Entry<String, Object> analyzerEntry : analyzer.entrySet() ) {
analyzerAnnotation.setValue( analyzerEntry.getKey(), analyzerEntry.getValue() );
}
fieldAnnotation.setValue( "analyzer", createAnnotation( analyzerAnnotation ) );
addAnalyzerAnnotationTo( fieldAnnotation, entry );
}
else if ( entry.getKey().equals( "boost" ) ) {
AnnotationDescriptor boostAnnotation = new AnnotationDescriptor( Boost.class );
Expand Down Expand Up @@ -466,6 +460,16 @@ else if ( entry.getKey().equals( "bridge" ) ) {
createFieldBridge( property );
}

private void addAnalyzerAnnotationTo(AnnotationDescriptor fieldAnnotation, Entry<String, Object> entry) {
AnnotationDescriptor analyzerAnnotation = new AnnotationDescriptor( Analyzer.class );
@SuppressWarnings("unchecked")
Map<String, Object> analyzer = (Map<String, Object>) entry.getValue();
for ( Map.Entry<String, Object> analyzerEntry : analyzer.entrySet() ) {
analyzerAnnotation.setValue( analyzerEntry.getKey(), analyzerEntry.getValue() );
}
fieldAnnotation.setValue( "analyzer", createAnnotation( analyzerAnnotation ) );
}

private void createFieldBridge(PropertyDescriptor property) {
if ( property.getFieldBridge() != null ) {
AnnotationDescriptor fieldBridgeAnn = new AnnotationDescriptor( FieldBridge.class );
Expand Down Expand Up @@ -605,7 +609,10 @@ private ClassBridge createClassBridge(Map<String, Object> classBridgeDef) {
AnnotationDescriptor annotation = new AnnotationDescriptor( ClassBridge.class );
Set<Entry<String, Object>> entrySet = classBridgeDef.entrySet();
for ( Entry<String, Object> entry : entrySet ) {
if ( entry.getKey().equals( "params" ) ) {
if ( entry.getKey().equals( "analyzer" ) ) {
addAnalyzerAnnotationTo( annotation, entry );
}
else if ( entry.getKey().equals( "params" ) ) {
addParamsToAnnotation( annotation, entry );
}
else {
Expand Down Expand Up @@ -669,7 +676,7 @@ public <T extends Annotation> boolean isAnnotationPresent(Class<T> annotationTyp

public Annotation[] getAnnotations() {
initAnnotations();
return new Annotation[0]; //To change body of implemented methods use File | Settings | File Templates.
return new Annotation[0];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public SearchMapping build() {
.similarity( DefaultSimilarity.class )
.boost( 2 )
.classBridge( AddressClassBridge.class )
.analyzer( "english" )
.property( "addressId", ElementType.FIELD ).documentId().name( "id" )
.property("lastUpdated", ElementType.FIELD)
.field().name("last-updated")
Expand Down