This commit is contained in:
@@ -121,7 +121,17 @@ namespace AyaNova.Biz
|
|||||||
return ReturnObject;
|
return ReturnObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
//IF PHRASE SPECIFIED
|
// todo: SEARCH UI
|
||||||
|
// - all searches without wildcards or quotes are "contains" searches by default and multiple phrases space delimited are accomodated
|
||||||
|
// - if user want's an exact search then they put it in quotes like google for MUST have in that exact form and case (if case insensitive mode)
|
||||||
|
|
||||||
|
|
||||||
|
//IF PHRASE SPECIFIED <---wtf? why wouldn't it be?
|
||||||
|
|
||||||
|
//escape literal percentage signs first just in case they are searching for 50% off or something
|
||||||
|
//https://www.postgresql.org/docs/current/functions-matching.html#FUNCTIONS-LIKE
|
||||||
|
//need to get around breaking possibly losing the symbol so make it text
|
||||||
|
searchParameters.Phrase = searchParameters.Phrase.Replace("%", "pctsym");
|
||||||
|
|
||||||
//Modify Phrase to replace wildcard * with % as breakcore expects sql style wildcards
|
//Modify Phrase to replace wildcard * with % as breakcore expects sql style wildcards
|
||||||
searchParameters.Phrase = searchParameters.Phrase.Replace("*", "%");
|
searchParameters.Phrase = searchParameters.Phrase.Replace("*", "%");
|
||||||
@@ -130,15 +140,15 @@ namespace AyaNova.Biz
|
|||||||
var PhraseItems = await BreakSearchPhraseAsync(translationId, searchParameters.Phrase);
|
var PhraseItems = await BreakSearchPhraseAsync(translationId, searchParameters.Phrase);
|
||||||
|
|
||||||
//SPLIT OUT WILDCARDS FROM NON WILDCARDS
|
//SPLIT OUT WILDCARDS FROM NON WILDCARDS
|
||||||
List<string> WildCardSearchTerms = new List<string>();
|
List<string> PreWildCardedSearchTerms = new List<string>();
|
||||||
List<string> RegularSearchTerms = new List<string>();
|
List<string> SearchTerms = new List<string>();
|
||||||
|
|
||||||
foreach (string PhraseItem in PhraseItems)
|
foreach (string PhraseItem in PhraseItems)
|
||||||
{
|
{
|
||||||
if (PhraseItem.Contains("%"))
|
if (PhraseItem.Contains("%"))
|
||||||
WildCardSearchTerms.Add(PhraseItem);
|
PreWildCardedSearchTerms.Add(PhraseItem.Replace("pctsym", @"\%"));//put back literal percentage symbol if necessary
|
||||||
else
|
else
|
||||||
RegularSearchTerms.Add(PhraseItem);
|
SearchTerms.Add(PhraseItem.Replace("pctsym", @"\%"));//put back literal percentage symbol if necessary
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -148,15 +158,19 @@ namespace AyaNova.Biz
|
|||||||
|
|
||||||
|
|
||||||
//GET LIST OF DICTIONARY ID'S THAT MATCH REGULAR SEARCH TERMS
|
//GET LIST OF DICTIONARY ID'S THAT MATCH REGULAR SEARCH TERMS
|
||||||
if (RegularSearchTerms.Count > 0)
|
if (SearchTerms.Count > 0)
|
||||||
DictionaryMatches = await ct.SearchDictionary.Where(m => RegularSearchTerms.Contains(m.Word)).Select(m => m.Id).ToListAsync();
|
//DictionaryMatches = await ct.SearchDictionary.Where(m => SearchTerms.Contains(m.Word)).Select(m => m.Id).ToListAsync();
|
||||||
|
foreach (string Term in SearchTerms)
|
||||||
|
{
|
||||||
|
DictionaryMatches.AddRange(await ct.SearchDictionary.Where(m => m.Word.Contains(Term)).Select(m => m.Id).ToListAsync());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//GET LIST OF DICTIONARY ID'S THAT MATCH WILDCARD SEARCH TERMS
|
//GET LIST OF DICTIONARY ID'S THAT MATCH WILDCARD SEARCH TERMS
|
||||||
if (WildCardSearchTerms.Count > 0)
|
if (PreWildCardedSearchTerms.Count > 0)
|
||||||
{
|
{
|
||||||
foreach (string WildCardSearchTerm in WildCardSearchTerms)
|
foreach (string WildCardSearchTerm in PreWildCardedSearchTerms)
|
||||||
{
|
{
|
||||||
//Contains?
|
//Contains?
|
||||||
if (WildCardSearchTerm.StartsWith("%") && WildCardSearchTerm.EndsWith("%"))
|
if (WildCardSearchTerm.StartsWith("%") && WildCardSearchTerm.EndsWith("%"))
|
||||||
@@ -175,7 +189,7 @@ namespace AyaNova.Biz
|
|||||||
}
|
}
|
||||||
|
|
||||||
//SEARCH SEARCHKEY FOR MATCHING WORDS AND OPTIONALLY TYPE AND INNAME
|
//SEARCH SEARCHKEY FOR MATCHING WORDS AND OPTIONALLY TYPE AND INNAME
|
||||||
var TotalSearchTermsToMatch = WildCardSearchTerms.Count + RegularSearchTerms.Count;
|
var TotalSearchTermsToMatch = PreWildCardedSearchTerms.Count + SearchTerms.Count;
|
||||||
|
|
||||||
// var TestRawMatches = await ct.SearchKey.Where(x => DictionaryMatches.Contains(x.WordId)).ToListAsync();
|
// var TestRawMatches = await ct.SearchKey.Where(x => DictionaryMatches.Contains(x.WordId)).ToListAsync();
|
||||||
|
|
||||||
@@ -792,7 +806,8 @@ private static Dictionary<long, TranslationWordBreakingData> translationWordBrea
|
|||||||
{
|
{
|
||||||
List<string> textStrings = new List<string>();
|
List<string> textStrings = new List<string>();
|
||||||
textStrings.Add(searchPhrase);
|
textStrings.Add(searchPhrase);
|
||||||
return await BreakCoreAsync(translationId, true, textStrings);
|
//note: we want stopwords if this is a search phrase break because they might type "some" wanting awesome but some is a stopword so..
|
||||||
|
return await BreakCoreAsync(translationId, true, textStrings, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -801,7 +816,7 @@ private static Dictionary<long, TranslationWordBreakingData> translationWordBrea
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
||||||
|
|
||||||
internal static async Task<List<string>> BreakCoreAsync(long translationId, bool KeepWildCards, List<string> textStrings)
|
internal static async Task<List<string>> BreakCoreAsync(long translationId, bool KeepWildCards, List<string> textStrings, bool ignoreStopWords = false)
|
||||||
{
|
{
|
||||||
//For stopwords and CJKIndex flag value
|
//For stopwords and CJKIndex flag value
|
||||||
//if not provided (will be provided by seeder for performance but normally never) then fetch
|
//if not provided (will be provided by seeder for performance but normally never) then fetch
|
||||||
@@ -1075,13 +1090,21 @@ private static Dictionary<long, TranslationWordBreakingData> translationWordBrea
|
|||||||
//but keep them if they are part of a wildcard search phrase
|
//but keep them if they are part of a wildcard search phrase
|
||||||
if (s.Length >= MINWORDLENGTH || (KeepWildCards && s.Contains('%')))
|
if (s.Length >= MINWORDLENGTH || (KeepWildCards && s.Contains('%')))
|
||||||
{
|
{
|
||||||
//Add only non stopwords
|
if (ignoreStopWords)
|
||||||
|
{
|
||||||
|
//breaking of search phrase
|
||||||
|
ReturnList.Add(s);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Add only non stopwords - regular breaking of object for dictionary entry
|
||||||
if (!translationWordBreakData.StopWords.Contains(s))
|
if (!translationWordBreakData.StopWords.Contains(s))
|
||||||
{
|
{
|
||||||
ReturnList.Add(s);
|
ReturnList.Add(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//sometimes all the results are stop words so you end up here with nothing
|
//sometimes all the results are stop words so you end up here with nothing
|
||||||
return ReturnList;
|
return ReturnList;
|
||||||
|
|||||||
Reference in New Issue
Block a user