mirror of
https://github.com/partitioncloud/partitioncloud-server.git
synced 2025-04-22 05:33:55 +02:00
Fix online search sometimes blocking local search
This commit is contained in:
parent
1d02292c61
commit
971d54af41
@ -5,12 +5,15 @@ Module implémentant la recherche de partitions par mots-clés
|
||||
from uuid import uuid4
|
||||
import urllib.request
|
||||
import threading
|
||||
import socket
|
||||
import os
|
||||
|
||||
import googlesearch
|
||||
|
||||
from .db import get_db
|
||||
|
||||
socket.setdefaulttimeout(5) # Maximum time before we give up on downloading a file (dead url)
|
||||
|
||||
|
||||
def local_search(query, partitions):
|
||||
"""
|
||||
@ -60,6 +63,8 @@ def online_search(query, num_queries):
|
||||
db = get_db()
|
||||
query = f"partition filetype:pdf {query}"
|
||||
partitions = []
|
||||
|
||||
try:
|
||||
results = googlesearch.search(
|
||||
query,
|
||||
num=num_queries,
|
||||
@ -90,6 +95,9 @@ def online_search(query, num_queries):
|
||||
except db.IntegrityError:
|
||||
pass
|
||||
|
||||
except urllib.error.URLError: # Unable to access network
|
||||
return []
|
||||
|
||||
threads = [threading.Thread(target=download_search_result, args=(elem,)) for elem in partitions]
|
||||
|
||||
for thread in threads:
|
||||
|
Loading…
x
Reference in New Issue
Block a user