Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
fix: changed searching strategy.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Aug 18, 2023
1 parent df08550 commit cd6a61a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
3 changes: 1 addition & 2 deletions RotationSolver/ActionSequencer/ConditionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ internal static void SearchItemsReflection<T>(string popId, string name, ref str
var searchingKey = searchTxt;

var members = actions.Select(m => (m, m.GetMemberName()))
.OrderBy(s => s.Item2.Split(' ')
.Min(c => RotationConfigWindow.StringComparer.Distance(c, searchingKey)));
.OrderByDescending(s => RotationConfigWindow.Similarity(s.Item2, searchingKey));

ImGui.SetNextItemWidth(Math.Max(50 * ImGuiHelpers.GlobalScale, members.Max(i => ImGuiHelpers.GetButtonSize(i.Item2).X)));
ImGui.InputTextWithHint("##Searching the member", LocalizationManager.RightLang.ConfigWindow_Actions_MemberName, ref searchTxt, 128);
Expand Down
3 changes: 3 additions & 0 deletions RotationSolver/Localization/Strings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,4 +699,7 @@ internal partial class Strings
public string ConfigWindow_Actions_MoveUp { get; set; } = "Move Up";
public string ConfigWindow_Actions_MoveDown { get; set; } = "Move Down";
public string ConfigWindow_NotInJob { get; set; } = "This option is unavailable while using your current job\n \nRoles or jobs needed:\n{0}";

public string ConfigWindow_Searching { get; set; } = "Searching...";

}
1 change: 0 additions & 1 deletion RotationSolver/RotationSolver.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

<ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.11" />
<PackageReference Include="String.Similarity" Version="3.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
16 changes: 8 additions & 8 deletions RotationSolver/UI/RotationConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1447,8 +1447,8 @@ private static void DrawStatusList(string name, HashSet<uint> statuses, Status[]

foreach (var status in statuses.Select(a => Service.GetSheet<Status>().GetRow(a))
.Where(a => a != null)
.OrderBy(s => Math.Min(StringComparer.Distance(s.Name, _statusSearching)
, StringComparer.Distance(s.RowId.ToString(), _statusSearching))))
.OrderByDescending(s => Math.Min(Similarity(s.Name, _statusSearching)
, Similarity(s.RowId.ToString(), _statusSearching))))
{
void Delete() => removeId = status.RowId;

Expand Down Expand Up @@ -1491,8 +1491,8 @@ internal static void StatusPopUp(string popupId, Status[] allStatus, ref string
var index = 0;

var searchingKey = searching;
foreach (var status in allStatus.OrderBy(s => Math.Min(StringComparer.Distance(s.Name, searchingKey)
, StringComparer.Distance(s.RowId.ToString(), searchingKey))))
foreach (var status in allStatus.OrderByDescending(s => Math.Min(Similarity(s.Name, searchingKey)
, Similarity(s.RowId.ToString(), searchingKey))))
{
if (IconSet.GetTexture(status.Icon, out var texture, notLoadId))
{
Expand Down Expand Up @@ -1570,8 +1570,8 @@ private static void DrawActionsList(string name, HashSet<uint> actions)

if (ImGui.BeginChild("Rotation Solver Add action", new Vector2(-1, 400 * _scale)))
{
foreach (var action in AllActions.OrderBy(s => Math.Min(StringComparer.Distance(s.Name, _actionSearching)
, StringComparer.Distance(s.RowId.ToString(), _actionSearching))))
foreach (var action in AllActions.OrderByDescending(s => Math.Min(Similarity(s.Name, _actionSearching)
, Similarity(s.RowId.ToString(), _actionSearching))))
{
var selected = ImGui.Selectable($"{action.Name} ({action.RowId})");
if (ImGui.IsItemHovered())
Expand Down Expand Up @@ -1601,8 +1601,8 @@ private static void DrawActionsList(string name, HashSet<uint> actions)

foreach (var action in actions.Select(a => Service.GetSheet<GAction>().GetRow(a))
.Where(a => a != null)
.OrderBy(s => Math.Min(StringComparer.Distance(s.Name, _actionSearching)
, StringComparer.Distance(s.RowId.ToString(), _actionSearching))))
.OrderByDescending(s => Math.Min(Similarity(s.Name, _actionSearching)
, Similarity(s.RowId.ToString(), _actionSearching))))
{
void Reset() => removeId = action.RowId;

Expand Down
16 changes: 12 additions & 4 deletions RotationSolver/UI/RotationConfigWindow_Config.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Dalamud.Game.ClientState.Keys;
using ECommons.ImGuiMethods;
using F23.StringSimilarity;
using RotationSolver.Basic.Configuration;
using RotationSolver.Localization;
using RotationSolver.UI.SearchableConfigs;
Expand All @@ -10,13 +9,22 @@ namespace RotationSolver.UI;

public partial class RotationConfigWindow
{
internal static readonly Levenshtein StringComparer = new ();
internal static float Similarity(string text, string key)
{
var chars = text.Split(new char[] { ' ', ',', '、', '.', '。' }, StringSplitOptions.RemoveEmptyEntries);

var startWithCount = chars.Count(i => i.StartsWith(key, StringComparison.OrdinalIgnoreCase));

var containCount = chars.Count(i => i.Contains(key, StringComparison.OrdinalIgnoreCase));

return startWithCount * 3 + containCount;
}

private string _searchText = string.Empty;
private ISearchable[] _searchResults = Array.Empty<ISearchable>();
private void SearchingBox()
{
if (ImGui.InputTextWithHint("##Rotation Solver Search Box", "Searching...", ref _searchText, 128, ImGuiInputTextFlags.AutoSelectAll))
if (ImGui.InputTextWithHint("##Rotation Solver Search Box", LocalizationManager.RightLang.ConfigWindow_Searching, ref _searchText, 128, ImGuiInputTextFlags.AutoSelectAll))
{
if (!string.IsNullOrEmpty(_searchText))
{
Expand All @@ -28,7 +36,7 @@ private void SearchingBox()
.Where(f => f.FieldType == typeof(ISearchable[]) && f.IsInitOnly)
.SelectMany(f => (ISearchable[])f.GetValue(this))
.SelectMany(GetChildren)
.OrderBy(i => i.SearchingKeys.Split(' ').Min(k => StringComparer.Distance(k, _searchText)))
.OrderByDescending(i => Similarity(i.SearchingKeys, _searchText))
.Select(GetParent).GetEnumerator();

int index = 0;
Expand Down

0 comments on commit cd6a61a

Please sign in to comment.