This commit is contained in:
2018-09-19 22:35:47 +00:00
parent 97b0097582
commit 2988240cef
3 changed files with 85 additions and 19 deletions

View File

@@ -44,7 +44,7 @@ namespace AyaNova.Biz
_id = long.Parse(sId);
int nType = int.Parse(sObjectTypeNumeral);
if (!AyaTypeExists(nType))
_ayaType = AyaType.NotValid;
_ayaType = AyaType.NoType;
else
_ayaType = (AyaType)Enum.Parse(typeof(AyaType), sObjectTypeNumeral);
}
@@ -53,7 +53,7 @@ namespace AyaNova.Biz
{
get
{
return (_ayaType == AyaType.NotValid) || (_id == 0);
return (_ayaType == AyaType.NoType) || (_id == 0);
}
}

View File

@@ -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>();
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
//await ct.SaveChangesAsync();
@@ -293,8 +366,7 @@ namespace AyaNova.Biz
/// <returns>List of strings</returns>
internal static List<string> Break(long localeId, params string[] text)
{
List<string> KeyWordList = new List<string>(BreakCore(localeId, false, text).Split(','));
return KeyWordList;
return BreakCore(localeId, false, text);
}
/// <summary>
@@ -304,7 +376,7 @@ namespace AyaNova.Biz
/// <param name="localeId"></param>
/// <param name="text"></param>
/// <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);
}
@@ -315,7 +387,7 @@ namespace AyaNova.Biz
/// </summary>
// 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
LocaleWordBreakingData LocaleSearchData = GetLocaleSearchData(localeId);
@@ -327,11 +399,7 @@ namespace AyaNova.Biz
StringBuilder sb = new StringBuilder();
StringBuilder sbWord = new StringBuilder();
// System.IO.StringWriter sr = new System.IO.StringWriter(sb);
// System.Xml.XmlTextWriter w = new System.Xml.XmlTextWriter(sr);
// w.Formatting = System.Xml.Formatting.Indented;
// w.WriteStartElement("Items");
List<string> ReturnList = new List<string>();
//Loop through each of the passed in strings
@@ -573,7 +641,7 @@ namespace AyaNova.Biz
//bail early if there is nothing indexed
if (tempParsedWords.Count == 0) return "";
if (tempParsedWords.Count == 0) return ReturnList;
//Make a return string array
@@ -583,14 +651,12 @@ namespace AyaNova.Biz
//Add only non stopwords
if (!LocaleSearchData.StopWords.Contains(s))
{
sbResults.Append(s);
sbResults.Append(",");
ReturnList.Add(s);
}
}
//sometimes all the results are stop words so you end up
//here with nothing in sbResults.
return sbResults.ToString().TrimEnd(',');
//sometimes all the results are stop words so you end up here with nothing
return ReturnList;
}

View File

@@ -49,7 +49,7 @@ namespace AyaNova.Models
StartAfter=Created;
JobType=JobType.NotSet;
ObjectId=0;
ObjectType=AyaType.NotValid;
ObjectType=AyaType.NoType;
JobStatus=JobStatus.Sleeping;
JobInfo=null;