[READ ONLY MIRROR] Spark Social AppView Server github.com/sprksocial/server
atproto deno hono lexicon
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(search): only return sprk profiles in typeahead

+37 -24
+37 -24
data-plane/routes/search.ts
··· 106 106 const handlePrefix = cleanedTerm.toLowerCase(); 107 107 const handleRangeEnd = `${handlePrefix}\uffff`; 108 108 109 - const [matchingActors, matchingProfiles] = await Promise.all([ 110 - this.db.models.Actor.find({ 111 - handle: { 112 - $gte: handlePrefix, 113 - $lt: handleRangeEnd, 114 - }, 115 - }) 116 - .select("did -_id") 117 - .sort({ handle: 1 }) 118 - .limit(candidateLimit) 119 - .lean(), 120 - this.db.models.Profile.find({ 121 - $text: { $search: cleanedTerm }, 122 - }) 123 - .select("authorDid -_id") 124 - .limit(candidateLimit) 125 - .lean(), 126 - ]); 109 + const matchingActors = await this.db.models.Actor.find({ 110 + handle: { 111 + $gte: handlePrefix, 112 + $lt: handleRangeEnd, 113 + }, 114 + }) 115 + .select("did -_id") 116 + .sort({ handle: 1 }) 117 + .limit(candidateLimit) 118 + .lean(); 119 + 120 + const handleDids = matchingActors.map((actor) => actor.did); 121 + const profileQuery = handleDids.length > 0 122 + ? { 123 + $or: [ 124 + { authorDid: { $in: handleDids } }, 125 + { $text: { $search: cleanedTerm } }, 126 + ], 127 + } 128 + : { $text: { $search: cleanedTerm } }; 129 + const matchingProfiles = await this.db.models.Profile.find(profileQuery) 130 + .select("authorDid -_id") 131 + .limit(candidateLimit * 2) 132 + .lean(); 133 + 134 + const handleDidSet = new Set(handleDids); 135 + const handleProfileDidSet = new Set( 136 + matchingProfiles.map((p) => p.authorDid), 137 + ); 138 + const handleProfileDids = handleDids.filter((did) => 139 + handleProfileDidSet.has(did) 140 + ); 141 + const includedDids = new Set(handleProfileDids); 142 + const textProfileDids = matchingProfiles 143 + .map((profile) => profile.authorDid) 144 + .filter((did) => !includedDids.has(did) && !handleDidSet.has(did)); 127 145 128 - const dids = Array.from( 129 - new Set([ 130 - ...matchingActors.map((actor) => actor.did), 131 - ...matchingProfiles.map((profile) => profile.authorDid), 132 - ]), 133 - ).slice(0, safeLimit); 146 + const dids = [...handleProfileDids, ...textProfileDids].slice(0, safeLimit); 134 147 135 148 return { 136 149 dids,