# Hibernate Search 6 suggesters + completion type

**URL:** <https://discourse.hibernate.org/t/hibernate-search-6-suggesters-completion-type/2978>\
**Category:** Hibernate Search\
**Created:** [July 18, 2019, 9:33am UTC](https://discourse.hibernate.org/t/hibernate-search-6-suggesters-completion-type/2978 "2019-07-18T09:33:36Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![yrodiere](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/yrodiere/32/1760_2.png) [@yrodiere](https://discourse.hibernate.org/u/yrodiere)\
**Post date:** [July 22, 2019, 8:21am UTC](https://discourse.hibernate.org/t/hibernate-search-6-suggesters-completion-type/2978/11 "2019-07-22T08:21:22Z")

</div>

We released Alpha8, which fixes this bug but also updates the bridge APIs. An official announcement will follow later today as I’m able (I’m traveling).

I’ll drop an updated version of my earlier comment here:

Define an annotation:

```java
package com.acme;

// ... imports ...

@PropertyBinding(binder = @PropertyBinderRef(type = com.acme.MyCompletionFieldBridge.Binder.class))
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.FIELD })
@Documented
@Repeatable(CompletionField.List.class)
public @interface CompletionField {

	String name();

	@Retention(RetentionPolicy.RUNTIME)
	@Target({ ElementType.METHOD, ElementType.FIELD })
	@Documented
	@interface List {
		CompletionField[] value();
	}
}

```

Then the bridge and its binder:

```auto
package com.acme;

// ... imports ...

public class MyCompletionFieldBridge implements PropertyBridge {
	private final IndexFieldReference<String> valueFieldReference;

	private MyCompletionFieldBridge(IndexFieldReference<String> valueFieldReference) {
		this.valueFieldReference = valueFieldReference;
	}

	@Override
	public void write(DocumentElement target, Object bridgedElement, PropertyBridgeWriteContext context) {
		String sourceValue = (String) bridgedElement;
		if ( sourceValue != null ) {
			// The "native" field type requires you to perform the JSON conversion yourself.
			// Ideally you should use a JSON library to properly escape the strings.
			target.addValue( valueFieldReference, "['" + sourceValue + "']" );
		}
	}

	public static class Binder implements PropertyBinder<CompletionField> {
		private String fieldName;

		@Override
		public void initialize(CompletionField annotation) {
			fieldName = annotation.name();
		}

		@Override
		public void bind(PropertyBindingContext context) {
			if ( fieldName == null || fieldName.isEmpty() ) {
				throw new IllegalArgumentException( "fieldName is a mandatory parameter" );
			}
			context.getDependencies().useRootOnly();
			IndexFieldReference<String> valueFieldReference = schema.field(
					fieldName,
					f -> f.extension( ElasticsearchExtension.get() )
							.asNative( "{\"type\": \"completion\"}" )
			).toReference();
			context.setBridge( new MyCompletionFieldBridge( valueFieldReference ) );
		}
	}
}

```

Then use the annotation in your mapping:

```auto
@CompletionField(name = "myTextProperty_suggest")
String myTextProperty;

```

---

_[View the full topic](https://discourse.hibernate.org/t/hibernate-search-6-suggesters-completion-type/2978)._
