Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d23d526629 |
+4
-4
@@ -157,16 +157,16 @@ class Database:
|
|||||||
if category:
|
if category:
|
||||||
cursor.execute('''
|
cursor.execute('''
|
||||||
SELECT * FROM articles
|
SELECT * FROM articles
|
||||||
WHERE (product_names LIKE ? OR keywords LIKE ? OR summary LIKE ? OR content LIKE ?)
|
WHERE (product_names LIKE ? OR keywords LIKE ? OR summary LIKE ? OR content LIKE ? OR url LIKE ?)
|
||||||
AND category = ?
|
AND category = ?
|
||||||
ORDER BY fetch_date DESC
|
ORDER BY fetch_date DESC
|
||||||
''', (f'%{keyword}%', f'%{keyword}%', f'%{keyword}%', f'%{keyword}%', category))
|
''', (f'%{keyword}%', f'%{keyword}%', f'%{keyword}%', f'%{keyword}%', f'%{keyword}%', category))
|
||||||
else:
|
else:
|
||||||
cursor.execute('''
|
cursor.execute('''
|
||||||
SELECT * FROM articles
|
SELECT * FROM articles
|
||||||
WHERE product_names LIKE ? OR keywords LIKE ? OR summary LIKE ? OR content LIKE ?
|
WHERE product_names LIKE ? OR keywords LIKE ? OR summary LIKE ? OR content LIKE ? OR url LIKE ?
|
||||||
ORDER BY fetch_date DESC
|
ORDER BY fetch_date DESC
|
||||||
''', (f'%{keyword}%', f'%{keyword}%', f'%{keyword}%', f'%{keyword}%'))
|
''', (f'%{keyword}%', f'%{keyword}%', f'%{keyword}%', f'%{keyword}%', f'%{keyword}%'))
|
||||||
return [dict(row) for row in cursor.fetchall()]
|
return [dict(row) for row in cursor.fetchall()]
|
||||||
|
|
||||||
def get_article_by_id(self, article_id):
|
def get_article_by_id(self, article_id):
|
||||||
|
|||||||
@@ -157,12 +157,17 @@ class SearchService:
|
|||||||
if match:
|
if match:
|
||||||
title = match.group(1)
|
title = match.group(1)
|
||||||
ref = match.group(2)
|
ref = match.group(2)
|
||||||
# 放宽过滤条件:只要不是纯域名格式就保留
|
# 过滤纯域名格式
|
||||||
if not (title.endswith('.com') or title.endswith('.cn') or title.endswith('.net')):
|
is_domain = (title.endswith('.com') or title.endswith('.cn') or
|
||||||
|
title.endswith('.net') or title.endswith('.org') or
|
||||||
|
title.endswith('.edu') or title.endswith('.gov'))
|
||||||
|
if not is_domain:
|
||||||
refs.append((title, ref))
|
refs.append((title, ref))
|
||||||
|
|
||||||
# 获取每个结果的 URL
|
# 获取每个结果的 URL,多获取几个以防解析失败
|
||||||
for title, ref in refs[:max_results]:
|
for title, ref in refs[:max_results + 5]:
|
||||||
|
if len(results) >= max_results:
|
||||||
|
break
|
||||||
url = self._get_link_url(ref)
|
url = self._get_link_url(ref)
|
||||||
if url and 'bing.com/search' not in url: # 过滤搜索结果页本身的链接
|
if url and 'bing.com/search' not in url: # 过滤搜索结果页本身的链接
|
||||||
results.append({
|
results.append({
|
||||||
|
|||||||
Reference in New Issue
Block a user