Skip to content

Commit b56d1dc

Browse files
committed
Improved using domains with dash or comma, remove for unique domain id.
1 parent 983cade commit b56d1dc

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Diff for: conf/sphinx/sphinx.conf

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
# Generate proper index and source for each DOMAIN
4-
#
4+
#
55
import sys
66
from os import getenv
77

@@ -152,6 +152,12 @@ if domains is None or len(domains) < 0:
152152
raise Exception('Missing required environment variable DOMAINS!')
153153
sys.exit(1)
154154

155+
156+
def get_domain_id(domain):
157+
# Remove unexpected characters: .:/-,
158+
return domain.replace('.', '').replace(':', '').replace('/', '').replace('-', '').replace(',', '')
159+
160+
155161
# Split domains by comma and prepare source/index for this domain:
156162
# Input data /data/<domain>/search.tsv
157163
domains = domains.split(',')
@@ -161,7 +167,7 @@ index_config = ''
161167
for domain in domains:
162168
# continue
163169
domain_config = ''
164-
domain_id = domain.replace('.', '').replace(':', '').replace('/', '')
170+
domain_id = get_domain_id(domain)
165171
global_search_cols = ''
166172
format_args = {
167173
'domain': domain,

Diff for: web/websearch.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
# Input data /data/<domain>/search.tsv
3838
domains = domains.split(',')
3939

40+
4041
# Return maximal number of results
4142
SEARCH_MAX_COUNT = 100
4243
SEARCH_DEFAULT_COUNT = 20
@@ -46,6 +47,10 @@
4647
SEARCH_DEFAULT_COUNT = int(getenv('SEARCH_DEFAULT_COUNT'))
4748

4849

50+
def get_domain_id(domain):
51+
# Remove unexpected characters: .:/-,
52+
return domain.replace('.', '').replace(':', '').replace('/', '').replace('-', '').replace(',', '')
53+
4954

5055
# ---------------------------------------------------------
5156
"""
@@ -421,7 +426,7 @@ def search():
421426
if domain not in domains:
422427
data['result'] = {'error': 'Domain not allowed!'}
423428
return formatResponse(data, 403)
424-
domain_id = domain.replace('.', '').replace(':', '').replace('/', '')
429+
domain_id = get_domain_id(domain)
425430
data['domain'] = domain
426431

427432
index = 'search_{}_index'.format(domain_id)
@@ -508,7 +513,7 @@ def update(domain):
508513
data['result'] = {'error': 'Domain not allowed!'}
509514
return formatResponse(data, 403)
510515

511-
domain_id = domain.replace('.', '').replace(':', '').replace('/', '').encode('utf-8')
516+
domain_id = get_domain_id(domain).encode('utf-8')
512517
data['domain'] = domain.encode('utf-8')
513518
data['protocol'] = 'http'
514519
if request.args.get('https', None):

0 commit comments

Comments
 (0)