Skip to content

Commit acda647

Browse files
committed
Reranking hardening | fixing states
1 parent f279d1e commit acda647

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

src/components/map-projects/MapProject.jsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2185,19 +2185,27 @@ const MapProject = () => {
21852185
const service = APIService.concepts().appendToUrl('$rerank/')
21862186
try {
21872187
const response = await service.post({q: query, rows: candidates,});
2188-
log({action: 'rerank_finished'}, index)
2189-
markAlgo(index, 'rerank', 1)
21902188

21912189
setAllCandidates(prev => {
2192-
const newCandidates = {...allCandidatesRef.current}
2190+
const newCandidates = {...prev}
21932191
forEach(keys(prev), algoId => {
2194-
const existingCandidates = [...allCandidatesRef.current[algoId]]
2192+
const existingCandidates = [...(prev[algoId] || [])]
21952193
const ranked = filter(response.data, result => result.search_meta.algorithm === algoId)
2196-
if(ranked.length > 0)
2197-
existingCandidates[findIndex(existingCandidates, match => match.row.__index === index)].results = ranked
2194+
if(ranked.length > 0) {
2195+
const matchIndex = findIndex(existingCandidates, match => match.row.__index === index)
2196+
if(matchIndex > -1) {
2197+
existingCandidates[matchIndex] = {
2198+
...existingCandidates[matchIndex],
2199+
results: ranked
2200+
}
2201+
newCandidates[algoId] = existingCandidates
2202+
}
2203+
}
21982204
})
21992205
return newCandidates
22002206
})
2207+
markAlgo(index, 'rerank', 1)
2208+
log({action: 'rerank_finished'}, index)
22012209
if(isBulk)
22022210
setTimeout(() => setAutoMatched([index]), 1000)
22032211
return response

0 commit comments

Comments
 (0)