Skip to content

Commit d75c1d1

Browse files
authored
fix: boost table score for exact match when searching table (pinterest#1097)
1 parent 12520df commit d75c1d1

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

‎querybook/server/lib/elasticsearch/search_table.py‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,18 @@
66
)
77

88

9+
def _get_potential_exact_schema_table_name(keywords):
10+
"""Get the schema and table name from a full table name.
11+
12+
E.g. "default.table_a", will return (default, table_a)
13+
"""
14+
dot_index = keywords.find(".")
15+
if dot_index == -1:
16+
return None, keywords
17+
18+
return keywords[:dot_index], keywords[dot_index + 1 :]
19+
20+
921
def _match_table_word_fields(fields):
1022
search_fields = []
1123
for field in fields:
@@ -44,6 +56,18 @@ def construct_tables_query(
4456
):
4557
keywords_query = {}
4658
if keywords:
59+
should_clause = _match_table_phrase_queries(fields, keywords)
60+
61+
table_schema, table_name = _get_potential_exact_schema_table_name(keywords)
62+
if table_schema:
63+
filters.append(["schema", table_schema])
64+
65+
# boost score for table name exact match
66+
if table_name:
67+
should_clause.append(
68+
{"term": {"name": {"value": table_name, "boost": 100}}},
69+
)
70+
4771
keywords_query = {
4872
"bool": {
4973
"must": {
@@ -54,7 +78,7 @@ def construct_tables_query(
5478
"operator": "and",
5579
},
5680
},
57-
"should": _match_table_phrase_queries(fields, keywords),
81+
"should": should_clause,
5882
}
5983
}
6084
else:

‎querybook/webapp/redux/dataTableSearch/action.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ function mapStateToSearch(state: IDataTableSearchState) {
2828
([_, filterValue]) => filterValue != null
2929
);
3030

31-
const matchSchemaName = searchString.match(/(\w+)\.(\w*)/);
32-
if (matchSchemaName) {
33-
filters.push(['schema', matchSchemaName[1]]);
34-
}
35-
3631
const searchParam = {
3732
metastore_id: state.metastoreId,
3833
keywords: searchString,

0 commit comments

Comments
 (0)