Skip to content

Commit

Permalink
improvments, fuzzy entries
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyAmphibian committed Dec 29, 2024
1 parent 7a764bb commit 9861664
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Content.Client/Construction/UI/ConstructionMenuPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,16 @@ private void OnGridViewRecipeSelected(object? sender, ConstructionPrototype? rec
PopulateInfo(_selected);
}

private int CheckFuzzySearch(string hostfield,string searchtext){// return an int for futureproofing, if you wanted to sort by likeness, or something. doesn't matter much now, ints are compatible with boolean logic, anyways.
private bool CheckFuzzySearch(string hostfield,string searchtext){
int matchedtokens=0;
char[] str_seps={' ',':','.',',','/'}; //flatten punctuation.
char[] str_seps={' ',':','.',',','/','-'}; //flatten punctuation.
string[] searchtokens = searchtext.Split(str_seps); //turn the search into tokens

foreach (string stoken in searchtokens){
if(hostfield.Contains(stoken,StringComparison.OrdinalIgnoreCase)) matchedtokens++; //thanks chatGPT for helping me.
}

return matchedtokens;
return matchedtokens==searchtokens.Length;
}


Expand Down Expand Up @@ -205,7 +205,7 @@ private void OnViewPopulateRecipes(object? sender, (string search, string catago

if (!string.IsNullOrEmpty(search))
{
if ( fuzzySearch? CheckFuzzySearch( string.IsNullOrEmpty(recipe.FuzzyName) ? recipe.Name : recipe.FuzzyName,search)==0 :(!recipe.Name.ToLowerInvariant().Contains(search.Trim().ToLowerInvariant())))
if ( fuzzySearch? !CheckFuzzySearch( string.IsNullOrEmpty(recipe.FuzzyName) ? recipe.Name : recipe.FuzzyName,search) :(!recipe.Name.ToLowerInvariant().Contains(search.Trim().ToLowerInvariant())))
continue;
}

Expand Down
Loading

0 comments on commit 9861664

Please sign in to comment.