Skip to content

Commit

Permalink
#146 cleanup and rename getSearchScoreV2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonatai committed Jan 26, 2024
1 parent b6a328d commit 1288edd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/components/Search/SearchInput/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { faMagnifyingGlass } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

import { useGenerateSearchEntries } from '../../../Hooks/useGenerateSearchEntries';
import { getSearchScoreV2TS } from '../getSearchScoreV2';
import { getSearchScoreV2TS } from '../getSearchScore';

export const SearchInput = (props: ISearchInput): JSX.Element => {
const { summary, setSearchHits, setSearchInput, searchInput } = props;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ export const getSearchScoreV2TS = (

specification.features.forEach((feature) => {
const normalizedFeature = normalizeString(feature.id);

const featureScore = featureSearchScore(
searchTerm,
normalizedFeature
);
score += featureScore;
featureScores.push({
id: feature.id,
score: featureScore,
});

score += featureScore;
});

const sortedFeatureScores = featureScores.sort(sortScore);
Expand All @@ -53,8 +55,7 @@ export const getSearchScoreV2TS = (
return chosen;
};

const getTop25 = (sortedScores: IScore[]) =>
sortedScores.filter((score) => score.score > 0).slice(0, 25);
const getTop25 = (sortedScores: IScore[]) => sortedScores.slice(0, 25);

const sortScore = (
scoreA: IScore | IFeatureScore,
Expand All @@ -67,17 +68,11 @@ const normalizeString = (term: string) => {

const getSearchWordsScore = (searchWords: string[], searchTerm: string) => {
let searchWordsScore = 0;
if (searchWords.length > 1) {
searchWords.forEach((word) => {
if (word.length === 0) {
searchWordsScore += 0;
}

if (word.includes(searchTerm)) {
searchWordsScore += 0.25;
}
});
}
searchWords.forEach((word) => {
if (word.includes(searchTerm)) {
searchWordsScore += 0.25;
}
});

return searchWordsScore;
};
Expand Down Expand Up @@ -171,6 +166,7 @@ const removeFillWords = (sentence: string) =>
const fillWords = [
'the',
'a',
'an',
'of',
'and',
'or',
Expand All @@ -191,7 +187,6 @@ const fillWords = [
'with',
'by',
'for',
'an',
];

const replaceCharSet = ['.', '`', ',', '"', '?', '_'];
Expand Down

0 comments on commit 1288edd

Please sign in to comment.