Skip to content

Commit

Permalink
DYN-6535 DynamoRevit Improve Search Code Review
Browse files Browse the repository at this point in the history
Convert the ByEmptySpace to be a property and remove it from the enum.
  • Loading branch information
RobertGlobant20 committed Jan 23, 2024
1 parent 18a3e8f commit ff1b100
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/DynamoCore/Utilities/LuceneSearchUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ internal class LuceneSearchUtility
/// </summary>
internal static readonly LuceneStartConfig DefaultPkgIndexStartConfig = new LuceneStartConfig(LuceneSearchUtility.LuceneStorage.FILE_SYSTEM, LuceneConfig.PackagesIndexingDirectory);

private bool hasEmptySpaces { get; set; }

public enum LuceneStorage
{
//Lucene Storage will be located in RAM and all the info indexed will be lost when Dynamo app is closed
Expand All @@ -88,10 +90,7 @@ public enum SearchType
Normal,

//Search by category using the "." character for example "list.re"
ByCategory,

//Search using an empty space as separator like "get parameters" or "set parameters"
ByEmptySpace
ByCategory
}

// Used for creating the StandardAnalyzer
Expand Down Expand Up @@ -279,6 +278,7 @@ internal string CreateSearchQuery(string[] fields, string SearchTerm)
//By Default the search will be normal
SearchType searchType = SearchType.Normal;
int fuzzyLogicMaxEdits = LuceneConfig.FuzzySearchMinEdits;
hasEmptySpaces = false;

//Max number of nodes allowed in the search when is a ByEmptySpace search
const int MaxNodeNamesRepeated = 20;
Expand All @@ -295,11 +295,11 @@ internal string CreateSearchQuery(string[] fields, string SearchTerm)
if (searchTerm.Contains('.'))
searchType = SearchType.ByCategory;
else if (searchTerm.Contains(' '))
searchType = SearchType.ByEmptySpace;
hasEmptySpaces = true;
else
searchType = SearchType.Normal;

var trimmedSearchTerm = searchType == SearchType.ByEmptySpace ? searchTerm.Replace(" ", "") : searchTerm;
var trimmedSearchTerm = hasEmptySpaces == true ? searchTerm.Replace(" ", "") : searchTerm;

foreach (string f in fields)
{
Expand Down Expand Up @@ -335,12 +335,12 @@ internal string CreateSearchQuery(string[] fields, string SearchTerm)
FuzzyQuery fuzzyQuery;
if (searchTerm.Length > LuceneConfig.FuzzySearchMinimalTermLength)
{
fuzzyQuery = new FuzzyQuery(new Term(f, searchType == SearchType.ByEmptySpace ? trimmedSearchTerm : searchTerm), fuzzyLogicMaxEdits);
fuzzyQuery = new FuzzyQuery(new Term(f, hasEmptySpaces == true ? trimmedSearchTerm : searchTerm), fuzzyLogicMaxEdits);
booleanQuery.Add(fuzzyQuery, Occur.SHOULD);
}

var fieldQuery = CalculateFieldWeight(f, searchType == SearchType.ByEmptySpace ? trimmedSearchTerm : searchTerm);
var wildcardQuery = CalculateFieldWeight(f, searchType == SearchType.ByEmptySpace ? trimmedSearchTerm : searchTerm, true);
var fieldQuery = CalculateFieldWeight(f, hasEmptySpaces == true ? trimmedSearchTerm : searchTerm);
var wildcardQuery = CalculateFieldWeight(f, hasEmptySpaces == true ? trimmedSearchTerm : searchTerm, true);

if (searchType == SearchType.ByCategory && f == nameof(LuceneConfig.NodeFieldsEnum.CategorySplitted))
{
Expand Down

0 comments on commit ff1b100

Please sign in to comment.