mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-31 14:42:10 +00:00
allow search files with specified suffix(es)
This commit is contained in:
@@ -6,7 +6,7 @@ if getattr(settings, 'ENABLE_FILE_SEARCH', False):
|
||||
from seafes import es_get_conn, es_search
|
||||
|
||||
es_conn = None
|
||||
def search_file_by_name(request, keyword, start, size):
|
||||
def search_file_by_name(request, keyword, suffixes, start, size):
|
||||
owned_repos, shared_repos, groups_repos, pub_repo_list = get_user_repos(request.user)
|
||||
|
||||
# unify the repo.owner property
|
||||
@@ -35,7 +35,7 @@ if getattr(settings, 'ENABLE_FILE_SEARCH', False):
|
||||
global es_conn
|
||||
if es_conn is None:
|
||||
es_conn = es_get_conn()
|
||||
files_found, total = es_search(es_conn, nonpub_repo_ids, keyword, start, size)
|
||||
files_found, total = es_search(es_conn, nonpub_repo_ids, keyword, suffixes, start, size)
|
||||
|
||||
if len(files_found) > 0:
|
||||
# construt a (id, repo) hash table for fast lookup
|
||||
@@ -59,12 +59,12 @@ if getattr(settings, 'ENABLE_FILE_SEARCH', False):
|
||||
return files_found, total
|
||||
|
||||
|
||||
def search_repo_file_by_name(request, repo, keyword, start, size):
|
||||
def search_repo_file_by_name(request, repo, keyword, suffixes, start, size):
|
||||
global es_conn
|
||||
if es_conn is None:
|
||||
es_conn = es_get_conn()
|
||||
|
||||
files_found, total = es_search(es_conn, [repo.id], keyword, start, size)
|
||||
files_found, total = es_search(es_conn, [repo.id], keyword, suffixes, start, size)
|
||||
|
||||
for f in files_found:
|
||||
f['repo'] = repo
|
||||
|
@@ -5,9 +5,26 @@ from seaserv import get_repo
|
||||
from seahub.auth.decorators import login_required
|
||||
from seahub.utils.search import search_file_by_name, search_repo_file_by_name
|
||||
|
||||
|
||||
def parse_suffixes(suffixes):
|
||||
if not suffixes:
|
||||
return None
|
||||
|
||||
l = []
|
||||
for suffix in suffixes.split(','):
|
||||
suffix = suffix.strip()
|
||||
if suffix:
|
||||
l.append(suffix)
|
||||
|
||||
print l
|
||||
|
||||
return l
|
||||
|
||||
@login_required
|
||||
def search(request):
|
||||
keyword = request.GET['q']
|
||||
suffixes = parse_suffixes(request.GET.get('suffixes', None))
|
||||
|
||||
current_page = int(request.GET.get('page', '1'))
|
||||
per_page= int(request.GET.get('per_page', '25'))
|
||||
|
||||
@@ -17,15 +34,14 @@ def search(request):
|
||||
scale = request.GET.get('scale', None)
|
||||
repo_id = request.GET.get('search_repo_id', None)
|
||||
repo = None
|
||||
if repo_id:
|
||||
repo = get_repo(repo_id)
|
||||
if scale == 'current' and repo_id:
|
||||
repo = get_repo(repo_id)
|
||||
if repo:
|
||||
results, total = search_repo_file_by_name(request, repo, keyword, start, size)
|
||||
results, total = search_repo_file_by_name(request, repo, keyword, suffixes, start, size)
|
||||
else:
|
||||
results, total = [], 0
|
||||
else:
|
||||
results, total = search_file_by_name(request, keyword, start, size)
|
||||
results, total = search_file_by_name(request, keyword, suffixes, start, size)
|
||||
|
||||
if total > current_page * per_page:
|
||||
has_more = True
|
||||
|
Reference in New Issue
Block a user