Skip to content

Commit

Permalink
DYN-7111 Enable package search to show results for package authors as…
Browse files Browse the repository at this point in the history
… the search key (#15338)
  • Loading branch information
zeusongit authored Jun 21, 2024
1 parent a16334b commit f893b7a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
10 changes: 8 additions & 2 deletions src/DynamoCore/Configuration/LuceneConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,12 @@ public enum NodeFieldsEnum
/// <summary>
/// Node Input Parameters as string (there are nodes with same name and category but different parameters)
/// </summary>
Parameters
Parameters,

/// <summary>
/// Package author name
/// </summary>
Author
}

/// <summary>
Expand All @@ -208,6 +213,7 @@ public enum NodeFieldsEnum
public static string[] PackageIndexFields = { nameof(NodeFieldsEnum.Name),
nameof(NodeFieldsEnum.Description),
nameof(NodeFieldsEnum.SearchKeywords),
nameof(NodeFieldsEnum.Hosts)};
nameof(NodeFieldsEnum.Hosts),
nameof(NodeFieldsEnum.Author)};
}
}
19 changes: 11 additions & 8 deletions src/DynamoCore/Utilities/LuceneSearchUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,11 @@ internal Document InitializeIndexDocumentForPackages()
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 author = new TextField(nameof(LuceneConfig.NodeFieldsEnum.Author), string.Empty, Field.Store.YES);

var d = new Document()
{
name, description, keywords, hosts
name, description, keywords, hosts, author
};
return d;
}
Expand Down Expand Up @@ -294,8 +295,9 @@ private bool IsMatchingCategory(string term, string FullCategoryName)
/// </summary>
/// <param name="fields">All fields to be searched in.</param>
/// <param name="SearchTerm">Search key to be searched for.</param>
/// <param name="IsPackageContext">Set this to true if the search context is packages instead of nodes.</param>
/// <returns></returns>
internal string CreateSearchQuery(string[] fields, string SearchTerm)
internal string CreateSearchQuery(string[] fields, string SearchTerm, bool IsPackageContext = false)
{
//By Default the search will be normal
SearchType searchType = SearchType.Normal;
Expand All @@ -314,12 +316,13 @@ internal string CreateSearchQuery(string[] fields, string SearchTerm)
var booleanQuery = new BooleanQuery();
string searchTerm = QueryParser.Escape(SearchTerm);

if (searchTerm.Contains('.'))
searchType = SearchType.ByCategory;
else if (searchTerm.Contains(' '))
hasEmptySpaces = true;
else
searchType = SearchType.Normal;
if (!IsPackageContext)
{
if (searchTerm.Contains('.'))
searchType = SearchType.ByCategory;
else if (searchTerm.Contains(' '))
hasEmptySpaces = true;
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,6 +593,7 @@ internal void AddPackageToSearchIndex(PackageManagerSearchElement package, Docum

LuceneUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.Name), package.Name);
LuceneUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.Description), package.Description);
LuceneUtility.SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.Author), package.Maintainers);

if (package.Keywords.Length > 0)
{
Expand Down Expand Up @@ -1457,7 +1458,7 @@ internal IEnumerable<PackageManagerSearchElementViewModel> Search(string searchT
FuzzyMinSim = LuceneConfig.MinimumSimilarity
};

Query query = parser.Parse(LuceneUtility.CreateSearchQuery(LuceneConfig.PackageIndexFields, searchTerm));
Query query = parser.Parse(LuceneUtility.CreateSearchQuery(LuceneConfig.PackageIndexFields, searchTerm, true));

//indicate we want the first 50 results
TopDocs topDocs = LuceneUtility.Searcher.Search(query, n: LuceneConfig.DefaultResultsCount);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,8 @@ public void PackageSearchDialogSearchTestDependencyFilters()
packageManagerSearchViewModel.NonHostFilter[3].FilterCommand.Execute(string.Empty);
Assert.IsFalse(packageManagerSearchViewModel.NonHostFilter[4].OnChecked);
}
/// <summary>

/// <summary>
/// This unit test will validate that we can search packages in different languages and they will be found.
/// </summary>
[Test]
Expand All @@ -549,6 +549,7 @@ public void PackageSearchDialogSearchDifferentLanguage()
string packageVersionNumber = "1.0.0.0";
string packageCreatedDateString = "2016 - 12 - 02T13:13:20.135000 + 00:00";
string formItFilterName = "FormIt";
var packageMaintainer = new User(){ username = "DynamoTest", _id = "90-63-17" };

//Packages list
List<string> packagesNameDifferentLanguages = new List<string> { "paquete", "упаковка", "包裹" };
Expand Down Expand Up @@ -579,6 +580,7 @@ public void PackageSearchDialogSearchDifferentLanguage()
name = package,
versions = new List<PackageVersion> { tmpPackageVersion },
host_dependencies = new List<string> { formItFilterName },
maintainers = new List<User> { packageMaintainer },
}), false);
packageManagerSearchViewModel.AddToSearchResults(tmpPackage);
}
Expand Down

0 comments on commit f893b7a

Please sign in to comment.