Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store search-score in EntityInfo. Respect score when retrieving search entries #86

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public List<EntityInfo> searchAllField(String searchTerm, int firstResult, int m
String entityName = doc.getField(FLD_ENTITY).stringValue();
String strEntityId = doc.getField(FLD_ID).stringValue();
EntityInfo entityInfo = new EntityInfo(entityName, parseIdFromString(strEntityId, entityName));
entityInfo.setScore(scoreDoc.score);
set.add(entityInfo);
}
} catch (IOException e) {
Expand Down Expand Up @@ -215,6 +216,7 @@ public List<EntityInfo> searchLinksField(Object id, int firstResult, int maxResu
String entityName = doc.getField(FLD_ENTITY).stringValue();
String strEntityId = doc.getField(FLD_ID).stringValue();
EntityInfo entityInfo = new EntityInfo(entityName, parseIdFromString(strEntityId, entityName));
entityInfo.setScore(scoreDoc.score);
set.add(entityInfo);
}
} catch (IOException e) {
Expand Down
10 changes: 10 additions & 0 deletions modules/global/src/com/haulmont/fts/global/EntityInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ public class EntityInfo implements Serializable {

private String entityName;
private Object id;
private float score;

public EntityInfo(String entityName, Object id) {
this.id = id;
this.entityName = entityName;
this.score = 0;
}

public Object getId() {
Expand All @@ -39,6 +41,14 @@ public String getEntityName() {
return entityName;
}

public float getScore() {
return score;
}

public void setScore(float score) {
this.score = score;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
9 changes: 7 additions & 2 deletions modules/global/src/com/haulmont/fts/global/SearchResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.annotation.Nullable;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;

/**
* Contains information about searched entities and searched page {@link QueryKey}
Expand Down Expand Up @@ -52,8 +53,12 @@ public SearchResultEntry getEntryByEntityInfo(EntityInfo entityInfo) {
}

public Set<SearchResultEntry> getEntriesByEntityName(String entityName) {
Set<SearchResultEntry> entries = entriesByEntityName.get(entityName);
return entries == null ? Collections.emptySet() : Collections.unmodifiableSet(entries);
final Comparator<SearchResultEntry> comparator = Comparator.comparing(searchResultEntry -> searchResultEntry.getEntityInfo().getScore());
Set<SearchResultEntry> entries = entriesByEntityName.get(entityName)
.stream()
.sorted(comparator.reversed())
.collect(Collectors.toCollection(LinkedHashSet::new));
return Collections.unmodifiableSet(entries);
}

public Set<SearchResultEntry> getAllEntries() {
Expand Down