Add user rank to result query (sphinx)

This commit is contained in:
Jack Stdin
2016-02-22 21:37:06 +03:00
parent 685c719ec1
commit dc8e5d35a7
5 changed files with 6 additions and 26 deletions

View File

@@ -123,30 +123,16 @@ class SphinxSearch:
good_vars_word_count = len(set([v.parent for v in good_vars]))
freq_vars_word_count = len(set([v.parent for v in freq_vars]))
self.__configure(sphinx_conf.index_addjobj, word_count)
# формируем строки для поиска в Сфинксе
for i in range(good_vars_word_count, max(0, good_vars_word_count - 3), -1):
first_q = "@fullname \"{}\"/{}".format(" ".join(good_var.text for good_var in good_vars), i)
if self.search_freq_words and freq_vars_word_count:
second_q = " @sname {}".format(" ".join(freq_var.text for freq_var in freq_vars))
self.client_show.AddQuery(first_q + second_q, sphinx_conf.index_addjobj)
self.client_show.AddQuery(first_q, sphinx_conf.index_addjobj)
# if self.search_freq_words:
# for j in range(freq_vars_word_count, -1, -1):
# if j == 0:
# second_q = ""
# else:
# second_q = " @sname {}".format(" | ".join(freq_var.text for freq_var in freq_vars), j)
# second_q = second_q.replace("*", "")
#
# print first_q + second_q
# self.client_show.AddQuery(first_q + second_q, sphinx_conf.index_addjobj)
# else:
# print first_q
# self.client_show.AddQuery(first_q, sphinx_conf.index_addjobj)
self.__configure(sphinx_conf.index_addjobj, word_count)
start_t = time.time()
rs = self.client_show.RunQueries()
elapsed_t = time.time() - start_t
@@ -164,9 +150,7 @@ class SphinxSearch:
if not ma['attrs']['aoid'] in parsed_ids:
parsed_ids.append(ma['attrs']['aoid'])
results.append(
dict(aoid=ma['attrs']['aoid'], text=unicode(ma['attrs']['fullname']), ratio=ma['weight'],
dict(aoid=ma['attrs']['aoid'], text=unicode(ma['attrs']['fullname']), ratio=ma['attrs']['krank'],
cort=i))
# results.sort(key=lambda x: Levenshtein.ratio(text, x['text']), reverse=False)
return results