From 1aa215a4f9888c7bb325f8277ca403f66a8ee4aa Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Thu, 20 Jun 2024 14:58:57 -0400 Subject: [PATCH 1/3] add pkg author to search index --- src/DynamoCore/Configuration/LuceneConfig.cs | 10 ++++++++-- .../Utilities/LuceneSearchUtility.cs | 18 ++++++++++-------- .../PackageManagerSearchViewModel.cs | 3 ++- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/DynamoCore/Configuration/LuceneConfig.cs b/src/DynamoCore/Configuration/LuceneConfig.cs index b894de80c29..363bce391aa 100644 --- a/src/DynamoCore/Configuration/LuceneConfig.cs +++ b/src/DynamoCore/Configuration/LuceneConfig.cs @@ -185,7 +185,12 @@ public enum NodeFieldsEnum /// /// Node Input Parameters as string (there are nodes with same name and category but different parameters) /// - Parameters + Parameters, + + /// + /// Package author name + /// + Author } /// @@ -208,6 +213,7 @@ public enum NodeFieldsEnum public static string[] PackageIndexFields = { nameof(NodeFieldsEnum.Name), nameof(NodeFieldsEnum.Description), nameof(NodeFieldsEnum.SearchKeywords), - nameof(NodeFieldsEnum.Hosts)}; + nameof(NodeFieldsEnum.Hosts), + nameof(NodeFieldsEnum.Author)}; } } diff --git a/src/DynamoCore/Utilities/LuceneSearchUtility.cs b/src/DynamoCore/Utilities/LuceneSearchUtility.cs index 77cc6d85880..752584286be 100644 --- a/src/DynamoCore/Utilities/LuceneSearchUtility.cs +++ b/src/DynamoCore/Utilities/LuceneSearchUtility.cs @@ -214,10 +214,11 @@ internal Document InitializeIndexDocumentForPackages() var description = new TextField(nameof(LuceneConfig.NodeFieldsEnum.Description), string.Empty, Field.Store.YES); var keywords = new TextField(nameof(LuceneConfig.NodeFieldsEnum.SearchKeywords), string.Empty, Field.Store.YES); var hosts = new TextField(nameof(LuceneConfig.NodeFieldsEnum.Hosts), string.Empty, Field.Store.YES); + var author = new TextField(nameof(LuceneConfig.NodeFieldsEnum.Author), string.Empty, Field.Store.YES); var d = new Document() { - name, description, keywords, hosts + name, description, keywords, hosts, author }; return d; } @@ -295,7 +296,7 @@ private bool IsMatchingCategory(string term, string FullCategoryName) /// All fields to be searched in. /// Search key to be searched for. /// - internal string CreateSearchQuery(string[] fields, string SearchTerm) + internal string CreateSearchQuery(string[] fields, string SearchTerm, bool IsPackageContext = false) { //By Default the search will be normal SearchType searchType = SearchType.Normal; @@ -314,12 +315,13 @@ internal string CreateSearchQuery(string[] fields, string SearchTerm) var booleanQuery = new BooleanQuery(); string searchTerm = QueryParser.Escape(SearchTerm); - if (searchTerm.Contains('.')) - searchType = SearchType.ByCategory; - else if (searchTerm.Contains(' ')) - hasEmptySpaces = true; - else - searchType = SearchType.Normal; + if (!IsPackageContext) + { + if (searchTerm.Contains('.')) + searchType = SearchType.ByCategory; + else if (searchTerm.Contains(' ')) + hasEmptySpaces = true; + } var trimmedSearchTerm = hasEmptySpaces == true ? searchTerm.Replace(" ", "") : searchTerm; diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerSearchViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerSearchViewModel.cs index 84776f6f74f..383a0994fbe 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerSearchViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerSearchViewModel.cs @@ -593,6 +593,7 @@ internal void AddPackageToSearchIndex(PackageManagerSearchElement package, Docum LuceneUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.Name), package.Name); LuceneUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.Description), package.Description); + LuceneUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.Author), package.Maintainers); if (package.Keywords.Length > 0) { @@ -1457,7 +1458,7 @@ internal IEnumerable Search(string searchT FuzzyMinSim = LuceneConfig.MinimumSimilarity }; - Query query = parser.Parse(LuceneUtility.CreateSearchQuery(LuceneConfig.PackageIndexFields, searchTerm)); + Query query = parser.Parse(LuceneUtility.CreateSearchQuery(LuceneConfig.PackageIndexFields, searchTerm, true)); //indicate we want the first 50 results TopDocs topDocs = LuceneUtility.Searcher.Search(query, n: LuceneConfig.DefaultResultsCount); From c208d6d360b632798802a0925d67acb85a1e291a Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Thu, 20 Jun 2024 15:12:41 -0400 Subject: [PATCH 2/3] Update LuceneSearchUtility.cs --- src/DynamoCore/Utilities/LuceneSearchUtility.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/DynamoCore/Utilities/LuceneSearchUtility.cs b/src/DynamoCore/Utilities/LuceneSearchUtility.cs index 752584286be..4224c63e878 100644 --- a/src/DynamoCore/Utilities/LuceneSearchUtility.cs +++ b/src/DynamoCore/Utilities/LuceneSearchUtility.cs @@ -295,6 +295,7 @@ private bool IsMatchingCategory(string term, string FullCategoryName) /// /// All fields to be searched in. /// Search key to be searched for. + /// Set this to true if the search context is packages instead of nodes. /// internal string CreateSearchQuery(string[] fields, string SearchTerm, bool IsPackageContext = false) { From 335c94357bed5d2bd5f02f81ff21337cf970ddc2 Mon Sep 17 00:00:00 2001 From: Ashish Aggarwal Date: Thu, 20 Jun 2024 16:19:28 -0400 Subject: [PATCH 3/3] add maintainers for test --- .../PackageManagerSearchElementViewModelTests.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/DynamoCoreWpfTests/PackageManager/PackageManagerSearchElementViewModelTests.cs b/test/DynamoCoreWpfTests/PackageManager/PackageManagerSearchElementViewModelTests.cs index 8ae630e8e3c..29ef0653d92 100644 --- a/test/DynamoCoreWpfTests/PackageManager/PackageManagerSearchElementViewModelTests.cs +++ b/test/DynamoCoreWpfTests/PackageManager/PackageManagerSearchElementViewModelTests.cs @@ -537,8 +537,8 @@ public void PackageSearchDialogSearchTestDependencyFilters() packageManagerSearchViewModel.NonHostFilter[3].FilterCommand.Execute(string.Empty); Assert.IsFalse(packageManagerSearchViewModel.NonHostFilter[4].OnChecked); } - - /// + + /// /// This unit test will validate that we can search packages in different languages and they will be found. /// [Test] @@ -549,6 +549,7 @@ public void PackageSearchDialogSearchDifferentLanguage() string packageVersionNumber = "1.0.0.0"; string packageCreatedDateString = "2016 - 12 - 02T13:13:20.135000 + 00:00"; string formItFilterName = "FormIt"; + var packageMaintainer = new User(){ username = "DynamoTest", _id = "90-63-17" }; //Packages list List packagesNameDifferentLanguages = new List { "paquete", "упаковка", "包裹" }; @@ -579,6 +580,7 @@ public void PackageSearchDialogSearchDifferentLanguage() name = package, versions = new List { tmpPackageVersion }, host_dependencies = new List { formItFilterName }, + maintainers = new List { packageMaintainer }, }), false); packageManagerSearchViewModel.AddToSearchResults(tmpPackage); }