This commit is contained in:
2019-07-03 18:29:36 +00:00
parent 76ee4c5de1
commit a041eefa34
6 changed files with 82 additions and 33 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
@@ -39,6 +40,37 @@ namespace AyaNova.Util
}
/// <summary>
/// Utility used by biz classes to extract all the custom field data as text strings suitable for search indexing
/// Does not take into account type of field only what is in it and weeds out bools and any other non suitable for search text
/// </summary>
/// <param name="jsonIn"></param>
/// <returns></returns>
public static List<string> GetCustomFieldsAsStringArrayForSearchIndexing(string jsonIn)
{
var ret = new List<string>();
if (!string.IsNullOrWhiteSpace(jsonIn))
{
var j = JObject.Parse(jsonIn);
//iterate the values in the custom fields
foreach (KeyValuePair<string, JToken> kv in j)
{
//Add as string any value that isn't a bool since bools are useless for searching
//and don't add dates as it gets hellish to factor in time zone conversions and local server vs user date format and all that shit
//and at the end of the day it won't really be useful for searching as people will probably ask for a filter or sort instead which we may have to
//look at in future, for search though just the numbers and text that are plausibly search-worthy
if (kv.Value.Type != JTokenType.Boolean && kv.Value.Type != JTokenType.Date)
{
ret.Add(kv.Value.Value<string>());
}
}
}
return ret;
}
}//eoc
}//eons