This commit is contained in:
@@ -44,7 +44,7 @@ namespace AyaNova.Biz
|
|||||||
_id = long.Parse(sId);
|
_id = long.Parse(sId);
|
||||||
int nType = int.Parse(sObjectTypeNumeral);
|
int nType = int.Parse(sObjectTypeNumeral);
|
||||||
if (!AyaTypeExists(nType))
|
if (!AyaTypeExists(nType))
|
||||||
_ayaType = AyaType.NotValid;
|
_ayaType = AyaType.NoType;
|
||||||
else
|
else
|
||||||
_ayaType = (AyaType)Enum.Parse(typeof(AyaType), sObjectTypeNumeral);
|
_ayaType = (AyaType)Enum.Parse(typeof(AyaType), sObjectTypeNumeral);
|
||||||
}
|
}
|
||||||
@@ -53,7 +53,7 @@ namespace AyaNova.Biz
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return (_ayaType == AyaType.NotValid) || (_id == 0);
|
return (_ayaType == AyaType.NoType) || (_id == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -109,10 +109,83 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static async Task<List<SearchResult>> DoSearch(AyContext ct, SearchRequestParameters searchParameters)
|
public static async Task<List<SearchResult>> DoSearch(AyContext ct, long localeId, SearchRequestParameters searchParameters)
|
||||||
{
|
{
|
||||||
List<SearchResult> ResultList = new List<SearchResult>();
|
List<SearchResult> ResultList = new List<SearchResult>();
|
||||||
|
|
||||||
|
if (!searchParameters.IsValid)
|
||||||
|
{
|
||||||
|
throw new System.ArgumentException("Search::DoSearch - Search request parameters must contain a phrase or tags");
|
||||||
|
}
|
||||||
|
|
||||||
|
//IF PHRASE SPECIFIED
|
||||||
|
|
||||||
|
//Modify Phrase to replace wildcard * with % as breakcore expects sql style wildcards
|
||||||
|
searchParameters.Phrase = searchParameters.Phrase.Replace("*", "%");
|
||||||
|
|
||||||
|
//BREAK SEARCH PHRASE INTO SEPARATE TERMS
|
||||||
|
var PhraseItems = BreakSearchPhrase(localeId, searchParameters.Phrase);
|
||||||
|
|
||||||
|
//SPLIT OUT WILDCARDS FROM NON WILDCARDS
|
||||||
|
List<string> WildCardSearchTerms = new List<string>();
|
||||||
|
List<string> RegularSearchTerms = new List<string>();
|
||||||
|
|
||||||
|
foreach (string PhraseItem in PhraseItems)
|
||||||
|
{
|
||||||
|
if (PhraseItem.Contains("%"))
|
||||||
|
WildCardSearchTerms.Add(PhraseItem);
|
||||||
|
else
|
||||||
|
RegularSearchTerms.Add(PhraseItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//GET LIST OF DICTIONARY ID'S THAT MATCH REGULAR SEARCH TERMS
|
||||||
|
List<SearchDictionary> RegularMatches = new List<SearchDictionary>();
|
||||||
|
if (RegularSearchTerms.Count > 0)
|
||||||
|
RegularMatches = await ct.SearchDictionary.Where(m => RegularSearchTerms.Contains(m.Word)).ToListAsync();
|
||||||
|
|
||||||
|
|
||||||
|
//GET LIST OF DICTIONARY ID'S THAT MATCH WILDCARD SEARCH TERMS
|
||||||
|
List<SearchDictionary> WildCardMatches = new List<SearchDictionary>();
|
||||||
|
if (WildCardSearchTerms.Count > 0)
|
||||||
|
{
|
||||||
|
//Ok some fuckery required to implement this the EF CORE way
|
||||||
|
/*
|
||||||
|
.Where(entity => entity.Name.Contains("xyz"))
|
||||||
|
.Where(entity => entity.Name.EndsWith("xyz"))
|
||||||
|
.Where(entity => entity.Name.StartsWith("xyz"))
|
||||||
|
*/
|
||||||
|
foreach (string WildCardSearchTerm in WildCardSearchTerms)
|
||||||
|
{
|
||||||
|
//Contains?
|
||||||
|
if (WildCardSearchTerm.StartsWith("%") && WildCardSearchTerm.EndsWith("%"))
|
||||||
|
{
|
||||||
|
WildCardMatches.AddRange(await ct.SearchDictionary.Where(m => m.Word.EndsWith(WildCardSearchTerm.Replace("%", ""))).ToListAsync());
|
||||||
|
}
|
||||||
|
else if (WildCardSearchTerm.EndsWith("%")) //STARTS WITH?
|
||||||
|
{
|
||||||
|
WildCardMatches.AddRange(await ct.SearchDictionary.Where(m => m.Word.EndsWith(WildCardSearchTerm.Replace("%", ""))).ToListAsync());
|
||||||
|
}
|
||||||
|
else if (WildCardSearchTerm.StartsWith("%"))//ENDS WITH?
|
||||||
|
{
|
||||||
|
WildCardMatches.AddRange(await ct.SearchDictionary.Where(m => m.Word.EndsWith(WildCardSearchTerm.Replace("%", ""))).ToListAsync());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
WildCardMatches = await ct.SearchDictionary.Where(m => WildCardMatches.Contains(m.Word)).ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
//SEARCH SEARCHKEY FOR MATCHING WORDS AND OPTIONALLY TYPE AND INNAME
|
||||||
|
|
||||||
|
//IF TAGS SPECIFIED
|
||||||
|
//LOOP THROUGH SEARCHKEY MATCHES
|
||||||
|
//FOREACH OBJECT SEARCH TAGMAP FOR MATCHING OBJECTTYPE AND ID
|
||||||
|
//REMOVE RESULTS FROM SEARCH PHRASE PHASE THAT ARE NOT MATCHING
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//fake await to clear error
|
//fake await to clear error
|
||||||
//await ct.SaveChangesAsync();
|
//await ct.SaveChangesAsync();
|
||||||
|
|
||||||
@@ -293,8 +366,7 @@ namespace AyaNova.Biz
|
|||||||
/// <returns>List of strings</returns>
|
/// <returns>List of strings</returns>
|
||||||
internal static List<string> Break(long localeId, params string[] text)
|
internal static List<string> Break(long localeId, params string[] text)
|
||||||
{
|
{
|
||||||
List<string> KeyWordList = new List<string>(BreakCore(localeId, false, text).Split(','));
|
return BreakCore(localeId, false, text);
|
||||||
return KeyWordList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -304,7 +376,7 @@ namespace AyaNova.Biz
|
|||||||
/// <param name="localeId"></param>
|
/// <param name="localeId"></param>
|
||||||
/// <param name="text"></param>
|
/// <param name="text"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
internal static string BreakSearchPhrase(long localeId, params string[] text)
|
internal static List<string> BreakSearchPhrase(long localeId, params string[] text)
|
||||||
{
|
{
|
||||||
return BreakCore(localeId, true, text);
|
return BreakCore(localeId, true, text);
|
||||||
}
|
}
|
||||||
@@ -315,7 +387,7 @@ namespace AyaNova.Biz
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
// public static System.Collections.Generic.List<string> StopList = null;
|
// public static System.Collections.Generic.List<string> StopList = null;
|
||||||
|
|
||||||
internal static string BreakCore(long localeId, bool KeepWildCards, params string[] text)
|
internal static List<string> BreakCore(long localeId, bool KeepWildCards, params string[] text)
|
||||||
{
|
{
|
||||||
//Get stopwords and CJKIndex flag value
|
//Get stopwords and CJKIndex flag value
|
||||||
LocaleWordBreakingData LocaleSearchData = GetLocaleSearchData(localeId);
|
LocaleWordBreakingData LocaleSearchData = GetLocaleSearchData(localeId);
|
||||||
@@ -327,11 +399,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
StringBuilder sbWord = new StringBuilder();
|
StringBuilder sbWord = new StringBuilder();
|
||||||
// System.IO.StringWriter sr = new System.IO.StringWriter(sb);
|
List<string> ReturnList = new List<string>();
|
||||||
// System.Xml.XmlTextWriter w = new System.Xml.XmlTextWriter(sr);
|
|
||||||
|
|
||||||
// w.Formatting = System.Xml.Formatting.Indented;
|
|
||||||
// w.WriteStartElement("Items");
|
|
||||||
|
|
||||||
|
|
||||||
//Loop through each of the passed in strings
|
//Loop through each of the passed in strings
|
||||||
@@ -573,7 +641,7 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
//bail early if there is nothing indexed
|
//bail early if there is nothing indexed
|
||||||
if (tempParsedWords.Count == 0) return "";
|
if (tempParsedWords.Count == 0) return ReturnList;
|
||||||
|
|
||||||
|
|
||||||
//Make a return string array
|
//Make a return string array
|
||||||
@@ -583,14 +651,12 @@ namespace AyaNova.Biz
|
|||||||
//Add only non stopwords
|
//Add only non stopwords
|
||||||
if (!LocaleSearchData.StopWords.Contains(s))
|
if (!LocaleSearchData.StopWords.Contains(s))
|
||||||
{
|
{
|
||||||
sbResults.Append(s);
|
ReturnList.Add(s);
|
||||||
sbResults.Append(",");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//sometimes all the results are stop words so you end up
|
//sometimes all the results are stop words so you end up here with nothing
|
||||||
//here with nothing in sbResults.
|
return ReturnList;
|
||||||
return sbResults.ToString().TrimEnd(',');
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ namespace AyaNova.Models
|
|||||||
StartAfter=Created;
|
StartAfter=Created;
|
||||||
JobType=JobType.NotSet;
|
JobType=JobType.NotSet;
|
||||||
ObjectId=0;
|
ObjectId=0;
|
||||||
ObjectType=AyaType.NotValid;
|
ObjectType=AyaType.NoType;
|
||||||
JobStatus=JobStatus.Sleeping;
|
JobStatus=JobStatus.Sleeping;
|
||||||
JobInfo=null;
|
JobInfo=null;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user