Spaces:
Running
on
Zero
Running
on
Zero
Update search_history.py
Browse files- search_history.py +99 -46
search_history.py
CHANGED
@@ -58,58 +58,111 @@ class SearchHistoryComponent:
|
|
58 |
</div>
|
59 |
"""
|
60 |
|
61 |
-
if search_type == "criteria":
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
else:
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
|
87 |
-
# 共用的結果顯示邏輯
|
88 |
-
html += """
|
89 |
-
<div class="results-list">
|
90 |
-
|
91 |
-
|
92 |
-
"""
|
93 |
|
94 |
-
if results:
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
|
108 |
-
html += """
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
</div>
|
|
|
|
|
|
|
110 |
</div>
|
111 |
</div>
|
112 |
-
|
|
|
113 |
|
114 |
html += "</div>"
|
115 |
return html
|
|
|
58 |
</div>
|
59 |
"""
|
60 |
|
61 |
+
# if search_type == "criteria":
|
62 |
+
# # 原有的條件搜尋顯示邏輯
|
63 |
+
# prefs = entry.get('preferences', {})
|
64 |
+
# html += f"""
|
65 |
+
# <div class="params-list">
|
66 |
+
# <h4>Search Parameters:</h4>
|
67 |
+
# <ul>
|
68 |
+
# <li><span class="param-label">Living Space:</span> {prefs.get('living_space', 'N/A')}</li>
|
69 |
+
# <li><span class="param-label">Exercise Time:</span> {prefs.get('exercise_time', 'N/A')} minutes</li>
|
70 |
+
# <li><span class="param-label">Grooming:</span> {prefs.get('grooming_commitment', 'N/A')}</li>
|
71 |
+
# <li><span class="param-label">Experience:</span> {prefs.get('experience_level', 'N/A')}</li>
|
72 |
+
# <li><span class="param-label">Children at Home:</span> {"Yes" if prefs.get('has_children') else "No"}</li>
|
73 |
+
# <li><span class="param-label">Noise Tolerance:</span> {prefs.get('noise_tolerance', 'N/A')}</li>
|
74 |
+
# </ul>
|
75 |
+
# </div>
|
76 |
+
# """
|
77 |
+
# else:
|
78 |
+
# # Description 搜尋的顯示邏輯
|
79 |
+
# description = entry.get('description', 'No description provided')
|
80 |
+
# html += f"""
|
81 |
+
# <div class="description-section">
|
82 |
+
# <h4>Search Description:</h4>
|
83 |
+
# <p class="user-description">{description}</p>
|
84 |
+
# </div>
|
85 |
+
# """
|
86 |
|
87 |
+
# # 共用的結果顯示邏輯
|
88 |
+
# html += """
|
89 |
+
# <div class="results-list">
|
90 |
+
# <h4>Top 10 Breed Matches:</h4>
|
91 |
+
# <div class="breed-list">
|
92 |
+
# """
|
93 |
|
94 |
+
# if results:
|
95 |
+
# for i, result in enumerate(results[:10], 1):
|
96 |
+
# breed_name = result.get('breed', 'Unknown breed').replace('_', ' ')
|
97 |
+
# score = result.get('overall_score', result.get('final_score', 0))
|
98 |
+
# html += f"""
|
99 |
+
# <div class="breed-item">
|
100 |
+
# <div class="breed-info">
|
101 |
+
# <span class="breed-rank">#{i}</span>
|
102 |
+
# <span class="breed-name">{breed_name}</span>
|
103 |
+
# <span class="breed-score">{score*100:.1f}%</span>
|
104 |
+
# </div>
|
105 |
+
# </div>
|
106 |
+
# """
|
107 |
|
108 |
+
# html += """
|
109 |
+
# </div>
|
110 |
+
# </div>
|
111 |
+
# </div>
|
112 |
+
# """
|
113 |
+
|
114 |
+
if search_type == "criteria":
|
115 |
+
# 原有的條件搜尋顯示邏輯
|
116 |
+
prefs = entry.get('preferences', {})
|
117 |
+
html += f"""
|
118 |
+
<div class="params-list" style="background: #f8fafc; padding: 16px; border-radius: 8px; margin-bottom: 16px;">
|
119 |
+
<h4 style="font-size: 1.1em; font-weight: 600; color: #2D3748; margin-bottom: 12px; border-bottom: 2px solid #E2E8F0; padding-bottom: 8px;">Search Parameters:</h4>
|
120 |
+
<ul style="display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; list-style: none; padding: 0;">
|
121 |
+
<li><span class="param-label" style="font-weight: 600; color: #2D3748;">Living Space:</span> {prefs.get('living_space', 'N/A')}</li>
|
122 |
+
<li><span class="param-label" style="font-weight: 600; color: #2D3748;">Exercise Time:</span> {prefs.get('exercise_time', 'N/A')} minutes</li>
|
123 |
+
<li><span class="param-label" style="font-weight: 600; color: #2D3748;">Grooming:</span> {prefs.get('grooming_commitment', 'N/A')}</li>
|
124 |
+
<li><span class="param-label" style="font-weight: 600; color: #2D3748;">Experience:</span> {prefs.get('experience_level', 'N/A')}</li>
|
125 |
+
<li><span class="param-label" style="font-weight: 600; color: #2D3748;">Children at Home:</span> {"Yes" if prefs.get('has_children') else "No"}</li>
|
126 |
+
<li><span class="param-label" style="font-weight: 600; color: #2D3748;">Noise Tolerance:</span> {prefs.get('noise_tolerance', 'N/A')}</li>
|
127 |
+
</ul>
|
128 |
+
</div>
|
129 |
+
"""
|
130 |
+
else:
|
131 |
+
# Description 搜尋的顯示邏輯
|
132 |
+
description = entry.get('description', 'No description provided')
|
133 |
+
html += f"""
|
134 |
+
<div class="description-section" style="background: #f8fafc; padding: 16px; border-radius: 8px; margin-bottom: 16px;">
|
135 |
+
<h4 style="font-size: 1.1em; font-weight: 600; color: #2D3748; margin-bottom: 12px; border-bottom: 2px solid #E2E8F0; padding-bottom: 8px;">Search Description:</h4>
|
136 |
+
<p class="user-description" style="color: #4A5568; font-style: italic; line-height: 1.6; margin: 8px 0;">{description}</p>
|
137 |
+
</div>
|
138 |
+
"""
|
139 |
+
|
140 |
+
# 共用的結果顯示邏輯
|
141 |
+
html += """
|
142 |
+
<div class="results-list">
|
143 |
+
<h4 style="font-size: 1.1em; font-weight: 600; color: #2D3748; margin-bottom: 12px; border-bottom: 2px solid #E2E8F0; padding-bottom: 8px;">Top 10 Breed Matches:</h4>
|
144 |
+
<div class="breed-list">
|
145 |
+
"""
|
146 |
+
|
147 |
+
if results:
|
148 |
+
for i, result in enumerate(results[:10], 1):
|
149 |
+
breed_name = result.get('breed', 'Unknown breed').replace('_', ' ')
|
150 |
+
score = result.get('overall_score', result.get('final_score', 0))
|
151 |
+
html += f"""
|
152 |
+
<div class="breed-item" style="margin-bottom: 8px;">
|
153 |
+
<div class="breed-info" style="display: flex; align-items: center; justify-content: space-between; padding: 8px; background: #f8fafc; border-radius: 6px;">
|
154 |
+
<span class="breed-rank" style="background: linear-gradient(135deg, #4299e1, #48bb78); color: white; padding: 4px 10px; border-radius: 6px; font-weight: 600; min-width: 40px; text-align: center;">#{i}</span>
|
155 |
+
<span class="breed-name" style="font-weight: 500; color: #2D3748; font-size: 1.05em; margin: 0 12px;">{breed_name}</span>
|
156 |
+
<span class="breed-score" style="background: #F0FFF4; color: #48BB78; padding: 4px 8px; border-radius: 4px; font-weight: 600;">{score*100:.1f}%</span>
|
157 |
+
</div>
|
158 |
</div>
|
159 |
+
"""
|
160 |
+
|
161 |
+
html += """
|
162 |
</div>
|
163 |
</div>
|
164 |
+
</div>
|
165 |
+
"""
|
166 |
|
167 |
html += "</div>"
|
168 |
return html
|