-
Notifications
You must be signed in to change notification settings - Fork 0
/
SolrSearch.py
58 lines (42 loc) · 1.6 KB
/
SolrSearch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import pysolr
import CONSTANTS
import SecondaryScoring
def search(query, scoring_method, collection):
collection_list = [CONSTANTS.SOLR_URL_CORE, CONSTANTS.SOLR_URL_INTER, CONSTANTS.SOLR_URL_TEST]
solr = pysolr.Solr(collection_list[int(collection)-1], timeout=10)
results = solr.search(query, fl='id,score', rows=CONSTANTS.NO_OF_ROWS)
# query = input('Enter query: ')
#Test this for total
# query = 'calcium'
# query = '(description:calcium)^2 mesh_terms:calcium'
#Test this for count vs total
# query = 'sequence'
# for result in results:
#
# print("The title is '{0}'.".format(result['id']))
# print("The score is {0}.".format(result['score']))
# # print("Contents= {0}".format(result['description']))
# print('\nSelect Secondary scoring option:')
# print('1. Scores total')
# print('2. Scores total (log10)')
# print('3. No of Documents\n')
#Testing
# scoring_method = input('Enter scoring option: ')
# scoring_method = 4
options = {
1: SecondaryScoring.total_scoring,
2: SecondaryScoring.count_scoring,
3: SecondaryScoring.highest_relevancy,
4: SecondaryScoring.log10_scoring
}
#Printing all for testing
# print(results.docs)
# print(SecondaryScoring.compute_total_scores(results))
# print(options[1](results))
# print(options[2](results))
# print(options[3](results))
#Printing input option
# print(options[int(scoring_method)](results))
# print(options[1](results))
final_result = options[int(scoring_method)](results)
return final_result