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

DYN-7273 Search Issue Civil3D #15420

Merged
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
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reason behind removing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when searching for criteria like "file path" with MUST we were creating a query like this one (consider that the word 'file' is a Category):

SELECT .... FROM ..... WHERE CATEGORY = 'file' AND (NAME LIKE 'path' or NAME LIKE ''path*)

so it was returning the two nodes in which Category = 'Core.File' that match the criteria related with the Name (the Name should contain 'path'),
But the user is expecting the "file path" node - this one didn't match due that belongs to the Category = "Core.Input" so removing the MUST makes the query more flexible showing also the nodes that matches the Name = 'file path' OR the Category = "Core.File".
Please let me know if this is clear enough.

}
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(' '))
Copy link
Contributor

@zeusongit zeusongit Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we somehow combine this and the hasEmptySpaces flag, so that we do not have to check this twice, and probably avoid some confusion in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will suggest to consider this refactoring for a different Jira task since I remember it generated other problems also the hasEmptySpaces is under a condition that you added probably we will need to think more about it.
image

https://github.com/DynamoDS/Dynamo/pull/15338/files

{
//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));
}
}
}
Loading