Skip to content

Commit

Permalink
DYN-6055 Lucene Search Category Based Code Review
Browse files Browse the repository at this point in the history
I've added more comments
I've changed the validation for always taking the last two sections (the NameSplitted can be empty due that later there is a validation) so if the search criteria use a large category like "Core.File.FileSystem.A". it will take only the last two sections.
  • Loading branch information
RobertGlobant20 committed Dec 6, 2023
1 parent 0e9dcd2 commit a3f7bd6
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/DynamoCore/Utilities/LuceneSearchUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,14 @@ internal string CreateSearchQuery(string[] fields, string SearchTerm)
continue;

var categorySearchBased = searchTerm.Split('.');
if (f == nameof(LuceneConfig.NodeFieldsEnum.CategorySplitted))
searchTerm = categorySearchBased[0];
else
searchTerm = categorySearchBased[1];
//In the case the search criteria is like "Core.File.FileSystem.a" it will take only the last two sections Category=FileSystem and Name=a*
if (categorySearchBased.Length > 1 && !string.IsNullOrEmpty(categorySearchBased[categorySearchBased.Length - 2]))
{
if (f == nameof(LuceneConfig.NodeFieldsEnum.CategorySplitted))
searchTerm = categorySearchBased[categorySearchBased.Length - 2];
else
searchTerm = categorySearchBased[categorySearchBased.Length - 1];
}
}

FuzzyQuery fuzzyQuery;
Expand Down Expand Up @@ -355,6 +359,7 @@ private WildcardQuery CalculateFieldWeight(string fieldName, string searchTerm,
{
WildcardQuery query;

//In case we are weighting the NameSplitted field then means that is a search based on Category of the type "cat.node" so we will be using the wilcard "category.node*" otherwise will be the normal wildcard
var termText = fieldName == nameof(LuceneConfig.NodeFieldsEnum.NameSplitted) ? searchTerm + "*" : "*" + searchTerm + "*";

query = isWildcard == false ?
Expand Down Expand Up @@ -484,6 +489,7 @@ internal void AddNodeTypeToSearchIndex(NodeSearchElement node, Document doc)

var categoryParts = node.FullCategoryName.Split('.');
string categoryParsed = categoryParts.Length > 1 ? categoryParts[categoryParts.Length - 1] : node.FullCategoryName;
//In case the search criteria is like "filesystem.replace" we will be storing the value "filesystem" inside the CategorySplitted field
SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.CategorySplitted), categoryParsed);

SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.Name), node.Name);
Expand Down

0 comments on commit a3f7bd6

Please sign in to comment.