diff --git a/src/DynamoCore/Utilities/LuceneSearchUtility.cs b/src/DynamoCore/Utilities/LuceneSearchUtility.cs index 4224c63e878..c8a3b592fd7 100644 --- a/src/DynamoCore/Utilities/LuceneSearchUtility.cs +++ b/src/DynamoCore/Utilities/LuceneSearchUtility.cs @@ -379,7 +379,6 @@ internal string CreateSearchQuery(string[] fields, string SearchTerm, bool IsPac { //Means that the first term is a category when we will be using the FullCategoryName for making a specific search based in the category trimmedSearchTerm = matchingCategory?.FullCategoryName; - occurQuery = Occur.MUST; } else if (f == nameof(LuceneConfig.NodeFieldsEnum.Name) && firstTermIsCategory == true) { @@ -409,6 +408,22 @@ internal string CreateSearchQuery(string[] fields, string SearchTerm, bool IsPac if (searchTerm.Contains(' ')) { + //Added due that the Search algorithm was not matching the exact name when searchTerm contain empty spaces + if (!string.IsNullOrEmpty(searchTerm) && f == nameof(LuceneConfig.NodeFieldsEnum.Name)) + { + //I had to use the use the WildcardQuery class directly to set the weight(Boost) to the default value (instead of using the one calculated by the CalculateFieldWeight() method + var wildcardQueryWithEmptySpace = new WildcardQuery(new Term(f, "*" + searchTerm + "*")); + + //PhraseQuery will escape whitespace characters trying to match the exact phrase + var phraseQuery = new PhraseQuery + { + new Term(f, searchTerm), + }; + + booleanQuery.Add(phraseQuery, occurQuery); + booleanQuery.Add(wildcardQueryWithEmptySpace, occurQuery); + } + foreach (string s in searchTerm.Split(' ', '.')) { //If is a ByEmptySpace search and the splitted words match with more than MaxNodeNamesRepeated nodes then the word is skipped diff --git a/test/DynamoCoreWpfTests/SearchSideEffects.cs b/test/DynamoCoreWpfTests/SearchSideEffects.cs index 1fb9bc54084..f2f9050e535 100644 --- a/test/DynamoCoreWpfTests/SearchSideEffects.cs +++ b/test/DynamoCoreWpfTests/SearchSideEffects.cs @@ -255,5 +255,24 @@ public void LuceneSearchTSplineNodesOrderingValidation() Assert.That(firstCatExpectedNode == 0); } + + + //This test will validate that File Path node is found when using the criteria "file path" + [Test] + [Category("UnitTests")] + public void LuceneSearchFilePathValidation() + { + Assert.IsAssignableFrom(typeof(HomeWorkspaceModel), ViewModel.Model.CurrentWorkspace); + string searchTerm = "file path"; + + // Search and check that the results are correct based in the node name provided for the searchTerm + var nodesResult = ViewModel.CurrentSpaceViewModel.InCanvasSearchViewModel.Search(searchTerm); + Assert.IsNotNull(nodesResult); + Assert.That(nodesResult.Count(), Is.GreaterThan(0)); + + //Validate that the file path node is in the first 5 elements of the resulting list + var nodesNamesList = nodesResult.Take(5).Select(x => x.Name.ToLower()); + Assert.IsTrue(nodesNamesList.Contains(searchTerm)); + } } }