This commit is contained in:
@@ -113,6 +113,9 @@ namespace AyaNova.Biz
|
||||
{
|
||||
List<SearchResult> ResultList = new List<SearchResult>();
|
||||
|
||||
//list to hold temporary search/tag hits
|
||||
List<AyaTypeId> MatchingObjects = new List<AyaTypeId>();
|
||||
|
||||
if (!searchParameters.IsValid)
|
||||
{
|
||||
throw new System.ArgumentException("Search::DoSearch - Search request parameters must contain a phrase or tags");
|
||||
@@ -185,14 +188,47 @@ namespace AyaNova.Biz
|
||||
//Trigger the search
|
||||
SearchKeyMatches = await q.ToListAsync();
|
||||
|
||||
//PUT THE RESULTS INTO MATCHING OBJECTS LIST
|
||||
foreach (SearchKey SearchKeyMatch in SearchKeyMatches)
|
||||
{
|
||||
MatchingObjects.Add(new AyaTypeId(SearchKeyMatch.ObjectType, SearchKeyMatch.ObjectId));
|
||||
}
|
||||
|
||||
|
||||
//IF TAGS SPECIFIED
|
||||
if (searchParameters.Tags.Count > 0)
|
||||
{
|
||||
|
||||
if (string.IsNullOrWhiteSpace(searchParameters.Phrase))
|
||||
{
|
||||
//It's a tags only search so tags are inclusive
|
||||
//QUERY FOR ALL TAGMAPS THAT MATCH OBJECT TYPE AND ID
|
||||
//TODO: this
|
||||
//TAGS ONLY SEARCH (NO PHRASE) ALL FULL MATCHES ARE INCLUSIVE
|
||||
Dictionary<long, long> TagCounts = new Dictionary<long, long>();
|
||||
|
||||
//QUERY FOR ALL TAGMAPS THAT MATCH OBJECT TYPE AND ID FOR EVERY TAG SPECIFIED (UNION)
|
||||
//var tagmatches= await ct.TagMap.Where(m => ).Select(m => m.Id).ToListAsync();
|
||||
|
||||
//algorithm:
|
||||
//1) get counts for each tag specified from tagmap, if any are zero then none match and can bail early
|
||||
foreach (long SearchTagId in searchParameters.Tags)
|
||||
{
|
||||
var SearchTagCount = await ct.TagMap.Where(m => m.TagId == SearchTagId).LongCountAsync();
|
||||
//zero tags matching here at any point means no results for the entire search and we can bail
|
||||
if (SearchTagCount == 0)
|
||||
{
|
||||
//return empty resultlist
|
||||
return ResultList;
|
||||
}
|
||||
|
||||
//Save the matching count
|
||||
TagCounts.Add(SearchTagId,SearchTagCount);
|
||||
}
|
||||
|
||||
//2) find smallest count match, fetch the entire list of tagmaps for that term so we are working with the shortest list first
|
||||
var ShortestMatchingTag = TagCounts.OrderBy(x => x.Value).First().Key;
|
||||
|
||||
//3) Generate the shortlist of items that match the shortest tag list, then iterate the shortlist and see if each item matches all other tags specified if it does then put it into the matching objects list for return
|
||||
|
||||
//now iterate it and keep each item that matches all other tags
|
||||
|
||||
}
|
||||
else
|
||||
@@ -206,20 +242,23 @@ namespace AyaNova.Biz
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach (SearchKey SearchKeyMatch in SearchKeyMatches)
|
||||
{
|
||||
SearchResult SR = new SearchResult();
|
||||
SR.Name = BizObjectNameFetcher.Name(SearchKeyMatch.ObjectType, SearchKeyMatch.ObjectId, ct);
|
||||
SR.Id = SearchKeyMatch.ObjectId;
|
||||
SR.Type = SearchKeyMatch.ObjectType;
|
||||
ResultList.Add(SR);
|
||||
}
|
||||
|
||||
//REMOVE ANY ITEMS THAT USER IS NOT PERMITTED TO READ
|
||||
//TODO: this
|
||||
|
||||
|
||||
//amost ready to return, now populate the return list
|
||||
//TODO: change this to use MatchingObjects list instead
|
||||
// foreach (SearchKey SearchKeyMatch in SearchKeyMatches)
|
||||
// {
|
||||
// SearchResult SR = new SearchResult();
|
||||
// SR.Name = BizObjectNameFetcher.Name(SearchKeyMatch.ObjectType, SearchKeyMatch.ObjectId, ct);
|
||||
// SR.Id = SearchKeyMatch.ObjectId;
|
||||
// SR.Type = SearchKeyMatch.ObjectType;
|
||||
// ResultList.Add(SR);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
return ResultList;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user