Skip to content

Commit

Permalink
DYN-6535 DynamoRevit Improve Search Fix 2 Code Review
Browse files Browse the repository at this point in the history
Updating Linq query so that is executed only once.
  • Loading branch information
RobertGlobant20 committed Feb 6, 2024
1 parent 5ef4493 commit c62ba64
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/DynamoCore/Utilities/LuceneSearchUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -356,19 +356,22 @@ internal string CreateSearchQuery(string[] fields, string SearchTerm)
{
//Check if the first term of the search criteria match any category
var possibleCategory = searchTerm.Split(' ')[0];
firstTermIsCategory = dynamoModel.SearchModel.Entries.Where(entry => IsMatchingCategory(possibleCategory, entry.FullCategoryName) == true && !string.IsNullOrEmpty(possibleCategory)).Any();
if (string.IsNullOrEmpty(possibleCategory)) continue;

var specificCategoryEntries = dynamoModel.SearchModel.Entries.Where(entry => IsMatchingCategory(possibleCategory, entry.FullCategoryName) == true);
firstTermIsCategory = specificCategoryEntries.Any();

//Get the node matching the Category provided in the search term
var matchingCategory = dynamoModel.SearchModel.Entries.Where(entry => IsMatchingCategory(possibleCategory, entry.FullCategoryName) == true && !string.IsNullOrEmpty(possibleCategory)).FirstOrDefault();
var matchingCategory = specificCategoryEntries.FirstOrDefault();
if (matchingCategory == null && firstTermIsCategory == true) continue;

if (f == nameof(LuceneConfig.NodeFieldsEnum.FullCategoryName) && firstTermIsCategory)
if (f == nameof(LuceneConfig.NodeFieldsEnum.FullCategoryName) && firstTermIsCategory == true)
{
//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)
else if (f == nameof(LuceneConfig.NodeFieldsEnum.Name) && firstTermIsCategory == true)
{
//If the field being iterated is Name and we are sure that the first term is a Category when we remove the term from the string so we can search for the specific node Name
trimmedSearchTerm = trimmedSearchTerm?.Replace(possibleCategory, string.Empty);
Expand Down

0 comments on commit c62ba64

Please sign in to comment.