# Want to display scores in Percentage

**URL:** <https://discourse.hibernate.org/t/want-to-display-scores-in-percentage/4362>\
**Category:** Hibernate Search\
**Created:** [July 2, 2020, 8:24am UTC](https://discourse.hibernate.org/t/want-to-display-scores-in-percentage/4362 "2020-07-02T08:24:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kumar\_Shikhar](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/kumar_shikhar/32/1097_2.png) [@Kumar\_Shikhar](https://discourse.hibernate.org/u/Kumar_Shikhar)\
**Post date:** [July 2, 2020, 8:24am UTC](https://discourse.hibernate.org/t/want-to-display-scores-in-percentage/4362/1 "2020-07-02T08:24:17Z")

</div>

I am new Lucene and hibernate Search. I am displaying scores of result fetched from indexes. I am using whitespace analyzer to index my data. I am getting scores in decimal values. My requirement is to display the score in percentage on scale of 100 %.  
below is my mentioned code and output. Please help if someone knows about this facility.  
You help will be appreciated.  
public class Scoring {

```
private static BooleanJunction<BooleanJunction> bool;

@SuppressWarnings("unchecked")
public static List<Object[]> check_score(String input) {

	List<Object[]> compassSingleLines = null;
	List<String> split_input = new ArrayList<>();
	input = input.replace("\"", "");
	String Whitespace_Analyzed_token = "fullRecord_forWildcards";
	Session session = null;

	session = HibernateUtil.getSessionFactory().openSession();
	FullTextSession fullTextSession = Search.getFullTextSession(session);
	QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(CompassSingleLine.class)
			.get();

	bool = qb.bool();
	String tokenizedinput = Whitespace_Analyzed_token;
	boolean check_wildcard = input.contains("?") || input.contains("*");
	boolean check_white_space = input.contains(" ");
	System.out.println("Contains whitespace :" + check_white_space);
	System.out.println("Contains wildcard :" + check_wildcard);

	if (check_white_space) {
		split_input = Arrays.asList(input.split("\\s"));
	}

	else {
		split_input.add(input);
	}

	System.out.println("Splitted value" + ":" + (split_input));
	System.out.println("tokenizedInput Used :" + (tokenizedinput));
	for (String token : split_input) {
		org.apache.lucene.search.Query lucene_query = qb.keyword().onField(tokenizedinput)
				.matching((token.toLowerCase())).createQuery();
		bool.must(lucene_query);
	}
    final Sort sort = qb.sort().byScore().createSort();

	org.apache.lucene.search.Query comb_query = bool
			.should(qb.simpleQueryString().onField("status").matching("Current").createQuery()).createQuery();

	FullTextQuery fulltext_query = fullTextSession.createFullTextQuery(comb_query, CompassSingleLine.class);
	fulltext_query.setProjection(ProjectionConstants.SCORE, ProjectionConstants.EXPLANATION,
		ProjectionConstants.THIS);
	System.out.println("Fulltext_Query_UsingSplit = " + " " + fulltext_query);
	fulltext_query.setMaxResults(15);
	compassSingleLines = fulltext_query.setSort(sort).getResultList();

	return compassSingleLines;

}

public static void display_score(String input) {

	long startTime = System.currentTimeMillis();
	List<Object[]> lines = Scoring.check_score(input);
	List<CompassSingleLine> singleLines = new ArrayList<>();

	for (Object[] a : lines) {
		Object[] firstResult = (Object[]) a;
		String score = firstResult[0].toString();
		String explanation = firstResult[1].toString();
		CompassSingleLine o = (CompassSingleLine) firstResult[2];
		System.out.println("Score: " + score);
	//	System.out.println("Explanation" +explanation);
		singleLines.add(o);
	}

	List<String> full_record = singleLines.stream().map(CompassSingleLine::getFullRecord)
			.collect(Collectors.toList());
	full_record.forEach(System.out::println);
	System.out.println("Matching no of rows" + " " + singleLines.size());
	System.out.println("searchLocation(): Total time: " + (System.currentTimeMillis() - startTime));

}

```

}

output :  
Contains whitespace :true  
Contains wildcard :false  
Splitted value:[MILLPOLL, COTTAGE]  
tokenizedInput Used :fullRecord\_forWildcards  
Fulltext\_Query\_UsingSplit = FullTextQueryImpl(+(fullRecord\_forWildcards:millpoll fullRecord\_forWildcards:MLPL) +(fullRecord\_forWildcards:cottage fullRecord\_forWildcards:KTJ fullRecord\_forWildcards:KTK) status:Current)  
Hibernate: select this\_.Ck as Ck1\_0\_0\_, this\_.addrId as addrId2\_0\_0\_, this\_.CompassSubtypeId as CompassS3\_0\_0\_, this\_.Confirmed as Confirme4\_0\_0\_, this\_.X as X5\_0\_0\_, this\_.Y as Y6\_0\_0\_, this\_.EntityType as EntityTy7\_0\_0\_, this\_.extRef as extRef8\_0\_0\_, this\_.FullRecord as FullReco9\_0\_0\_, this\_.LastModified as LastMod10\_0\_0\_, this\_.ProfileRecord as Profile11\_0\_0\_, this\_.Status as Status12\_0\_0\_ from vwCOMPASS\_SINGLELINE this\_ where (this\_.Ck in (?, ?, ?, ?, ?, ?, ?))  
Score: 3.1383018  
Score: 2.2411907  
Score: 1.9317881  
Score: 1.0988603  
Score: 1.0550767  
Score: 1.0550767  
Score: 0.8941627  
MILLPOOL COTTAGE (FIRST FLOOR FLAT)  
MILLPOOL COTTAGE (FIRST FLOOR FLAT), 12, MILLPOOL COTTAGE (FIRST FLOOR FLAT), 12, ST ANDREWS PLACE, CAWSAND, CORNWALL  
, MILLPOOL COTTAGE (FIRST FLOOR FLAT), 12, MILLPOOL COTTAGE (FIRST FLOOR FLAT), 12, ST ANDREWS PLACE, CAWSAND, CORNWALL, PL10 1PH, PL101PH  
BROOK COTTAGE, BROOK COTTAGE, , MILLPOOL HEAD, MILLBROOK, CORNWALL  
, MILLPOOL HEAD COTTAGE, MILLPOOL HEAD COTTAGE, , MILLPOOL HEAD, MILLBROOK, CORNWALL, PL10 1AW, PL101AW  
MILLPOOL HEAD COTTAGE, MILLPOOL HEAD COTTAGE, , MILLPOOL HEAD, MILLBROOK, CORNWALL  
, BROOK COTTAGE, BROOK COTTAGE, , MILLPOOL HEAD, MILLBROOK, CORNWALL, PL10 1AW, PL101AW  
Matching no of rows 7

---

<div class="post-metadata">

**Author:** ![gsmet](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/gsmet/32/9_2.png) [@gsmet](https://discourse.hibernate.org/u/gsmet)\
**Post date:** [July 2, 2020, 10:48am UTC](https://discourse.hibernate.org/t/want-to-display-scores-in-percentage/4362/2 "2020-07-02T10:48:09Z")

</div>

See [https://cwiki.apache.org/confluence/display/LUCENE/ScoresAsPercentages](https://cwiki.apache.org/confluence/display/LUCENE/ScoresAsPercentages) .

---

<div class="post-metadata">

**Author:** ![Kumar\_Shikhar](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/kumar_shikhar/32/1097_2.png) [@Kumar\_Shikhar](https://discourse.hibernate.org/u/Kumar_Shikhar)\
**Post date:** [July 2, 2020, 1:51pm UTC](https://discourse.hibernate.org/t/want-to-display-scores-in-percentage/4362/3 "2020-07-02T13:51:27Z")

</div>

@gsmet Thanks for the response.  
As you replied that link take to the page where that is not recommended to display scores as percentage.  
I need a solution because of my requirement.  
Please let me know the solution if you have any using hibernate search.

---

<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:** [August 3, 2020, 7:00am UTC](https://discourse.hibernate.org/t/want-to-display-scores-in-percentage/4362/4 "2020-08-03T07:00:18Z")

</div>


