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

Fix #14694: Search - Change default operator to OR instead of AND #14695

Merged
merged 5 commits into from
Jan 16, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,15 @@ public Response search(SearchRequest request) throws IOException {
request.getQuery(), request.getFrom(), request.getSize());
case "test_case_resolution_status_search_index" -> buildTestCaseResolutionStatusSearch(
request.getQuery(), request.getFrom(), request.getSize());
case "mlmodel_service_search_index",
"database_service_search_index",
"messaging_service_index",
"dashboard_service_index",
"pipeline_service_index",
"storage_service_index",
"search_service_index",
"metadata_service_index" -> buildServiceSearchBuilder(
request.getQuery(), request.getFrom(), request.getSize());
default -> buildAggregateSearchBuilder(
request.getQuery(), request.getFrom(), request.getSize());
};
Expand Down Expand Up @@ -654,7 +663,6 @@ private static SearchSourceBuilder buildTopicSearchBuilder(String query, int fro
QueryStringQueryBuilder queryBuilder =
QueryBuilders.queryStringQuery(query)
.fields(TopicIndex.getFields())
.defaultOperator(Operator.AND)
.fuzziness(Fuzziness.AUTO);
HighlightBuilder.Field highlightTopicName = new HighlightBuilder.Field(FIELD_DISPLAY_NAME);
highlightTopicName.highlighterType(UNIFIED);
Expand Down Expand Up @@ -713,9 +721,9 @@ private static SearchSourceBuilder buildTableSearchBuilder(String query, int fro
QueryStringQueryBuilder queryStringBuilder =
QueryBuilders.queryStringQuery(query)
.fields(TableIndex.getFields())
.type(MultiMatchQueryBuilder.Type.BEST_FIELDS)
.defaultOperator(Operator.AND)
.fuzziness(Fuzziness.AUTO);
.type(MultiMatchQueryBuilder.Type.MOST_FIELDS)
.tieBreaker(0.9f);

FieldValueFactorFunctionBuilder boostScoreBuilder =
ScoreFunctionBuilders.fieldValueFactorFunction("usageSummary.weeklyStats.count")
.missing(0)
Expand Down Expand Up @@ -1020,6 +1028,21 @@ private static SearchSourceBuilder buildTestCaseResolutionStatusSearch(
return searchBuilder(queryBuilder, hb, from, size);
}

private static SearchSourceBuilder buildServiceSearchBuilder(String query, int from, int size) {
QueryStringQueryBuilder queryBuilder =
buildSearchQueryBuilder(query, SearchIndex.getDefaultFields());

HighlightBuilder hb = new HighlightBuilder();
HighlightBuilder.Field highlightServiceName = new HighlightBuilder.Field(FIELD_DISPLAY_NAME);
highlightServiceName.highlighterType(UNIFIED);
HighlightBuilder.Field highlightDescription = new HighlightBuilder.Field(FIELD_DESCRIPTION);
highlightDescription.highlighterType(UNIFIED);

hb.field(highlightServiceName);
hb.field(highlightDescription);
return searchBuilder(queryBuilder, hb, from, size);
}

private static SearchSourceBuilder buildDataProductSearch(String query, int from, int size) {
QueryStringQueryBuilder queryBuilder =
buildSearchQueryBuilder(query, DataProductIndex.getFields());
Expand All @@ -1046,17 +1069,13 @@ private static SearchSourceBuilder buildDataProductSearch(String query, int from

private static QueryStringQueryBuilder buildSearchQueryBuilder(
String query, Map<String, Float> fields) {
return QueryBuilders.queryStringQuery(query)
.fields(fields)
.defaultOperator(Operator.AND)
.fuzziness(Fuzziness.AUTO);
return QueryBuilders.queryStringQuery(query).fields(fields).fuzziness(Fuzziness.AUTO);
}

private static SearchSourceBuilder buildAggregateSearchBuilder(String query, int from, int size) {
QueryStringQueryBuilder queryBuilder =
QueryBuilders.queryStringQuery(query)
.fields(SearchIndex.getAllFields())
.defaultOperator(Operator.AND)
.fuzziness(Fuzziness.AUTO);
SearchSourceBuilder searchSourceBuilder = searchBuilder(queryBuilder, null, from, size);
return addAggregation(searchSourceBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.openmetadata.schema.entity.data.Container;
import org.openmetadata.schema.type.TagLabel;
import org.openmetadata.service.Entity;
Expand Down Expand Up @@ -68,7 +67,7 @@ public Map<String, Object> buildESDoc() {
"fqnParts",
getFQNParts(
container.getFullyQualifiedName(),
suggest.stream().map(SearchSuggest::getInput).collect(Collectors.toList())));
suggest.stream().map(SearchSuggest::getInput).toList()));
doc.put("owner", getEntityWithDisplayName(container.getOwner()));
doc.put("service", getEntityWithDisplayName(container.getService()));
doc.put("domain", getEntityWithDisplayName(container.getDomain()));
Expand All @@ -79,9 +78,7 @@ public static Map<String, Float> getFields() {
Map<String, Float> fields = SearchIndex.getDefaultFields();
fields.put("dataModel.columns.name", 2.0f);
fields.put(DATA_MODEL_COLUMNS_NAME_KEYWORD, 10.0f);
fields.put("dataModel.columns.name.ngram", 1.0f);
fields.put("dataModel.columns.displayName", 2.0f);
fields.put("dataModel.columns.displayName.ngram", 1.0f);
fields.put("dataModel.columns.description", 1.0f);
fields.put("dataModel.columns.children.name", 2.0f);
return fields;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.openmetadata.schema.entity.data.DashboardDataModel;
import org.openmetadata.schema.type.TagLabel;
import org.openmetadata.service.Entity;
Expand Down Expand Up @@ -62,7 +61,7 @@ public Map<String, Object> buildESDoc() {
"fqnParts",
getFQNParts(
dashboardDataModel.getFullyQualifiedName(),
suggest.stream().map(SearchSuggest::getInput).collect(Collectors.toList())));
suggest.stream().map(SearchSuggest::getInput).toList()));
doc.put("tier", parseTags.getTierTag());
doc.put("owner", getEntityWithDisplayName(dashboardDataModel.getOwner()));
doc.put("service", getEntityWithDisplayName(dashboardDataModel.getService()));
Expand All @@ -75,7 +74,6 @@ public static Map<String, Float> getFields() {
Map<String, Float> fields = SearchIndex.getDefaultFields();
fields.put(COLUMNS_NAME_KEYWORD, 10.0f);
fields.put("columns.name", 2.0f);
fields.put("columns.name.ngram", 1.0f);
fields.put("columns.displayName", 1.0f);
fields.put("columns.description", 1.0f);
fields.put("columns.children.name", 2.0f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.openmetadata.schema.entity.domains.DataProduct;
import org.openmetadata.service.Entity;
import org.openmetadata.service.search.SearchIndexUtils;
Expand All @@ -24,7 +23,7 @@ public Map<String, Object> buildESDoc() {
"fqnParts",
getFQNParts(
dataProduct.getFullyQualifiedName(),
suggest.stream().map(SearchSuggest::getInput).collect(Collectors.toList())));
suggest.stream().map(SearchSuggest::getInput).toList()));
doc.put("entityType", Entity.DATA_PRODUCT);
doc.put("owner", getEntityWithDisplayName(dataProduct.getOwner()));
doc.put("domain", getEntityWithDisplayName(dataProduct.getDomain()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public static Map<String, Float> getFields() {
fields.put("synonyms.ngram", 1.0f);
fields.put("glossary.name", 5.0f);
fields.put("glossary.displayName", 5.0f);
fields.put("glossary.displayName.ngram", 1.0f);
return fields;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.openmetadata.schema.entity.data.MlModel;
import org.openmetadata.service.Entity;
import org.openmetadata.service.search.ParseTags;
Expand Down Expand Up @@ -41,7 +40,7 @@ public Map<String, Object> buildESDoc() {
"fqnParts",
getFQNParts(
mlModel.getFullyQualifiedName(),
suggest.stream().map(SearchSuggest::getInput).collect(Collectors.toList())));
suggest.stream().map(SearchSuggest::getInput).toList()));
doc.put("owner", getEntityWithDisplayName(mlModel.getOwner()));
doc.put("service", getEntityWithDisplayName(mlModel.getService()));
doc.put("domain", getEntityWithDisplayName(mlModel.getDomain()));
Expand All @@ -50,7 +49,7 @@ public Map<String, Object> buildESDoc() {

public static Map<String, Float> getFields() {
Map<String, Float> fields = SearchIndex.getDefaultFields();
fields.put("mlFeatures.name", 2.0f);
fields.put("mlFeatures.name", 8.0f);
fields.put("mlFeatures.description", 1.0f);
return fields;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.openmetadata.schema.entity.data.Pipeline;
import org.openmetadata.schema.type.Task;
import org.openmetadata.service.Entity;
Expand Down Expand Up @@ -53,7 +52,7 @@ public Map<String, Object> buildESDoc() {
"fqnParts",
getFQNParts(
pipeline.getFullyQualifiedName(),
suggest.stream().map(SearchSuggest::getInput).collect(Collectors.toList())));
suggest.stream().map(SearchSuggest::getInput).toList()));
doc.put("owner", getEntityWithDisplayName(pipeline.getOwner()));
doc.put("service", getEntityWithDisplayName(pipeline.getService()));
doc.put("domain", getEntityWithDisplayName(pipeline.getDomain()));
Expand All @@ -62,7 +61,7 @@ public Map<String, Object> buildESDoc() {

public static Map<String, Float> getFields() {
Map<String, Float> fields = SearchIndex.getDefaultFields();
fields.put("tasks.name", 2.0f);
fields.put("tasks.name", 8.0f);
fields.put("tasks.description", 1.0f);
return fields;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.openmetadata.schema.entity.data.Query;
import org.openmetadata.service.Entity;
import org.openmetadata.service.search.ParseTags;
Expand Down Expand Up @@ -40,8 +39,7 @@ public Map<String, Object> buildESDoc() {
doc.put(
"fqnParts",
getFQNParts(
query.getFullyQualifiedName(),
suggest.stream().map(SearchSuggest::getInput).collect(Collectors.toList())));
query.getFullyQualifiedName(), suggest.stream().map(SearchSuggest::getInput).toList()));
return doc;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.openmetadata.service.Entity;
import org.openmetadata.service.search.ParseTags;
import org.openmetadata.service.search.SearchIndexUtils;
Expand All @@ -27,7 +26,7 @@ public Map<String, Object> buildESDoc() {
"fqnParts",
getFQNParts(
searchIndex.getFullyQualifiedName(),
suggest.stream().map(SearchSuggest::getInput).collect(Collectors.toList())));
suggest.stream().map(SearchSuggest::getInput).toList()));
ParseTags parseTags = new ParseTags(Entity.getEntityTags(Entity.SEARCH_INDEX, searchIndex));
doc.put("tags", parseTags.getTags());
doc.put("tier", parseTags.getTierTag());
Expand All @@ -40,10 +39,11 @@ public Map<String, Object> buildESDoc() {

public static Map<String, Float> getFields() {
Map<String, Float> fields = SearchIndex.getDefaultFields();
fields.put("fields.name", 2.0f);
fields.put("fields.name.keyword", 2.0f);
fields.put("fields.name", 7.0f);
fields.put("fields.name.keyword", 50f);
fields.put("fields.children.description", 1.0f);
fields.put("fields.children.name", 2.0f);
fields.put("fields.children.name", 7.0f);
fields.put("fields.children.name.keyword", 5.0f);
return fields;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import static org.openmetadata.service.Entity.FIELD_DISPLAY_NAME;
import static org.openmetadata.service.Entity.FIELD_NAME;
import static org.openmetadata.service.search.EntityBuilderConstant.DISPLAY_NAME_KEYWORD;
import static org.openmetadata.service.search.EntityBuilderConstant.FIELD_DISPLAY_NAME_NGRAM;
import static org.openmetadata.service.search.EntityBuilderConstant.FIELD_NAME_NGRAM;
import static org.openmetadata.service.search.EntityBuilderConstant.FULLY_QUALIFIED_NAME;
import static org.openmetadata.service.search.EntityBuilderConstant.FULLY_QUALIFIED_NAME_PARTS;
import static org.openmetadata.service.search.EntityBuilderConstant.NAME_KEYWORD;
Expand Down Expand Up @@ -134,15 +132,13 @@ static void getLineageDataDirection(

static Map<String, Float> getDefaultFields() {
Map<String, Float> fields = new HashMap<>();
fields.put(FIELD_DISPLAY_NAME, 15.0f);
fields.put(FIELD_DISPLAY_NAME_NGRAM, 1.0f);
fields.put(FIELD_NAME, 15.0f);
fields.put(FIELD_NAME_NGRAM, 1.0f);
fields.put(DISPLAY_NAME_KEYWORD, 25.0f);
fields.put(NAME_KEYWORD, 25.0f);
fields.put(FIELD_DISPLAY_NAME, 10.0f);
fields.put(FIELD_NAME, 10.0f);
fields.put(DISPLAY_NAME_KEYWORD, 8.0f);
fields.put(NAME_KEYWORD, 8.0f);
fields.put(FIELD_DESCRIPTION, 1.0f);
fields.put(FULLY_QUALIFIED_NAME, 10.0f);
fields.put(FULLY_QUALIFIED_NAME_PARTS, 10.0f);
fields.put(FULLY_QUALIFIED_NAME, 5.0f);
fields.put(FULLY_QUALIFIED_NAME_PARTS, 5.0f);
return fields;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.openmetadata.schema.entity.services.SearchService;
import org.openmetadata.service.Entity;
import org.openmetadata.service.search.SearchIndexUtils;
Expand All @@ -26,7 +25,7 @@ public Map<String, Object> buildESDoc() {
"fqnParts",
getFQNParts(
searchService.getFullyQualifiedName(),
suggest.stream().map(SearchSuggest::getInput).collect(Collectors.toList())));
suggest.stream().map(SearchSuggest::getInput).toList()));
doc.put("owner", getEntityWithDisplayName(searchService.getOwner()));
return doc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.openmetadata.schema.entity.services.StorageService;
import org.openmetadata.service.Entity;
import org.openmetadata.service.search.SearchIndexUtils;
Expand All @@ -24,7 +23,7 @@ public Map<String, Object> buildESDoc() {
"fqnParts",
getFQNParts(
storageService.getFullyQualifiedName(),
suggest.stream().map(SearchSuggest::getInput).collect(Collectors.toList())));
suggest.stream().map(SearchSuggest::getInput).toList()));
doc.put("suggest", suggest);
doc.put("entityType", Entity.STORAGE_SERVICE);
doc.put("owner", getEntityWithDisplayName(storageService.getOwner()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.openmetadata.schema.entity.data.StoredProcedure;
import org.openmetadata.service.Entity;
import org.openmetadata.service.search.ParseTags;
Expand All @@ -25,7 +24,7 @@ public Map<String, Object> buildESDoc() {
"fqnParts",
getFQNParts(
storedProcedure.getFullyQualifiedName(),
suggest.stream().map(SearchSuggest::getInput).collect(Collectors.toList())));
suggest.stream().map(SearchSuggest::getInput).toList()));
doc.put("suggest", suggest);
doc.put("entityType", Entity.STORED_PROCEDURE);
ParseTags parseTags =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,11 @@ private void parseTableSuggest(List<SearchSuggest> suggest) {

public static Map<String, Float> getFields() {
Map<String, Float> fields = SearchIndex.getDefaultFields();
fields.put(COLUMNS_NAME_KEYWORD, 10.0f);
fields.put("columns.name", 2.0f);
fields.put("columns.name.ngram", 1.0f);
fields.put("columns.displayName", 1.0f);
fields.put(COLUMNS_NAME_KEYWORD, 5.0f);
fields.put("columns.name", 7.0f);
fields.put("columns.displayName", 7.0f);
fields.put("columns.description", 1.0f);
fields.put("columns.children.name", 2.0f);
fields.put("columns.children.name", 7.0f);
return fields;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.openmetadata.schema.entity.classification.Tag;
import org.openmetadata.service.Entity;
import org.openmetadata.service.search.SearchIndexUtils;
Expand All @@ -22,8 +21,7 @@ public Map<String, Object> buildESDoc() {
doc.put(
"fqnParts",
getFQNParts(
tag.getFullyQualifiedName(),
suggest.stream().map(SearchSuggest::getInput).collect(Collectors.toList())));
tag.getFullyQualifiedName(), suggest.stream().map(SearchSuggest::getInput).toList()));
if (tag.getDisabled() != null && tag.getDisabled()) {
doc.put("disabled", tag.getDisabled());
} else {
Expand All @@ -36,7 +34,7 @@ public Map<String, Object> buildESDoc() {

public static Map<String, Float> getFields() {
Map<String, Float> fields = SearchIndex.getDefaultFields();
fields.put("classification.name", 1.0f);
fields.put("classification.name", 7.0f);
return fields;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public static Map<String, Float> getFields() {
Map<String, Float> fields = SearchIndex.getDefaultFields();
fields.put("testSuite.fullyQualifiedName", 10.0f);
fields.put("testSuite.name", 10.0f);
fields.put("testSuite.description", 3.0f);
fields.put("testSuite.description", 1.0f);
fields.put("entityLink", 3.0f);
fields.put("entityFQN", 10.0f);
return fields;
Expand Down
Loading
Loading