Skip to content

Commit b544a95

Browse files
committed
Fixed load bar, search bar centralization, and semantic search mathematical logic
1 parent bd0d9b0 commit b544a95

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/components/OnboardingComponents/SemanticSearch/SemanticSearchContainer.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-FileCopyrightText: 2024 German Aerospace Center (DLR)
22
// SPDX-License-Identifier: Apache-2.0
33

4-
import React, {useState, useMemo, useCallback} from 'react';
4+
import React, {useState, useMemo, useCallback, useEffect} from 'react';
55
import {Box, Typography, Divider, TextField, IconButton, InputAdornment, CircularProgress} from '@mui/material';
66
import {useSemanticSearch} from 'context/SemanticSearchContext';
77
import QuerySuggestions from './QuerySuggestions';
@@ -26,6 +26,13 @@ export default function SemanticSearchContainer({localization}: {localization?:
2626
const {t: defaultT, i18n} = useTranslation();
2727
const [selectedArticle, setSelectedArticle] = useState<SearchResult | null>(null);
2828

29+
useEffect(() => {
30+
return () => {
31+
dispatch(setSemanticSearchQuery(''));
32+
clearSearch();
33+
};
34+
}, [dispatch, clearSearch]);
35+
2936
const memoizedLocalization = useMemo(
3037
() =>
3138
localization ?? {
@@ -119,6 +126,9 @@ export default function SemanticSearchContainer({localization}: {localization?:
119126
borderRadius: '4px',
120127
backgroundColor: 'primary.main',
121128
color: 'primary.contrastText',
129+
display: 'flex',
130+
alignItems: 'center',
131+
justifyContent: 'center',
122132
'&:hover': {
123133
backgroundColor: 'primary.dark',
124134
},

src/context/SemanticSearchContext.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ export function SemanticSearchProvider({children}: SemanticSearchProviderProps)
3838
const queryTerms = lowerCaseQuery.split(' ').filter((term) => term.length > 2);
3939

4040
const newResults: SearchResult[] = apiResponse.results.map((item) => {
41-
const relevanceScore = Math.round(item.similarity * 100);
41+
const relevanceScore = item.similarity;
4242

43-
let classification: 'direct' | 'high' | 'related';
44-
if (relevanceScore >= 90) {
43+
let classification: 'direct' | 'high' | 'related' | 'unrelated';
44+
if (relevanceScore >= 0.9) {
4545
classification = 'direct';
46-
} else if (relevanceScore >= 80) {
46+
} else if (relevanceScore >= 0.8) {
4747
classification = 'high';
48-
} else {
48+
} else if (relevanceScore < 0.8 && relevanceScore > 0.0) {
4949
classification = 'related';
50+
} else {
51+
classification = 'unrelated';
5052
}
5153

5254
return {

0 commit comments

Comments
 (0)