Commit 43c7d4f0 authored by tssasha's avatar tssasha
Browse files

testing upgrade

parent 200aa0c7
......@@ -5,52 +5,66 @@ import json
import requests
test_res = [["query", "context", "my result", "my len", "my time", "fuzzy result", "fuzzy len", "fuzzy time"]]
url = 'http://localhost:8983/solr/yelp/suggest'
def request(data):
def not_null_request(data):
url_values = urllib.parse.urlencode(data)
url_values = url_values.replace('%28', '(')
url_values = url_values.replace('%29', ')')
url_values = url_values.replace('+', '%20')
url = 'http://localhost:8983/solr/yelp/suggest'
full_url = url + '?' + url_values
time = 0
for i in range(10):
response = requests.get(full_url)
time += response.elapsed.total_seconds()
time /= 10
result = json.loads(response.content.decode('utf-8'))['suggest'][data['suggest.dictionary']][data['suggest.q']]['suggestions']
res_list = []
response = requests.get(full_url)
result = json.loads(response.content.decode('utf-8'))['suggest']['mySuggester'][data['suggest.q']]['suggestions']
if len(result) == 0:
return False
for item in result:
res_list.append(item['term'])
if data['suggest.dictionary'] == 'mySuggester':
test_res.append([data['suggest.q'], data['suggest.cfq'], res_list, len(res_list), time])
else:
test_res[-1].append(res_list)
test_res[-1].append(len(res_list))
test_res[-1].append(time)
return True
return False, url_values, []
res_list = [item['term'] for item in result]
return True, url_values, res_list
def request_time(url_values):
full_url = url + '?' + url_values
response = requests.get(full_url)
return response.elapsed.total_seconds()
with open('cities.txt') as c, open('words.txt') as w:
cities = c.read().splitlines()
words = w.read().splitlines()
num = 50
quantity = 0
while quantity < 50:
params = []
while quantity < num:
data = dict()
data['suggest.q'] = random.choice(words)
data['suggest.cfq'] = random.choice(cities)
data['suggest.count'] = '10000'
data['suggest.count'] = '5'
data['suggest.dictionary'] = 'mySuggester'
not_empty = request(data)
if not_empty:
data['suggest.dictionary'] = 'fuzzySuggester'
request(data)
not_null, url_values, my_res_list = not_null_request(data)
if not_null:
params.append(url_values)
test_res.append([data['suggest.q'], data['suggest.cfq'], my_res_list, len(my_res_list), 0])
quantity += 1
for i in range(1, num + 1):
url_values = params[i - 1][:-11] + 'fuzzySuggester'
params.append(url_values)
full_url = url + '?' + url_values
response = requests.get(full_url)
result = json.loads(response.content.decode('utf-8'))['suggest']['fuzzySuggester'][test_res[i][0]]['suggestions']
res_list = [item['term'] for item in result]
test_res[i].append(res_list)
test_res[i].append(len(res_list))
test_res[i].append(0)
time = [0] * num * 2
for i in range(10):
for j in range(num * 2):
time[j] += request_time(params[j])
for i in range(num):
test_res[i + 1][4] = time[i] / 10
test_res[i + 1][7] = time[num + i] / 10
myFile = open('results.csv', 'w')
with myFile:
writer = csv.writer(myFile)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment