From 55ce7bd67d3e405f90eaea7b62447c60ab6ed484 Mon Sep 17 00:00:00 2001 From: Adam Malek Date: Mon, 8 Sep 2025 12:23:48 +0200 Subject: [PATCH] ML in SE: Remove function to declare features (IJPL-202712) Instead - declare it right when declaring the variable. GitOrigin-RevId: 48bdafe6e6dde83416e9c3a106bb9c1536351f99 --- .../SearchEverywhereMLStatisticsCollector.kt | 34 ++++++------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/plugins/search-everywhere-ml/ranking/core/src/com/intellij/searchEverywhereMl/ranking/core/SearchEverywhereMLStatisticsCollector.kt b/plugins/search-everywhere-ml/ranking/core/src/com/intellij/searchEverywhereMl/ranking/core/SearchEverywhereMLStatisticsCollector.kt index a47df49382f5..f615bb6ffbfe 100644 --- a/plugins/search-everywhere-ml/ranking/core/src/com/intellij/searchEverywhereMl/ranking/core/SearchEverywhereMLStatisticsCollector.kt +++ b/plugins/search-everywhere-ml/ranking/core/src/com/intellij/searchEverywhereMl/ranking/core/SearchEverywhereMLStatisticsCollector.kt @@ -200,7 +200,17 @@ object SearchEverywhereMLStatisticsCollector : CounterUsagesCollector() { internal val ACTION_ID_KEY = ActionsEventLogGroup.ACTION_ID @VisibleForTesting - val FEATURES_DATA_KEY: ObjectEventField = createFeaturesEventObject() + val FEATURES_DATA_KEY: ObjectEventField = ObjectEventField( + "features", + *buildList { + addAll(SearchEverywhereElementFeaturesProvider.getDefaultFields()) + + SearchEverywhereElementFeaturesProvider.getFeatureProviders() + .forEach { featuresProvider -> + addAll(featuresProvider.getFeaturesDeclarations()) + } + }.toTypedArray() + ) internal val ML_WEIGHT_KEY: DoubleEventField = EventFields.Double("ml_weight") internal val PRIORITY_KEY: IntEventField = EventFields.Int("priority", "The final priority used for sorting elements") internal val CONTRIBUTOR_FEATURES_LIST = ObjectListEventField( @@ -258,26 +268,4 @@ object SearchEverywhereMLStatisticsCollector : CounterUsagesCollector() { SESSION_ID, CLASSES_WITHOUT_KEY_PROVIDERS_FIELD) // endregion - - - private fun collectNameFeaturesToFields(): Map> { - val nameFeatureToField = hashMapOf>( - *SearchEverywhereElementFeaturesProvider.run { - listOf(NAME_LENGTH, ML_SCORE_KEY, SIMILARITY_SCORE, IS_SEMANTIC_ONLY, BUFFERED_TIMESTAMP) - }.map { it.name to it }.toTypedArray() - ) - nameFeatureToField.putAll(SearchEverywhereElementFeaturesProvider.prefixMatchingNameFeatureToField.values.map { it.name to it }) - nameFeatureToField.putAll(SearchEverywhereElementFeaturesProvider.wholeMatchingNameFeatureToField.values.map { it.name to it }) - for (featureProvider in SearchEverywhereElementFeaturesProvider.getFeatureProviders()) { - nameFeatureToField.putAll(featureProvider.getFeaturesDeclarations().map { - it.name to it - }) - } - return nameFeatureToField - } - - private fun createFeaturesEventObject(): ObjectEventField { - val nameFeatureToField = collectNameFeaturesToFields() - return ObjectEventField("features", *nameFeatureToField.values.toTypedArray()) - } }