35
35
36
36
# Split domains by comma and prepare source/index for this domain:
37
37
# Input data /data/<domain>/search.tsv
38
+ # Prepare domain IDs
38
39
domains = domains .split (',' )
40
+ domain_ids = {}
41
+ for domain in domains :
42
+ # Check uniqueness and skip duplicates
43
+ if domain_id in domain_ids .values ():
44
+ continue
45
+ domain_ids [domain ] = domain_id
39
46
40
47
41
48
# Return maximal number of results
@@ -416,7 +423,7 @@ def displayName():
416
423
"""
417
424
@app .route ('/search' )
418
425
def search ():
419
- global domains
426
+ global domains , domain_ids
420
427
code = 400
421
428
422
429
data = {'query' : '' , 'route' : '/search' , 'template' : 'answer.html' }
@@ -426,7 +433,10 @@ def search():
426
433
if domain not in domains :
427
434
data ['result' ] = {'error' : 'Domain not allowed!' }
428
435
return formatResponse (data , 403 )
429
- domain_id = get_domain_id (domain )
436
+ if domain not in domain_ids :
437
+ data ['result' ] = {'error' : 'Duplicated domain is skipped!' }
438
+ return formatResponse (data , 404 )
439
+ domain_id = domain_ids [domain ]
430
440
data ['domain' ] = domain
431
441
432
442
index = 'search_{}_index' .format (domain_id )
@@ -505,15 +515,18 @@ def search():
505
515
"""
506
516
@app .route ('/update/<path:domain>' , methods = ['POST' ])
507
517
def update (domain ):
508
- global domains
518
+ global domains , domain_ids
509
519
data = {'route' : '/update' , 'template' : None }
510
520
511
521
domain = unquote (domain )
512
522
if domain not in domains :
513
523
data ['result' ] = {'error' : 'Domain not allowed!' }
514
524
return formatResponse (data , 403 )
525
+ if domain not in domain_ids :
526
+ data ['result' ] = {'error' : 'Duplicated domain is skipped!' }
527
+ return formatResponse (data , 404 )
515
528
516
- domain_id = get_domain_id ( domain ) .encode ('utf-8' )
529
+ domain_id = domain_ids [ domain ] .encode ('utf-8' )
517
530
data ['domain' ] = domain .encode ('utf-8' )
518
531
data ['protocol' ] = 'http'
519
532
if request .args .get ('https' , None ):
0 commit comments