mirror of
https://github.com/partitioncloud/partitioncloud-server.git
synced 2025-04-22 13:43: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
|
from uuid import uuid4
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import threading
|
import threading
|
||||||
|
import socket
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import googlesearch
|
import googlesearch
|
||||||
|
|
||||||
from .db import get_db
|
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):
|
def local_search(query, partitions):
|
||||||
"""
|
"""
|
||||||
@ -60,6 +63,8 @@ def online_search(query, num_queries):
|
|||||||
db = get_db()
|
db = get_db()
|
||||||
query = f"partition filetype:pdf {query}"
|
query = f"partition filetype:pdf {query}"
|
||||||
partitions = []
|
partitions = []
|
||||||
|
|
||||||
|
try:
|
||||||
results = googlesearch.search(
|
results = googlesearch.search(
|
||||||
query,
|
query,
|
||||||
num=num_queries,
|
num=num_queries,
|
||||||
@ -90,6 +95,9 @@ def online_search(query, num_queries):
|
|||||||
except db.IntegrityError:
|
except db.IntegrityError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
except urllib.error.URLError: # Unable to access network
|
||||||
|
return []
|
||||||
|
|
||||||
threads = [threading.Thread(target=download_search_result, args=(elem,)) for elem in partitions]
|
threads = [threading.Thread(target=download_search_result, args=(elem,)) for elem in partitions]
|
||||||
|
|
||||||
for thread in threads:
|
for thread in threads:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user