Skip to content

Commit

Permalink
(Hopefully) fixed an issue searching for item text in foreign languages
Browse files Browse the repository at this point in the history
  • Loading branch information
test90 committed Sep 30, 2024
1 parent 47a4bb9 commit e088fa7
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 37 deletions.
6 changes: 3 additions & 3 deletions IAGrim/Database/DAO/PlayerItemDaoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,9 @@ public List<PlayerItem> SearchForItems(ItemSearchRequest query) {

if (!string.IsNullOrEmpty(query.Wildcard)) {
// queryFragments.Add("(PI.namelowercase LIKE :name OR R.text LIKE :wildcard)");
queryFragments.Add("(PI.namelowercase LIKE :name OR R.id IN (SELECT replicaitemid FROM replicaitemrow WHERE text LIKE :wildcard))");
queryParams.Add("wildcard", $"%{query.Wildcard.ToLower()}%");
queryParams.Add("name", $"%{query.Wildcard.Replace(' ', '%').ToLower()}%");
queryFragments.Add("(PI.namelowercase LIKE :name OR R.id IN (SELECT replicaitemid FROM replicaitemrow WHERE IFNULL(textlowercase, text) LIKE :wildcard))");
queryParams.Add("wildcard", $"%{query.Wildcard.ToLowerInvariant()}%");
queryParams.Add("name", $"%{query.Wildcard.Replace(' ', '%').ToLowerInvariant()}%");
}

// Filter by mod/hc
Expand Down
1 change: 1 addition & 0 deletions IAGrim/Database/Model/ReplicaItemRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public class ReplicaItemRow {
public virtual long ReplicaItemId { get; set; }
public virtual long Type { get; set; } = 0;
public virtual string Text { get; set; } = "";
public virtual string TextLowercase { get; set; } = "";
}
}
1 change: 1 addition & 0 deletions IAGrim/Database/Model/ReplicaItemRow.hbm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@

<property name="Type" />
<property name="Text" />
<property name="TextLowercase" />
</class>
</hibernate-mapping>
1 change: 1 addition & 0 deletions IAGrim/Services/ItemReplica/ItemReplicaParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ private void Process(string filename) {
var stats = template.stats
.Select(m => new ReplicaItemRow {
Text = Regex.Replace(m.text.Trim(), @"(\^.?)", ""),
TextLowercase = Regex.Replace(m.text.Trim(), @"(\^.?)", "").ToLowerInvariant(),
Type = Int32.Parse(m.type),
}).ToList();

Expand Down
2 changes: 1 addition & 1 deletion IAGrim/Services/ItemReplica/ReplicaCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void Add(string hash) {
_cache.Add(hash, 0);

// TODO: In the future, delete the oldest or something
if (_cache.Keys.Count > 10000)
if (_cache.Keys.Count > 500000)
_cache.Clear();
}

Expand Down
3 changes: 1 addition & 2 deletions IAGrim/Services/ItemReplicaService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ private bool Process() {
count += items.Count;
foreach (var item in items) {
var hash = item.Id + ".csv";
if (_cache.Exists(
hash)) // Don't ask for the same item twice. Esp if the user somehow gets two identical items in, this would infinitely loop.
if (_cache.Exists(hash)) // Don't ask for the same item twice. Esp if the user somehow gets two identical items in, this would infinitely loop.
continue;


Expand Down
31 changes: 0 additions & 31 deletions IAGrim/Services/ItemStatService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,37 +82,6 @@ private List<BuddyItem> GetBuddyItems(List<PlayerHeldItem> items) {
return items.Where(IsBuddyItem).Select(item => item as BuddyItem).ToList();
}

private void ApplyStatsToAugmentations(List<PlayerHeldItem> items) {
ApplyStatsToDbItems(items, StatFetch.AugmentItems);
}

private void ApplyStatsToDbItems(List<PlayerHeldItem> items, StatFetch type) {
var records = GetRecordsForItems(items);
Dictionary<string, List<DBStatRow>> statMap = _databaseItemStatDao.GetStats(records, type);

foreach (PlayerHeldItem phi in items) {
List<DBStatRow> stats = new List<DBStatRow>();
if (statMap.ContainsKey(phi.BaseRecord))
stats.AddRange(Filter(statMap[phi.BaseRecord]));

var statsWithText = Filter(stats.Where(m => !string.IsNullOrEmpty(m.TextValue)));
List<DBStatRow> statsWithNumerics = stats.Where(m => string.IsNullOrEmpty(m.TextValue))
.GroupBy(r => r.Stat)
.Select(g => new DBStatRow {
Record = g.FirstOrDefault()?.Record,
TextValue = g.FirstOrDefault()?.TextValue,
Stat = g.FirstOrDefault()?.Stat,
Value = g.Sum(v => v.Value)
})
.ToList();

statsWithNumerics.AddRange(statsWithText);

phi.Tags = new HashSet<DBStatRow>(statsWithNumerics);
}

Logger.Debug($"Applied stats to {items.Count} items");
}

public void ApplyStats(IEnumerable<PlayerHeldItem> itemSource) {
var items = itemSource.ToList();
Expand Down

0 comments on commit e088fa7

Please sign in to comment.