Skip to content

Commit

Permalink
DYN-7273 Search Issue Civil3D (#15420)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertGlobant20 authored Aug 16, 2024
1 parent e43ecb6 commit 5dc7213
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/DynamoCore/Utilities/LuceneSearchUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions test/DynamoCoreWpfTests/SearchSideEffects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}

0 comments on commit 5dc7213

Please sign in to comment.