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

fix simple search explanation, fix typos #315

Merged
merged 2 commits into from
Oct 11, 2024
Merged
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
18 changes: 15 additions & 3 deletions src/components/search/concept-modal/tabs/explanation.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,19 @@ const palette = [

const parseScoreDetail = ({ value, description, details }) => {
if (value === 0) return null
// For "sum of:", relevant details contribute their own scores to a final aggregate value.
// (e.g., in a relevance scoring for a term over two search fields, perhaps name and description, maybe the name detail
// has score 5.2 and the description detail has score 3.3, then the aggregate score 8.5 will be used.)
if (description === "sum of:") {
return details.flatMap((detail) => parseScoreDetail(detail))
}
// For "max of:", only the detail with maximum score is used to compute the score.
// (e.g., in a relevance scoring for a term over two search fields, perhaps name and description, maybe the name detail
// has score 5.2 and the description detail has score 3.3, then the score of 5.2 will be used.)
if (description === "max of:") {
const maximalDetail = details.reduce((acc, cur) => cur.value > acc.value ? cur : acc, details[0])
return [parseScoreDetail(maximalDetail)]
}

const explainPattern = /^weight\((?<fieldName>.+):(?<searchTerm>.+) in (?<segmentNumber>\d+)\) \[(?<similarityMetric>.+)\], result of:$/
const match = description.match(explainPattern)
Expand Down Expand Up @@ -92,8 +102,8 @@ export const ExplanationTab = ({ result }) => {
const { fieldMatch, termMatch, source, value } = cur
const [fieldMatchName, fieldMatchDescription] = (
fieldMatch === "name" ? ["Concept Name", "Contribution to the score because the search query matched this concept's name"]
: fieldMatch === "description" ? ["Description", "Contribution to the score because we found the search query in this concept description"]
: fieldMatch === "search_terms" ? ["Synonyms", "Contribution to the score because we found the search query in this concept's synonymns"]
: fieldMatch === "description" ? ["Description", "Contribution to the score because we found the search query in this concept's description"]
: fieldMatch === "search_terms" ? ["Synonyms", "Contribution to the score because we found the search query in this concept's synonyms"]
: fieldMatch === "optional_terms" ? ["Related terms", "Contribution to the score because we found the search query among this concept's semantically related terms"]
: ["", ""]
)
Expand Down Expand Up @@ -175,7 +185,7 @@ export const ExplanationTab = ({ result }) => {
Explanation for this concept&apos;s relation to search term
</Text>
<div>
<Text style={{ fontSize: 13 }} italic>What does the total score returned by the search mean??</Text>
<Text style={{ fontSize: 13 }} italic>What does the total score returned by the search mean?</Text>
</div>
</div>
<div style={{ display: "flex", flexFlow: "row", alignItems: "center", marginRight: 16 }}>
Expand Down Expand Up @@ -204,6 +214,8 @@ export const ExplanationTab = ({ result }) => {
className="explanation-score-progress"
strokeColor={ colorMap[i] }
percent={ ((detail.value / totalScore) * 100).toFixed(0) }
// Get rid of annoying style rules at 100%
success={{ percent: 0 }}
title={ detail.value.toFixed(2) }
style={{ marginLeft: 8 }}
/>
Expand Down
Loading