improve search logic

This commit is contained in:
kawamataryo 2023-10-12 09:26:38 +09:00
parent f05ea60765
commit 29f51f2d52
2 changed files with 15 additions and 13 deletions

View File

@ -39,7 +39,7 @@ export const isSimilarUser = (names: Names, bskyProfile: ProfileView | undefined
} }
} }
if (bskyProfile.description?.toLocaleLowerCase().includes(lowerCaseNames.accountName)) { if (bskyProfile.description?.toLocaleLowerCase().includes(`@${lowerCaseNames.accountName}`)) {
return { return {
isSimilar: true, isSimilar: true,
type: BSKY_USER_MATCH_TYPE.DESCRIPTION, type: BSKY_USER_MATCH_TYPE.DESCRIPTION,

View File

@ -61,27 +61,29 @@ export const searchAndInsertBskyUsers = async (
let matchType = null let matchType = null
// Loop over search parameters and break if a user is found // Loop over search parameters and break if a user is found
for (const term of searchTerms) { searchLoop: for (const term of searchTerms) {
// one symbol is not a valid search term for bsky // one symbol is not a valid search term for bsky
if (!term || isOneSymbol(term)) { if (!term || isOneSymbol(term)) {
continue continue
} }
try { try {
const [searchResult] = await agent.searchUser({ const searchResults = await agent.searchUser({
term: term, term: term,
limit: 1, limit: 3,
}) })
const { isSimilar: isUserFound, type } = isSimilarUser({ for (const searchResult of searchResults) {
accountName: twAccountName, const { isSimilar: isUserFound, type } = isSimilarUser({
accountNameRemoveUnderscore: twAccountNameRemoveUnderscore, accountName: twAccountName,
displayName: twDisplayName, accountNameRemoveUnderscore: twAccountNameRemoveUnderscore,
}, searchResult) displayName: twDisplayName,
}, searchResult)
if (isUserFound) { if (isUserFound) {
targetAccount = searchResult targetAccount = searchResult
matchType = type matchType = type
break; // Stop searching when a user is found break searchLoop; // Stop searching when a user is found
}
} }
} catch (e) { } catch (e) {
console.error(e) console.error(e)