this repo has no description
0
fork

Configure Feed

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

palomar: improve profile typeahead search quality

- 'and' operation on terms (not 'or')
- special-case '@'-prefixed query as exact handle prefix match
- special-case single-word query to have some boosts on handle prefix
match, and custom domain over bsky.social

+50 -2
+50 -2
search/query.go
··· 7 7 "fmt" 8 8 "io/ioutil" 9 9 "log/slog" 10 + "strings" 10 11 11 12 "github.com/bluesky-social/indigo/atproto/identity" 12 13 ··· 126 127 if err := checkParams(0, size); err != nil { 127 128 return nil, err 128 129 } 130 + 129 131 query := map[string]interface{}{ 130 132 "query": map[string]interface{}{ 131 133 "multi_match": map[string]interface{}{ 132 - "query": q, 133 - "type": "bool_prefix", 134 + "query": q, 135 + "type": "bool_prefix", 136 + "operator": "and", 134 137 "fields": []string{ 138 + "handle^2", 135 139 "typeahead", 136 140 "typeahead._2gram", 137 141 "typeahead._3gram", ··· 139 143 }, 140 144 }, 141 145 "size": size, 146 + } 147 + 148 + // special-case: exact string match of handle 149 + if strings.HasPrefix(q, "@") && !strings.Contains(q, " ") { 150 + q = q[1:] 151 + query["query"] = map[string]interface{}{ 152 + "prefix": map[string]interface{}{ 153 + "handle": map[string]interface{}{ 154 + "value": q, 155 + }, 156 + }, 157 + } 158 + } 159 + 160 + // boost exact handle prefix match, if q is single simple term 161 + if len(q) >= 3 && !strings.ContainsAny(q, " .") { 162 + query["rescore"] = map[string]interface{}{ 163 + "window_size": 100, 164 + "query": map[string]interface{}{ 165 + "rescore_query": map[string]interface{}{ 166 + "boosting": map[string]interface{}{ 167 + "positive": map[string]interface{}{ 168 + "prefix": map[string]interface{}{ 169 + "handle": map[string]interface{}{ 170 + "value": q + ".", 171 + }, 172 + }, 173 + }, 174 + // downrank *.bsky.social (vs custom domain) 175 + // wildcard is expensive, so only in rescore 176 + "negative": map[string]interface{}{ 177 + "wildcard": map[string]interface{}{ 178 + "handle": map[string]interface{}{ 179 + "value": "*.bsky.social", 180 + }, 181 + }, 182 + }, 183 + "negative_boost": 0.5, 184 + }, 185 + }, 186 + "query_weight": 1.0, 187 + "rescore_query_weight": 1.0, 188 + }, 189 + } 142 190 } 143 191 144 192 return doSearch(ctx, escli, index, query)