Starts with a word or ends with a word

I am using Hibernate Search with spring-boot. I have requirement that user will have search operators to perform the following on the establishment name:

  1. Starts with a word
  2. Ends with a word
  • .Ali --> Means the phrase should strictly start with Ali, which means AlAli should not return in the results
query = queryBuilder.keyword().wildcard().onField("establishmentNameEn")
							.matching(term + "*").createQuery();

It returning mix result containing term in mid, start or in end not as per the above requirement

  • Kamran. --> Means it should strictly end end Kamran, meaning that Kamranullah should not be returned in the results
query = queryBuilder.keyword().wildcard().onField("establishmentNameEn")
							.matching("*"+term).createQuery();

As per documentation, its not a good idea to put “*” in start. My question here is: how can i achieve the expected

My domain class and analyzer:

@AnalyzerDef(name = "english", tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class), filters = {
		@TokenFilterDef(factory = StandardFilterFactory.class),
		@TokenFilterDef(factory = LowerCaseFilterFactory.class), })
@Indexed
@Entity
@Table(name = "DIRECTORY")
public class DirectoryEntity {

@Analyzer(definition = "english")
@Field(store = Store.YES)
@Column(name = "ESTABLISHMENT_NAME_EN")
private String establishmentNameEn;

getter and setter
}

This was crossposted to stackoverflow and answered there: https://stackoverflow.com/questions/59527919/starts-with-a-word-or-ends-with-a-word-using-hibernate-search/59608804#59608804

Closing.