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

View File

@ -143,7 +143,8 @@ class SphinxHelper:
out_filename = os.path.abspath(config_fname)
logging.info("Creating main config %s...", out_filename)
conf_data = template('aore/templates/sphinx/sphinx.conf', sphinx_listen=sphinx_conf.listen,
conf_data = template('aore/templates/sphinx/sphinx.conf',
sphinx_listen=sphinx_conf.listen.replace("unix://", ''),
sphinx_var_path=sphinx_conf.var_dir)
f = open(out_filename, "w")

View File

@ -24,6 +24,7 @@ index {{ index_name }}
# strip html by default
html_strip = 1
docinfo = extern
ignore_chars = @, -
charset_table = 0..9, A..Z->a..z, _, a..z, \

View File

@ -20,5 +20,4 @@ index {{index_name}}
source = {{index_name}}
path = {{sphinx_var_path}}/data/{{index_name}}
docinfo = extern
charset_type = utf-8
}

View File

@ -43,11 +43,6 @@ searchd
# mandatory
pid_file = {{sphinx_var_path}}/run/searchd.pid
# max amount of matches the daemon ever keeps in RAM, per-index
# WARNING, THERE'S ALSO PER-QUERY LIMIT, SEE SetLimits() API CALL
# default is 1000 (just like Google)
max_matches = 1000
# seamless rotate, prevents rotate stalls if precaching huge datasets
# optional, default is 1
seamless_rotate = 1