Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

performance tweaks to palomar profile typeahead #391

Merged
merged 8 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion search/post_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"settings": {
"index": {
"number_of_shards": 6,
"number_of_replicas": 0,
"number_of_replicas": 1,
"refresh_interval": "5s",
"analysis": {
"analyzer": {
"default": {
Expand Down
4 changes: 3 additions & 1 deletion search/profile_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"settings": {
"index": {
"number_of_shards": 1,
"number_of_replicas": 0,
"number_of_replicas": 1,
"refresh_interval": "5s",
"analysis": {
"analyzer": {
"default": {
Expand Down Expand Up @@ -44,6 +45,7 @@
"doc_index_ts": { "type": "date" },
"did": { "type": "keyword", "normalizer": "default", "doc_values": false },
"handle": { "type": "keyword", "normalizer": "default", "copy_to": ["everything", "typeahead"] },
"record_cid": { "type": "keyword", "normalizer": "default", "doc_values": false },

"display_name": { "type": "text", "analyzer": "textIcu", "search_analyzer": "textIcuSearch", "copy_to": ["everything", "typeahead"] },
"description": { "type": "text", "analyzer": "textIcu", "search_analyzer": "textIcuSearch", "copy_to": "everything" },
Expand Down
31 changes: 19 additions & 12 deletions search/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,8 @@ func DoSearchProfiles(ctx context.Context, dir identity.Directory, escli *es.Cli
queryStr, filters := ParseQuery(ctx, dir, q)
basic := map[string]interface{}{
"simple_query_string": map[string]interface{}{
"query": queryStr,
"fields": []string{
"handle^3",
"display_name^2",
"everything",
},
"query": queryStr,
"fields": []string{"everything"},
"flags": "AND|NOT|OR|PHRASE|PRECEDENCE|WHITESPACE",
"default_operator": "and",
"lenient": true,
Expand Down Expand Up @@ -186,7 +182,8 @@ func DoSearchProfilesTypeahead(ctx context.Context, escli *es.Client, index, q s
"type": "bool_prefix",
"operator": "and",
"fields": []string{
"handle^2",
// adding handle here improves relevency but may be too expensive in prod
//"handle^2",
"typeahead",
"typeahead._2gram",
"typeahead._3gram",
Expand Down Expand Up @@ -215,10 +212,20 @@ func DoSearchProfilesTypeahead(ctx context.Context, escli *es.Client, index, q s
"query": map[string]interface{}{
"rescore_query": map[string]interface{}{
"boosting": map[string]interface{}{
"positive": map[string]interface{}{
"prefix": map[string]interface{}{
"handle": map[string]interface{}{
"value": q + ".",
"positive": []map[string]interface{}{
{
"prefix": map[string]interface{}{
"handle": map[string]interface{}{
"value": q,
},
},
},
// additional boost if it is the full first name
{
"prefix": map[string]interface{}{
"handle": map[string]interface{}{
"value": q + ".",
},
},
},
},
Expand Down Expand Up @@ -266,7 +273,7 @@ func doSearch(ctx context.Context, escli *es.Client, index string, query interfa
if err != nil {
return nil, fmt.Errorf("failed to serialize query: %w", err)
}
slog.Warn("sending query", "index", index, "query", string(b))
slog.Info("sending query", "index", index, "query", string(b))

// Perform the search request.
res, err := escli.Search(
Expand Down