this repo has no description
0
fork

Configure Feed

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

palomar: update hashtags ('tag') schema and remove text parse

+18 -29
+1 -1
search/post_schema.json
··· 59 59 "embed_img_alt_text": { "type": "text", "analyzer": "textIcu", "search_analyzer": "textIcuSearch", "copy_to": "everything" }, 60 60 "self_label": { "type": "keyword", "normalizer": "default" }, 61 61 62 - "hashtag": { "type": "keyword", "normalizer": "default" }, 62 + "tag": { "type": "keyword", "normalizer": "default" }, 63 63 "emoji": { "type": "keyword", "normalizer": "caseSensitive" }, 64 64 65 65 "everything": { "type": "text", "analyzer": "textIcu", "search_analyzer": "textIcuSearch" },
+1 -1
search/profile_schema.json
··· 50 50 "img_alt_text": { "type": "text", "analyzer": "textIcu", "search_analyzer": "textIcuSearch", "copy_to": "everything" }, 51 51 "self_label": { "type": "keyword", "normalizer": "default" }, 52 52 53 - "hashtag": { "type": "keyword", "normalizer": "default" }, 53 + "tag": { "type": "keyword", "normalizer": "default" }, 54 54 "emoji": { "type": "keyword", "normalizer": "caseSensitive" }, 55 55 56 56 "has_avatar": { "type": "boolean" },
-1
search/testdata/transform-post-fixtures.json
··· 114 114 "lang_code": ["th", "en-US"], 115 115 "lang_code_iso2": ["th", "en"], 116 116 "self_label": ["nudity"], 117 - "hashtag": ["some", "hashtags"], 118 117 "emoji": ["\u2620", "\ud83d\ude42", "\ud83c\udf85\ud83c\udfff", "\ud83c\uddf8\ud83c\udde8"], 119 118 "embed_img_count": 0 120 119 }
-1
search/testdata/transform-profile-fixtures.json
··· 55 55 "description": "Big Description 🥸 #cheese", 56 56 "self_label": ["nudity"], 57 57 "emoji": ["🥸"], 58 - "hashtag": ["cheese"], 59 58 "has_avatar": true, 60 59 "has_banner": true 61 60 }
+16 -15
search/transform.go
··· 1 1 package search 2 2 3 3 import ( 4 - "regexp" 5 4 "strings" 6 5 "time" 7 6 ··· 20 19 Description *string `json:"description,omitempty"` 21 20 ImgAltText []string `json:"img_alt_text,omitempty"` 22 21 SelfLabel []string `json:"self_label,omitempty"` 23 - Hashtag []string `json:"hashtag,omitempty"` 22 + Tag []string `json:"tag,omitempty"` 24 23 Emoji []string `json:"emoji,omitempty"` 25 24 HasAvatar bool `json:"has_avatar"` 26 25 HasBanner bool `json:"has_banner"` ··· 43 42 EmbedImgCount int `json:"embed_img_count"` 44 43 EmbedImgAltText []string `json:"embed_img_alt_text,omitempty"` 45 44 SelfLabel []string `json:"self_label,omitempty"` 46 - Hashtag []string `json:"hashtag,omitempty"` 45 + Tag []string `json:"tag,omitempty"` 47 46 Emoji []string `json:"emoji,omitempty"` 48 47 } 49 48 ··· 64 63 func TransformProfile(profile *appbsky.ActorProfile, ident *identity.Identity, cid string) ProfileDoc { 65 64 // TODO: placeholder for future alt text on profile blobs 66 65 var altText []string 67 - var hashtags []string 66 + var tags []string 68 67 var emojis []string 69 68 if profile.Description != nil { 70 - hashtags = parseHashtags(*profile.Description) 69 + tags = parseProfileTags(profile) 71 70 emojis = parseEmojis(*profile.Description) 72 71 } 73 72 var selfLabels []string ··· 89 88 Description: profile.Description, 90 89 ImgAltText: altText, 91 90 SelfLabel: selfLabels, 92 - Hashtag: hashtags, 91 + Tag: tags, 93 92 Emoji: emojis, 94 93 HasAvatar: profile.Avatar != nil, 95 94 HasBanner: profile.Banner != nil, ··· 173 172 EmbedImgCount: embedImgCount, 174 173 EmbedImgAltText: embedImgAltText, 175 174 SelfLabel: selfLabels, 176 - Hashtag: parseHashtags(post.Text), 175 + Tag: parsePostTags(post), 177 176 Emoji: parseEmojis(post.Text), 178 177 } 179 178 ··· 184 183 return doc 185 184 } 186 185 187 - func parseHashtags(s string) []string { 188 - var hashtagRegex = regexp.MustCompile(`\B#([A-Za-z]+)\b`) 186 + func parseProfileTags(p *appbsky.ActorProfile) []string { 187 + // TODO: waiting for profile tag lexicon support 189 188 var ret []string = []string{} 190 - seen := make(map[string]bool) 191 - for _, m := range hashtagRegex.FindAllStringSubmatch(s, -1) { 192 - if seen[m[1]] == false { 193 - ret = append(ret, m[1]) 194 - seen[m[1]] = true 195 - } 189 + if len(ret) == 0 { 190 + return nil 196 191 } 192 + return ret 193 + } 194 + 195 + func parsePostTags(p *appbsky.FeedPost) []string { 196 + // TODO: waiting for post tag lexicon support (indigo codegen) 197 + var ret []string = []string{} 197 198 if len(ret) == 0 { 198 199 return nil 199 200 }
-10
search/transform_test.go
··· 13 13 "github.com/stretchr/testify/assert" 14 14 ) 15 15 16 - func TestParseHashtags(t *testing.T) { 17 - assert := assert.New(t) 18 - 19 - assert.Equal(parseHashtags("#basic post with #HashTag #examples"), []string{"basic", "HashTag", "examples"}) 20 - assert.Equal(parseHashtags("#dedupe #dedupe"), []string{"dedupe"}) 21 - assert.Equal(parseHashtags("##double"), []string{"double"}) 22 - assert.Equal(parseHashtags("#with-punc"), []string{"with"}) 23 - assert.True(parseHashtags("not https://example.com/thing#fragment") == nil) 24 - } 25 - 26 16 func TestParseEmojis(t *testing.T) { 27 17 assert := assert.New(t) 28 18