This commit is contained in:
@@ -31,7 +31,7 @@ namespace AyaNova.Biz
|
||||
- Can be empty if tags are specified, no tags and no phrase is an error condition
|
||||
- ObjectType: only return results for objects of this type
|
||||
- InName: flag that indicates only search in names
|
||||
- Tag ids that are also on result objects
|
||||
- Tags that are also on result objects
|
||||
- Can be empty if a phrase is specified
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ namespace AyaNova.Biz
|
||||
public string Phrase { get; set; }
|
||||
public bool NameOnly { get; set; }
|
||||
public AyaType TypeOnly { get; set; }
|
||||
// public List<long> Tags { get; set; }
|
||||
public List<string> Tags { get; set; }
|
||||
//Note: maxresults of 0 will get all results
|
||||
public int MaxResults { get; set; }
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace AyaNova.Biz
|
||||
{
|
||||
NameOnly = false;
|
||||
TypeOnly = AyaType.NoType;
|
||||
// Tags = new List<long>();
|
||||
Tags = new List<string>();
|
||||
MaxResults = 500;
|
||||
}
|
||||
|
||||
@@ -85,9 +85,9 @@ namespace AyaNova.Biz
|
||||
if (!string.IsNullOrWhiteSpace(this.Phrase))
|
||||
return true;
|
||||
|
||||
// //has tags?
|
||||
// if (this.Tags.Count > 0)
|
||||
// return true;
|
||||
//has tags?
|
||||
if (this.Tags.Count > 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -211,99 +211,102 @@ namespace AyaNova.Biz
|
||||
}
|
||||
|
||||
|
||||
//IF TAGS SPECIFIED
|
||||
//BUGBUG: If no valid tags provided, i.e. a single tag of type or id 0 then can skip
|
||||
// if (searchParameters.Tags.Count > 0)
|
||||
// {
|
||||
// //get a count of the search tags (used by both paths below)
|
||||
// var SearchTagCount = searchParameters.Tags.Count;
|
||||
|
||||
// if (string.IsNullOrWhiteSpace(searchParameters.Phrase))
|
||||
// {
|
||||
//--------------- TAGS
|
||||
//IF TAGS SPECIFIED
|
||||
if (searchParameters.Tags.Count > 0)
|
||||
{
|
||||
//get a count of the search tags (used by both paths below)
|
||||
var SearchTagCount = searchParameters.Tags.Count;
|
||||
|
||||
// #region TAGS ONLY SEARCH (NO PHRASE) ALL FULL MATCHES ARE INCLUSIVE
|
||||
// Dictionary<long, long> TagCounts = new Dictionary<long, long>();
|
||||
if (string.IsNullOrWhiteSpace(searchParameters.Phrase))
|
||||
{
|
||||
|
||||
// //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();
|
||||
// //ct.TagMap.Where(n => n.Tags.Count(t => tags.Contains(t.DisplayName)) == tags.Count)
|
||||
#region TAGS ONLY SEARCH (NO PHRASE) ALL FULL MATCHES ARE INCLUSIVE
|
||||
Dictionary<long, long> TagCounts = new Dictionary<long, long>();
|
||||
|
||||
// //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 MatchTagCount = 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 (MatchTagCount == 0)
|
||||
// {
|
||||
// //return empty resultlist
|
||||
// return ReturnObject;
|
||||
// }
|
||||
//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();
|
||||
//ct.TagMap.Where(n => n.Tags.Count(t => tags.Contains(t.DisplayName)) == tags.Count)
|
||||
|
||||
// //Save the matching count
|
||||
// TagCounts.Add(SearchTagId, MatchTagCount);
|
||||
// }
|
||||
//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 MatchTagCount = 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 (MatchTagCount == 0)
|
||||
{
|
||||
//return empty resultlist
|
||||
return ReturnObject;
|
||||
}
|
||||
|
||||
// //2) find smallest count match so we are working with the shortest list first
|
||||
// var ShortestMatchingTag = TagCounts.OrderBy(x => x.Value).First().Key;
|
||||
//Save the matching count
|
||||
TagCounts.Add(SearchTagId, MatchTagCount);
|
||||
}
|
||||
|
||||
// //3) Generate the shortlist of items that match the shortest tag list
|
||||
// var ShortList = await ct.TagMap.Where(x => x.TagId == ShortestMatchingTag).ToListAsync();
|
||||
//2) find smallest count match so we are working with the shortest list first
|
||||
var ShortestMatchingTag = TagCounts.OrderBy(x => x.Value).First().Key;
|
||||
|
||||
// //4) 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
|
||||
//3) Generate the shortlist of items that match the shortest tag list
|
||||
var ShortList = await ct.TagMap.Where(x => x.TagId == ShortestMatchingTag).ToListAsync();
|
||||
|
||||
// //Iterate shortlist
|
||||
// foreach (TagMap t in ShortList)
|
||||
// {
|
||||
// var matchCount = 1;
|
||||
// //Iterate requested tags
|
||||
// foreach (long TagId in searchParameters.Tags)
|
||||
// {
|
||||
// //skipping already matched shortest tag
|
||||
// if (TagId != ShortestMatchingTag)
|
||||
// {
|
||||
// //Ok, does this object have this tag?
|
||||
// bool HasTag = await ct.TagMap.Where(x => x.TagToObjectId == t.TagToObjectId && x.TagToObjectType == t.TagToObjectType && x.TagId == TagId).AnyAsync();
|
||||
// if (HasTag)
|
||||
// matchCount++;
|
||||
// }
|
||||
// }
|
||||
// //does it match all tags?
|
||||
// if (matchCount == SearchTagCount)
|
||||
// {
|
||||
// //yes, add it to the results
|
||||
// MatchingObjects.Add(new AyaTypeId(t.TagToObjectType, t.TagToObjectId));
|
||||
// }
|
||||
// }
|
||||
// #endregion
|
||||
//4) 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
|
||||
|
||||
//Iterate shortlist
|
||||
foreach (TagMap t in ShortList)
|
||||
{
|
||||
var matchCount = 1;
|
||||
//Iterate requested tags
|
||||
foreach (long TagId in searchParameters.Tags)
|
||||
{
|
||||
//skipping already matched shortest tag
|
||||
if (TagId != ShortestMatchingTag)
|
||||
{
|
||||
//Ok, does this object have this tag?
|
||||
bool HasTag = await ct.TagMap.Where(x => x.TagToObjectId == t.TagToObjectId && x.TagToObjectType == t.TagToObjectType && x.TagId == TagId).AnyAsync();
|
||||
if (HasTag)
|
||||
matchCount++;
|
||||
}
|
||||
}
|
||||
//does it match all tags?
|
||||
if (matchCount == SearchTagCount)
|
||||
{
|
||||
//yes, add it to the results
|
||||
MatchingObjects.Add(new AyaTypeId(t.TagToObjectType, t.TagToObjectId));
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// #region TAGS PLUS PHRASE SEARCH WITH NON MATCHING TAGS EXCLUSIVE
|
||||
// //list to hold temporary matches
|
||||
// List<AyaTypeId> TagMatchingObjects = new List<AyaTypeId>();
|
||||
}
|
||||
else
|
||||
{
|
||||
#region TAGS PLUS PHRASE SEARCH WITH NON MATCHING TAGS EXCLUSIVE
|
||||
//list to hold temporary matches
|
||||
List<AyaTypeId> TagMatchingObjects = new List<AyaTypeId>();
|
||||
|
||||
// //LOOP THROUGH MATCHING OBJECTS LIST
|
||||
// foreach (AyaTypeId i in MatchingObjects)
|
||||
// {
|
||||
// var matchCount = await ct.TagMap.Where(x => x.TagToObjectId == i.ObjectId && x.TagToObjectType == i.ObjectType && searchParameters.Tags.Contains(x.TagId)).LongCountAsync();
|
||||
// if (matchCount == SearchTagCount)
|
||||
// {
|
||||
// TagMatchingObjects.Add(i);
|
||||
// }
|
||||
//LOOP THROUGH MATCHING OBJECTS LIST
|
||||
foreach (AyaTypeId i in MatchingObjects)
|
||||
{
|
||||
var matchCount = await ct.TagMap.Where(x => x.TagToObjectId == i.ObjectId && x.TagToObjectType == i.ObjectType && searchParameters.Tags.Contains(x.TagId)).LongCountAsync();
|
||||
if (matchCount == SearchTagCount)
|
||||
{
|
||||
TagMatchingObjects.Add(i);
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
// //Ok here we have all the MatchingObjects that had all the tags in the TagMatchingObjects list so that's actually now our defacto return list
|
||||
// MatchingObjects = TagMatchingObjects;
|
||||
//Ok here we have all the MatchingObjects that had all the tags in the TagMatchingObjects list so that's actually now our defacto return list
|
||||
MatchingObjects = TagMatchingObjects;
|
||||
|
||||
|
||||
// #endregion
|
||||
#endregion
|
||||
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------- END TAGS -------------
|
||||
|
||||
//REMOVE ANY ITEMS THAT USER IS NOT PERMITTED TO READ
|
||||
//If it's a name only search then all is allowed
|
||||
|
||||
Reference in New Issue
Block a user