This commit is contained in:
@@ -17,14 +17,15 @@ SON OF TAGS
|
|||||||
|
|
||||||
- Remove old tag code, models, schema tables, cleanup and db erase code that refers to them
|
- Remove old tag code, models, schema tables, cleanup and db erase code that refers to them
|
||||||
- THINGS TO FIX AS A RESULT OF THIS:
|
- THINGS TO FIX AS A RESULT OF THIS:
|
||||||
//done? - Search.cs search code had a ton of tag stuff in it, rejig that shit
|
//done - Search.cs search indexing code had a ton of tag stuff in it, rejig that shit
|
||||||
- Import AyaNova7 biz tons of tag stuff
|
//done - Import AyaNova7 biz tons of tag stuff
|
||||||
|
|
||||||
- re-introduce Tag search to search test and make sure it works properly
|
- re-code tag search
|
||||||
|
- re-introduce Tag search to search test and make sure it works properly with widget
|
||||||
- Add new tag code to all taggable objects, their models and schema
|
- Add new tag code to all taggable objects, their models and schema
|
||||||
- Update seeder to tag objects with known set of tags for test and eval purposes
|
- Update seeder to tag objects with known set of tags for test and eval purposes
|
||||||
- Seed widget with predictable tags (Maybe colour names "red", "green", "blue" etc)
|
- Seed widget with predictable tags (Maybe colour names "red", "green", "blue" etc)
|
||||||
- Test v7 import tags users with correct scheduleable user group or whatever they will be tagged with
|
- Test v7 import tags users with correct tags for region, sched group and dispatch zone
|
||||||
|
|
||||||
SERVER SCHEMA
|
SERVER SCHEMA
|
||||||
- Add unique constraint to all name columns in all tables in ayschema and run tests (how did I miss that before??)
|
- Add unique constraint to all name columns in all tables in ayschema and run tests (how did I miss that before??)
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace AyaNova.Biz
|
|||||||
- Can be empty if tags are specified, no tags and no phrase is an error condition
|
- 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
|
- ObjectType: only return results for objects of this type
|
||||||
- InName: flag that indicates only search in names
|
- 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
|
- Can be empty if a phrase is specified
|
||||||
|
|
||||||
|
|
||||||
@@ -65,7 +65,7 @@ namespace AyaNova.Biz
|
|||||||
public string Phrase { get; set; }
|
public string Phrase { get; set; }
|
||||||
public bool NameOnly { get; set; }
|
public bool NameOnly { get; set; }
|
||||||
public AyaType TypeOnly { 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
|
//Note: maxresults of 0 will get all results
|
||||||
public int MaxResults { get; set; }
|
public int MaxResults { get; set; }
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
NameOnly = false;
|
NameOnly = false;
|
||||||
TypeOnly = AyaType.NoType;
|
TypeOnly = AyaType.NoType;
|
||||||
// Tags = new List<long>();
|
Tags = new List<string>();
|
||||||
MaxResults = 500;
|
MaxResults = 500;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,9 +85,9 @@ namespace AyaNova.Biz
|
|||||||
if (!string.IsNullOrWhiteSpace(this.Phrase))
|
if (!string.IsNullOrWhiteSpace(this.Phrase))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// //has tags?
|
//has tags?
|
||||||
// if (this.Tags.Count > 0)
|
if (this.Tags.Count > 0)
|
||||||
// return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -211,99 +211,102 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------- TAGS
|
||||||
//IF TAGS SPECIFIED
|
//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)
|
||||||
// if (searchParameters.Tags.Count > 0)
|
{
|
||||||
// {
|
//get a count of the search tags (used by both paths below)
|
||||||
// //get a count of the search tags (used by both paths below)
|
var SearchTagCount = searchParameters.Tags.Count;
|
||||||
// var SearchTagCount = searchParameters.Tags.Count;
|
|
||||||
|
|
||||||
// if (string.IsNullOrWhiteSpace(searchParameters.Phrase))
|
if (string.IsNullOrWhiteSpace(searchParameters.Phrase))
|
||||||
// {
|
{
|
||||||
|
|
||||||
// #region TAGS ONLY SEARCH (NO PHRASE) ALL FULL MATCHES ARE INCLUSIVE
|
#region TAGS ONLY SEARCH (NO PHRASE) ALL FULL MATCHES ARE INCLUSIVE
|
||||||
// Dictionary<long, long> TagCounts = new Dictionary<long, long>();
|
Dictionary<long, long> TagCounts = new Dictionary<long, long>();
|
||||||
|
|
||||||
// //QUERY FOR ALL TAGMAPS THAT MATCH OBJECT TYPE AND ID FOR EVERY TAG SPECIFIED (UNION)
|
//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();
|
//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)
|
//ct.TagMap.Where(n => n.Tags.Count(t => tags.Contains(t.DisplayName)) == tags.Count)
|
||||||
|
|
||||||
// //algorithm:
|
//algorithm:
|
||||||
// //1) get counts for each tag specified from tagmap, if any are zero then none match and can bail early
|
//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)
|
foreach (long SearchTagId in searchParameters.Tags)
|
||||||
// {
|
{
|
||||||
// var MatchTagCount = await ct.TagMap.Where(m => m.TagId == SearchTagId).LongCountAsync();
|
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
|
//zero tags matching here at any point means no results for the entire search and we can bail
|
||||||
// if (MatchTagCount == 0)
|
if (MatchTagCount == 0)
|
||||||
// {
|
{
|
||||||
// //return empty resultlist
|
//return empty resultlist
|
||||||
// return ReturnObject;
|
return ReturnObject;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //Save the matching count
|
//Save the matching count
|
||||||
// TagCounts.Add(SearchTagId, MatchTagCount);
|
TagCounts.Add(SearchTagId, MatchTagCount);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //2) find smallest count match so we are working with the shortest list first
|
//2) find smallest count match so we are working with the shortest list first
|
||||||
// var ShortestMatchingTag = TagCounts.OrderBy(x => x.Value).First().Key;
|
var ShortestMatchingTag = TagCounts.OrderBy(x => x.Value).First().Key;
|
||||||
|
|
||||||
// //3) Generate the shortlist of items that match the shortest tag list
|
//3) Generate the shortlist of items that match the shortest tag list
|
||||||
// var ShortList = await ct.TagMap.Where(x => x.TagId == ShortestMatchingTag).ToListAsync();
|
var ShortList = await ct.TagMap.Where(x => x.TagId == ShortestMatchingTag).ToListAsync();
|
||||||
|
|
||||||
// //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
|
//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
|
//Iterate shortlist
|
||||||
// foreach (TagMap t in ShortList)
|
foreach (TagMap t in ShortList)
|
||||||
// {
|
{
|
||||||
// var matchCount = 1;
|
var matchCount = 1;
|
||||||
// //Iterate requested tags
|
//Iterate requested tags
|
||||||
// foreach (long TagId in searchParameters.Tags)
|
foreach (long TagId in searchParameters.Tags)
|
||||||
// {
|
{
|
||||||
// //skipping already matched shortest tag
|
//skipping already matched shortest tag
|
||||||
// if (TagId != ShortestMatchingTag)
|
if (TagId != ShortestMatchingTag)
|
||||||
// {
|
{
|
||||||
// //Ok, does this object have this tag?
|
//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();
|
bool HasTag = await ct.TagMap.Where(x => x.TagToObjectId == t.TagToObjectId && x.TagToObjectType == t.TagToObjectType && x.TagId == TagId).AnyAsync();
|
||||||
// if (HasTag)
|
if (HasTag)
|
||||||
// matchCount++;
|
matchCount++;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// //does it match all tags?
|
//does it match all tags?
|
||||||
// if (matchCount == SearchTagCount)
|
if (matchCount == SearchTagCount)
|
||||||
// {
|
{
|
||||||
// //yes, add it to the results
|
//yes, add it to the results
|
||||||
// MatchingObjects.Add(new AyaTypeId(t.TagToObjectType, t.TagToObjectId));
|
MatchingObjects.Add(new AyaTypeId(t.TagToObjectType, t.TagToObjectId));
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// #endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
// }
|
}
|
||||||
// else
|
else
|
||||||
// {
|
{
|
||||||
// #region TAGS PLUS PHRASE SEARCH WITH NON MATCHING TAGS EXCLUSIVE
|
#region TAGS PLUS PHRASE SEARCH WITH NON MATCHING TAGS EXCLUSIVE
|
||||||
// //list to hold temporary matches
|
//list to hold temporary matches
|
||||||
// List<AyaTypeId> TagMatchingObjects = new List<AyaTypeId>();
|
List<AyaTypeId> TagMatchingObjects = new List<AyaTypeId>();
|
||||||
|
|
||||||
// //LOOP THROUGH MATCHING OBJECTS LIST
|
//LOOP THROUGH MATCHING OBJECTS LIST
|
||||||
// foreach (AyaTypeId i in MatchingObjects)
|
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();
|
var matchCount = await ct.TagMap.Where(x => x.TagToObjectId == i.ObjectId && x.TagToObjectType == i.ObjectType && searchParameters.Tags.Contains(x.TagId)).LongCountAsync();
|
||||||
// if (matchCount == SearchTagCount)
|
if (matchCount == SearchTagCount)
|
||||||
// {
|
{
|
||||||
// TagMatchingObjects.Add(i);
|
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
|
//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;
|
MatchingObjects = TagMatchingObjects;
|
||||||
|
|
||||||
|
|
||||||
// #endregion
|
#endregion
|
||||||
|
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
//--------------------- END TAGS -------------
|
||||||
|
|
||||||
//REMOVE ANY ITEMS THAT USER IS NOT PERMITTED TO READ
|
//REMOVE ANY ITEMS THAT USER IS NOT PERMITTED TO READ
|
||||||
//If it's a name only search then all is allowed
|
//If it's a name only search then all is allowed
|
||||||
|
|||||||
@@ -348,100 +348,100 @@ namespace raven_integration
|
|||||||
}//eot
|
}//eot
|
||||||
|
|
||||||
|
|
||||||
// [Fact]
|
[Fact]
|
||||||
// public async void TagSearchShouldWork()
|
public async void TagSearchShouldWork()
|
||||||
// {
|
{
|
||||||
// const string TEST_SEARCH_PHRASE = "element* aardvark";
|
const string TEST_SEARCH_PHRASE = "element* aardvark";
|
||||||
|
|
||||||
|
// //CREATE A TAG
|
||||||
|
// dynamic D = new JObject();
|
||||||
|
// D.name = Util.Uniquify("TAGSEARCH");
|
||||||
|
// ApiResponse a = await Util.PostAsync("Tag", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString());
|
||||||
|
// Util.ValidateDataReturnResponseOk(a);
|
||||||
|
// long TagId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||||
|
|
||||||
|
//Tags
|
||||||
|
dynamic TagsArray = new JArray();
|
||||||
|
TagsArray.Add(Util.Uniquify("TAGSEARCH"));
|
||||||
|
|
||||||
|
//w.tags = InclusiveTagsArray;
|
||||||
|
|
||||||
|
//CREATE A WIDGET
|
||||||
|
dynamic D = new JObject();
|
||||||
|
D.name = Util.Uniquify("TAG search test WIDGET TAG AND PHRASE");
|
||||||
|
D.dollarAmount = 1.11m;
|
||||||
|
D.active = true;
|
||||||
|
D.roles = 0;
|
||||||
|
D.notes = "This record will match in notes and tag: elementary my dear aardvark";
|
||||||
|
D.tags=TagsArray;
|
||||||
|
|
||||||
|
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString());
|
||||||
|
Util.ValidateDataReturnResponseOk(a);
|
||||||
|
long MatchWidgetInNotesId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||||
|
|
||||||
|
|
||||||
// //CREATE A WIDGET
|
|
||||||
// dynamic D = new JObject();
|
|
||||||
// D.name = Util.Uniquify("TAG search test WIDGET TAG AND PHRASE");
|
|
||||||
// D.dollarAmount = 1.11m;
|
|
||||||
// D.active = true;
|
|
||||||
// D.roles = 0;
|
|
||||||
// D.notes = "This record will match in notes and tag: elementary my dear aardvark";
|
|
||||||
|
|
||||||
// a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString());
|
|
||||||
// Util.ValidateDataReturnResponseOk(a);
|
|
||||||
// long MatchWidgetInNotesId = a.ObjectResponse["data"]["id"].Value<long>();
|
|
||||||
|
|
||||||
// //TAG the widget with the fresh tag
|
|
||||||
// D = new JObject();
|
|
||||||
// D.tagId = TagId;
|
|
||||||
// D.tagToObjectId = MatchWidgetInNotesId;
|
|
||||||
// D.tagToObjectType = 2;//widget
|
|
||||||
// a = await Util.PostAsync("TagMap", await Util.GetTokenAsync("BizAdminFull"), D.ToString());
|
|
||||||
// Util.ValidateDataReturnResponseOk(a);
|
|
||||||
|
|
||||||
|
|
||||||
// //CREATE A WIDGET WITH TAG BUT NOT SEARCH PHRASE
|
//CREATE A WIDGET WITH TAG BUT NOT SEARCH PHRASE
|
||||||
// D = new JObject();
|
D = new JObject();
|
||||||
// D.name = Util.Uniquify("TAG search test WIDGET TAG ONLY");
|
D.name = Util.Uniquify("TAG search test WIDGET TAG ONLY");
|
||||||
// D.dollarAmount = 1.11m;
|
D.dollarAmount = 1.11m;
|
||||||
// D.active = true;
|
D.active = true;
|
||||||
// D.roles = 0;
|
D.roles = 0;
|
||||||
// D.notes = "This record will match in tag but no search phrase";
|
D.notes = "This record will match in tag but no search phrase";
|
||||||
|
D.tags=TagsArray;
|
||||||
|
|
||||||
// a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString());
|
a = await Util.PostAsync("Widget", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString());
|
||||||
// Util.ValidateDataReturnResponseOk(a);
|
Util.ValidateDataReturnResponseOk(a);
|
||||||
// long NoPhraseMatchWidgetInTagId = a.ObjectResponse["data"]["id"].Value<long>();
|
long NoPhraseMatchWidgetInTagId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||||
|
|
||||||
// //TAG the tag only no phrase with the fresh tag
|
|
||||||
// D = new JObject();
|
|
||||||
// D.tagId = TagId;
|
|
||||||
// D.tagToObjectId = NoPhraseMatchWidgetInTagId;
|
|
||||||
// D.tagToObjectType = 2;//widget
|
|
||||||
|
|
||||||
// a = await Util.PostAsync("TagMap", await Util.GetTokenAsync("BizAdminFull"), D.ToString());
|
|
||||||
// Util.ValidateDataReturnResponseOk(a);
|
|
||||||
|
|
||||||
|
|
||||||
// //CREATE FIRST TEST USER WITH PHRASE IN NAME BUT NO TAG
|
|
||||||
// D = new JObject();
|
|
||||||
// D.name = Util.Uniquify("Wildcard contains search NAME elementary aardvark Test User");
|
|
||||||
// D.notes = "This user has the match in it's name but no tag match";
|
|
||||||
// D.ownerId = 1L;
|
|
||||||
// D.active = true;
|
|
||||||
// D.login = Util.Uniquify("LOGIN");
|
|
||||||
// D.password = Util.Uniquify("PASSWORD");
|
|
||||||
// D.roles = 0;//norole
|
|
||||||
// D.localeId = 1;//random locale
|
|
||||||
// D.userType = 3;//non scheduleable
|
|
||||||
|
|
||||||
// a = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString());
|
//CREATE FIRST TEST USER WITH PHRASE IN NAME BUT NO TAG
|
||||||
// Util.ValidateDataReturnResponseOk(a);
|
D = new JObject();
|
||||||
// long MatchUserInNameId = a.ObjectResponse["data"]["id"].Value<long>();
|
D.name = Util.Uniquify("Wildcard contains search NAME elementary aardvark Test User");
|
||||||
|
D.notes = "This user has the match in it's name but no tag match";
|
||||||
|
D.ownerId = 1L;
|
||||||
|
D.active = true;
|
||||||
|
D.login = Util.Uniquify("LOGIN");
|
||||||
|
D.password = Util.Uniquify("PASSWORD");
|
||||||
|
D.roles = 0;//norole
|
||||||
|
D.localeId = 1;//random locale
|
||||||
|
D.userType = 3;//non scheduleable
|
||||||
|
|
||||||
|
a = await Util.PostAsync("User", await Util.GetTokenAsync("manager", "l3tm3in"), D.ToString());
|
||||||
|
Util.ValidateDataReturnResponseOk(a);
|
||||||
|
long MatchUserInNameId = a.ObjectResponse["data"]["id"].Value<long>();
|
||||||
|
|
||||||
|
|
||||||
// //Now see if can find those objects with a phrase search
|
//Now see if can find those objects with a phrase search
|
||||||
// dynamic SearchParameters = new JObject();
|
dynamic SearchParameters = new JObject();
|
||||||
|
|
||||||
// SearchParameters.phrase = TEST_SEARCH_PHRASE;
|
SearchParameters.phrase = TEST_SEARCH_PHRASE;
|
||||||
// SearchParameters.nameOnly = false;
|
SearchParameters.nameOnly = false;
|
||||||
// SearchParameters.typeOnly = 0;//no type
|
SearchParameters.typeOnly = 0;//no type
|
||||||
// //product.Tags = new JArray("Real", "OnSale");
|
//product.Tags = new JArray("Real", "OnSale");
|
||||||
// SearchParameters.tags = new JArray(new long[] { TagId });
|
SearchParameters.tags = new JArray(new long[] { TagId });
|
||||||
// a = await Util.PostAsync("Search", await Util.GetTokenAsync("manager", "l3tm3in"), SearchParameters.ToString());
|
a = await Util.PostAsync("Search", await Util.GetTokenAsync("manager", "l3tm3in"), SearchParameters.ToString());
|
||||||
// Util.ValidateDataReturnResponseOk(a);
|
Util.ValidateDataReturnResponseOk(a);
|
||||||
|
|
||||||
// //Now validate the return list
|
//Now validate the return list
|
||||||
// ((JArray)a.ObjectResponse["data"]["searchResults"]).Count.Should().BeGreaterOrEqualTo(1);
|
((JArray)a.ObjectResponse["data"]["searchResults"]).Count.Should().BeGreaterOrEqualTo(1);
|
||||||
|
|
||||||
// //Turn the list into an array of id's
|
//Turn the list into an array of id's
|
||||||
// var v = ((JArray)a.ObjectResponse["data"]["searchResults"]);
|
var v = ((JArray)a.ObjectResponse["data"]["searchResults"]);
|
||||||
// List<long> MatchingIdList = new List<long>();
|
List<long> MatchingIdList = new List<long>();
|
||||||
// foreach (JObject j in v)
|
foreach (JObject j in v)
|
||||||
// {
|
{
|
||||||
// MatchingIdList.Add(j["id"].Value<long>());
|
MatchingIdList.Add(j["id"].Value<long>());
|
||||||
// }
|
}
|
||||||
|
|
||||||
// //Ensure the expected items are returned
|
//Ensure the expected items are returned
|
||||||
// MatchingIdList.Should().Contain(MatchWidgetInNotesId, "ShouldContainMatchWidgetInNotesId");
|
MatchingIdList.Should().Contain(MatchWidgetInNotesId, "ShouldContainMatchWidgetInNotesId");
|
||||||
// MatchingIdList.Should().NotContain(MatchUserInNameId, "ShouldNotContainMatchUserInNameId");
|
MatchingIdList.Should().NotContain(MatchUserInNameId, "ShouldNotContainMatchUserInNameId");
|
||||||
// MatchingIdList.Should().NotContain(NoPhraseMatchWidgetInTagId, "ShouldNotContainNoPhraseMatchWidgetInTagId");
|
MatchingIdList.Should().NotContain(NoPhraseMatchWidgetInTagId, "ShouldNotContainNoPhraseMatchWidgetInTagId");
|
||||||
|
|
||||||
// }//eot
|
}//eot
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user