File size: 3,145 Bytes
40daea5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
"""Debug why Marlin 5 returns Rail"""

import requests
import xml.etree.ElementTree as ET
import re

def debug_matching():
    """See what matches when searching for Marlin 5"""
    
    # Get Trek XML
    url = 'https://www.trekbisiklet.com.tr/output/8582384479'
    response = requests.get(url, verify=False, timeout=10)
    
    if response.status_code != 200:
        print("Failed to fetch XML")
        return
        
    root = ET.fromstring(response.content)
    
    # Search parameters (from smart_warehouse_with_price.py logic)
    search_name = "marlin 5"
    clean_search = re.sub(r'\s*\(\d{4}\)\s*', '', search_name).strip()
    
    print(f"Searching for: '{search_name}'")
    print(f"Clean search: '{clean_search}'")
    print(f"Search parts: {clean_search.split()}")
    print("\n" + "="*60)
    
    matches = []
    
    for item in root.findall('item'):
        rootlabel_elem = item.find('rootlabel')
        if rootlabel_elem is None or not rootlabel_elem.text:
            continue
            
        item_name = rootlabel_elem.text.lower()
        clean_item = re.sub(r'\s*\(\d{4}\)\s*', '', item_name).strip()
        
        # Calculate score (same logic as smart_warehouse_with_price.py)
        score = 0
        
        # Exact match
        if clean_search == clean_item:
            score += 100
        # Starts with
        elif clean_item.startswith(clean_search + " ") or clean_item == clean_search:
            score += 50
        else:
            # Partial matching
            name_parts = clean_search.split()
            for part in name_parts:
                if part in clean_item:
                    score += 1
        
        if score > 0:
            price_elem = item.find('priceTaxWithCur')
            link_elem = item.find('productLink')
            
            matches.append({
                'original': rootlabel_elem.text,
                'clean': clean_item,
                'score': score,
                'price': price_elem.text if price_elem is not None else 'N/A',
                'link': link_elem.text if link_elem is not None else 'N/A'
            })
    
    # Sort by score
    matches.sort(key=lambda x: x['score'], reverse=True)
    
    print(f"\nFound {len(matches)} matches:")
    print("="*60)
    
    for i, match in enumerate(matches[:20], 1):  # Show top 20
        print(f"\n{i}. Score: {match['score']}")
        print(f"   Original: {match['original']}")
        print(f"   Clean: {match['clean']}")
        print(f"   Price: {match['price']}")
        if match['link'] != 'N/A':
            print(f"   Link: ...{match['link'][-50:]}")
        
        # Explain why it matched
        print("   Why matched:")
        if clean_search == match['clean']:
            print("     - EXACT MATCH")
        elif match['clean'].startswith(clean_search + " "):
            print("     - STARTS WITH search")
        else:
            parts = clean_search.split()
            for part in parts:
                if part in match['clean']:
                    print(f"     - Contains '{part}'")

if __name__ == "__main__":
    debug_matching()