-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
58 lines (44 loc) · 1.59 KB
/
models.py
File metadata and controls
58 lines (44 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Data models for D2R AI Item Tracker."""
from pathlib import Path
from typing import List
class Item:
"""Represents a game item with its properties."""
def __init__(self, text: str, source_file: str, category: str = "MISC"):
self.text = text.strip()
self.source_file = source_file
self.hero_name = Path(source_file).stem
self.category = category.upper()
self.is_ethereal = "ETHEREAL" in self.text.upper()
self.is_socketed = "SOCKETED" in self.text.upper()
def fuzzy_search(
items: List[Item], query: str, category_filter: str = "ALL"
) -> List[Item]:
"""Simple fuzzy search through items with category filtering."""
# First filter by category
if category_filter != "ALL":
items = [item for item in items if item.category == category_filter]
if not query.strip():
return items
query = query.lower()
results = []
for item in items:
text_lower = item.text.lower()
hero_lower = item.hero_name.lower()
# Score based on multiple factors
score = 0
# Exact matches get highest score
if query in text_lower:
score += 100
if query in hero_lower:
score += 50
# Partial word matches
for word in query.split():
if word in text_lower:
score += 20
if word in hero_lower:
score += 10
if score > 0:
results.append((score, item))
# Sort by score descending
results.sort(key=lambda x: x[0], reverse=True)
return [item for score, item in results]