# Starts with a word or ends with a word

**URL:** https://discourse.hibernate.org/t/starts-with-a-word-or-ends-with-a-word/3577
**Category:** Hibernate Search
**Created:** [December 30, 2019, 8:09am UTC](https://discourse.hibernate.org/t/starts-with-a-word-or-ends-with-a-word/3577 "2019-12-30T08:09:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![kamran](https://avatars.discourse-cdn.com/v4/letter/k/b9e5f3/32.png) [@kamran](https://discourse.hibernate.org/u/kamran)
#### Post date: [December 30, 2019, 8:09am UTC](https://discourse.hibernate.org/t/starts-with-a-word-or-ends-with-a-word/3577/1 "2019-12-30T08:09:24Z")

</div>

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

```auto
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

```auto
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:

```auto
@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
}

```

---

<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: [January 6, 2020, 9:04am UTC](https://discourse.hibernate.org/t/starts-with-a-word-or-ends-with-a-word/3577/2 "2020-01-06T09:04:10Z")

</div>

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](https://stackoverflow.com/questions/59527919/starts-with-a-word-or-ends-with-a-word-using-hibernate-search/59608804#59608804)

Closing.

---

<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: [January 6, 2020, 9:04am UTC](https://discourse.hibernate.org/t/starts-with-a-word-or-ends-with-a-word/3577/3 "2020-01-06T09:04:12Z")

</div>


