Skip to content

Commit

Permalink
DYN-6037 Overloaded Nodes Code Review
Browse files Browse the repository at this point in the history
Renaming IndexFieldsEnum to NodeFieldsEnum.
  • Loading branch information
RobertGlobant20 committed Jul 10, 2023
1 parent 6bc39b7 commit fab8b07
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 40 deletions.
24 changes: 12 additions & 12 deletions src/DynamoCore/Configuration/LuceneConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ internal class LuceneConfig
/// <summary>
/// This represent the fields that will be indexed when initializing Lucene Search
/// </summary>
public enum IndexFieldsEnum
public enum NodeFieldsEnum
{
/// <summary>
/// Name - The name of the node
Expand Down Expand Up @@ -138,21 +138,21 @@ public enum IndexFieldsEnum
/// <summary>
/// Nodes Fields to be indexed by Lucene Search
/// </summary>
public static string[] NodeIndexFields = { nameof(IndexFieldsEnum.Name),
nameof(IndexFieldsEnum.FullCategoryName),
nameof(IndexFieldsEnum.Description),
nameof(IndexFieldsEnum.SearchKeywords),
nameof(IndexFieldsEnum.DocName),
nameof(IndexFieldsEnum.Documentation),
nameof(IndexFieldsEnum.Parameters)};
public static string[] NodeIndexFields = { nameof(NodeFieldsEnum.Name),
nameof(NodeFieldsEnum.FullCategoryName),
nameof(NodeFieldsEnum.Description),
nameof(NodeFieldsEnum.SearchKeywords),
nameof(NodeFieldsEnum.DocName),
nameof(NodeFieldsEnum.Documentation),
nameof(NodeFieldsEnum.Parameters)};


/// <summary>
/// Package Fields to be indexed by Lucene Search
/// </summary>
public static string[] PackageIndexFields = { nameof(IndexFieldsEnum.Name),
nameof(IndexFieldsEnum.Description),
nameof(IndexFieldsEnum.SearchKeywords),
nameof(IndexFieldsEnum.Hosts)};
public static string[] PackageIndexFields = { nameof(NodeFieldsEnum.Name),
nameof(NodeFieldsEnum.Description),
nameof(NodeFieldsEnum.SearchKeywords),
nameof(NodeFieldsEnum.Hosts)};
}
}
10 changes: 5 additions & 5 deletions src/DynamoCore/Models/DynamoModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3253,11 +3253,11 @@ private void AddNodeTypeToSearchIndex(NodeSearchElement node, Document doc)
if (IsTestMode) return;
if (LuceneSearchUtility.addedFields == null) return;

LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.IndexFieldsEnum.FullCategoryName), node.FullCategoryName);
LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.IndexFieldsEnum.Name), node.Name);
LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.IndexFieldsEnum.Description), node.Description);
if (node.SearchKeywords.Count > 0) LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.IndexFieldsEnum.SearchKeywords), node.SearchKeywords.Aggregate((x, y) => x + " " + y), true, true);
LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.IndexFieldsEnum.Parameters), node.Parameters?? string.Empty);
LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.FullCategoryName), node.FullCategoryName);
LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.Name), node.Name);
LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.Description), node.Description);
if (node.SearchKeywords.Count > 0) LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.SearchKeywords), node.SearchKeywords.Aggregate((x, y) => x + " " + y), true, true);
LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.Parameters), node.Parameters?? string.Empty);

LuceneSearchUtility.writer?.AddDocument(doc);
}
Expand Down
28 changes: 14 additions & 14 deletions src/DynamoCore/Utilities/LuceneSearchUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ internal Document InitializeIndexDocumentForNodes()
{
if (DynamoModel.IsTestMode) return null;

var name = new TextField(nameof(LuceneConfig.IndexFieldsEnum.Name), string.Empty, Field.Store.YES);
var fullCategory = new TextField(nameof(LuceneConfig.IndexFieldsEnum.FullCategoryName), string.Empty, Field.Store.YES);
var description = new TextField(nameof(LuceneConfig.IndexFieldsEnum.Description), string.Empty, Field.Store.YES);
var keywords = new TextField(nameof(LuceneConfig.IndexFieldsEnum.SearchKeywords), string.Empty, Field.Store.YES);
var docName = new StringField(nameof(LuceneConfig.IndexFieldsEnum.DocName), string.Empty, Field.Store.YES);
var fullDoc = new TextField(nameof(LuceneConfig.IndexFieldsEnum.Documentation), string.Empty, Field.Store.YES);
var parameters = new TextField(nameof(LuceneConfig.IndexFieldsEnum.Parameters), string.Empty, Field.Store.YES);
var name = new TextField(nameof(LuceneConfig.NodeFieldsEnum.Name), string.Empty, Field.Store.YES);
var fullCategory = new TextField(nameof(LuceneConfig.NodeFieldsEnum.FullCategoryName), string.Empty, Field.Store.YES);
var description = new TextField(nameof(LuceneConfig.NodeFieldsEnum.Description), string.Empty, Field.Store.YES);
var keywords = new TextField(nameof(LuceneConfig.NodeFieldsEnum.SearchKeywords), string.Empty, Field.Store.YES);
var docName = new StringField(nameof(LuceneConfig.NodeFieldsEnum.DocName), string.Empty, Field.Store.YES);
var fullDoc = new TextField(nameof(LuceneConfig.NodeFieldsEnum.Documentation), string.Empty, Field.Store.YES);
var parameters = new TextField(nameof(LuceneConfig.NodeFieldsEnum.Parameters), string.Empty, Field.Store.YES);

var d = new Document()
{
Expand All @@ -108,10 +108,10 @@ internal Document InitializeIndexDocumentForPackages()
{
if (DynamoModel.IsTestMode) return null;

var name = new TextField(nameof(LuceneConfig.IndexFieldsEnum.Name), string.Empty, Field.Store.YES);
var description = new TextField(nameof(LuceneConfig.IndexFieldsEnum.Description), string.Empty, Field.Store.YES);
var keywords = new TextField(nameof(LuceneConfig.IndexFieldsEnum.SearchKeywords), string.Empty, Field.Store.YES);
var hosts = new TextField(nameof(LuceneConfig.IndexFieldsEnum.Hosts), string.Empty, Field.Store.YES);
var name = new TextField(nameof(LuceneConfig.NodeFieldsEnum.Name), string.Empty, Field.Store.YES);
var description = new TextField(nameof(LuceneConfig.NodeFieldsEnum.Description), string.Empty, Field.Store.YES);
var keywords = new TextField(nameof(LuceneConfig.NodeFieldsEnum.SearchKeywords), string.Empty, Field.Store.YES);
var hosts = new TextField(nameof(LuceneConfig.NodeFieldsEnum.Hosts), string.Empty, Field.Store.YES);

var d = new Document()
{
Expand Down Expand Up @@ -198,7 +198,7 @@ internal string CreateSearchQuery(string[] fields, string SearchTerm)
}

var wildcardQuery = new WildcardQuery(new Term(f, searchTerm));
if (f.Equals(nameof(LuceneConfig.IndexFieldsEnum.Name)))
if (f.Equals(nameof(LuceneConfig.NodeFieldsEnum.Name)))
{
wildcardQuery.Boost = LuceneConfig.SearchNameWeight;
}
Expand All @@ -209,7 +209,7 @@ internal string CreateSearchQuery(string[] fields, string SearchTerm)
booleanQuery.Add(wildcardQuery, Occur.SHOULD);

wildcardQuery = new WildcardQuery(new Term(f, "*" + searchTerm + "*"));
if (f.Equals(nameof(LuceneConfig.IndexFieldsEnum.Name)))
if (f.Equals(nameof(LuceneConfig.NodeFieldsEnum.Name)))
{
wildcardQuery.Boost = LuceneConfig.WildcardsSearchNameWeight;
}
Expand All @@ -230,7 +230,7 @@ internal string CreateSearchQuery(string[] fields, string SearchTerm)
}
wildcardQuery = new WildcardQuery(new Term(f, "*" + s + "*"));

if (f.Equals(nameof(LuceneConfig.IndexFieldsEnum.Name)))
if (f.Equals(nameof(LuceneConfig.NodeFieldsEnum.Name)))
{
wildcardQuery.Boost = 5;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,17 +455,17 @@ private void AddPackageToSearchIndex(PackageManagerSearchElement package, Docume
if (DynamoModel.IsTestMode) return;
if (LuceneSearchUtility.addedFields == null) return;

LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.IndexFieldsEnum.Name), package.Name);
LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.IndexFieldsEnum.Description), package.Description);
LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.Name), package.Name);
LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.Description), package.Description);

if (package.Keywords.Count() > 0)
{
LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.IndexFieldsEnum.SearchKeywords), package.Keywords);
LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.SearchKeywords), package.Keywords);
}

if (package.Hosts != null && string.IsNullOrEmpty(package.Hosts.ToString()))
{
LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.IndexFieldsEnum.Hosts), package.Hosts.ToString(), true, true);
LuceneSearchUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.Hosts), package.Hosts.ToString(), true, true);
}

LuceneSearchUtility.writer?.AddDocument(doc);
Expand Down Expand Up @@ -1132,7 +1132,7 @@ internal IEnumerable<PackageManagerSearchElementViewModel> Search(string searchT
Document resultDoc = LuceneSearchUtility.Searcher.Doc(topDocs.ScoreDocs[i].Doc);

// Get the view model of the package element and add it to the results.
string name = resultDoc.Get(nameof(LuceneConfig.IndexFieldsEnum.Name));
string name = resultDoc.Get(nameof(LuceneConfig.NodeFieldsEnum.Name));

var foundPackage = GetViewModelForPackageSearchElement(name);
if (foundPackage != null)
Expand Down
8 changes: 4 additions & 4 deletions src/DynamoCoreWpf/ViewModels/Search/SearchViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -962,10 +962,10 @@ internal IEnumerable<NodeSearchElementViewModel> Search(string search, bool useL
// read back a Lucene doc from results
Document resultDoc = LuceneSearchUtility.Searcher.Doc(topDocs.ScoreDocs[i].Doc);

string name = resultDoc.Get(nameof(LuceneConfig.IndexFieldsEnum.Name));
string docName = resultDoc.Get(nameof(LuceneConfig.IndexFieldsEnum.DocName));
string cat = resultDoc.Get(nameof(LuceneConfig.IndexFieldsEnum.FullCategoryName));
string parameters = resultDoc.Get(nameof(LuceneConfig.IndexFieldsEnum.Parameters));
string name = resultDoc.Get(nameof(LuceneConfig.NodeFieldsEnum.Name));
string docName = resultDoc.Get(nameof(LuceneConfig.NodeFieldsEnum.DocName));
string cat = resultDoc.Get(nameof(LuceneConfig.NodeFieldsEnum.FullCategoryName));
string parameters = resultDoc.Get(nameof(LuceneConfig.NodeFieldsEnum.Parameters));

if (!string.IsNullOrEmpty(docName))
{
Expand Down

0 comments on commit fab8b07

Please sign in to comment.