Want to display scores in Percentage

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

See https://cwiki.apache.org/confluence/display/LUCENE/ScoresAsPercentages .

1 Like

@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.