I am trying to do a fulltext search, the only problem i am facing is the fact, that excact matches are not on top of the list. If i search for "cat" then i get "blablacatcc", "asdcatsada" and then "cat". Is there a way to have it sorted like that? With exact matches on top?
my code:
final String[] fields = Stream.of(
Product_.casNumber.getName(),
Product_.casIndexName.getName(),
Product_.chemicalName.getName(),
path(Product_.alternativeNames, ProductName_.alternativeName)
).toArray(String[]::new);
final QueryBuilder builder = manager.getSearchFactory().buildQueryBuilder().forEntity(Product.class).get();
final Sort sort = builder.sort().byScore().createSort();
final Query query = builder.keyword().wildcard().onFields(fields).matching("*" + pattern.toLowerCase() + "*").createQuery();
return manager.createFullTextQuery(query, Product.class).setSort(sort).getResultList();