Небольшие правки
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from aore.fias.search import SphinxSearch
|
||||
import logging
|
||||
|
||||
|
||||
class FiasFactory:
|
||||
@@ -7,11 +8,11 @@ class FiasFactory:
|
||||
self.searcher = SphinxSearch()
|
||||
|
||||
# text - строка поиска
|
||||
# strong - строгий поиск или "мягкий" (с допущением ошибок, опечаток)
|
||||
# strong - строгий поиск (True) или "мягкий" (False) (с допущением ошибок, опечаток)
|
||||
# out_format - "full" or "simple" - полный (подробно для каждого подпункта) или простой (только строка и AOID)
|
||||
def find(self, text, strong=False, out_format="simple"):
|
||||
try:
|
||||
results = self.searcher.find(text, strong)
|
||||
|
||||
print results
|
||||
except:
|
||||
return []
|
||||
|
||||
@@ -5,6 +5,7 @@ import re
|
||||
import Levenshtein
|
||||
import psycopg2
|
||||
import sphinxapi
|
||||
import logging
|
||||
|
||||
from aore.config import db as dbparams, sphinx_index_sugg, sphinx_index_addjobj
|
||||
from aore.dbutils.dbimpl import DBImpl
|
||||
@@ -23,14 +24,14 @@ class SphinxSearch:
|
||||
self.db = DBImpl(psycopg2, dbparams)
|
||||
|
||||
self.client_sugg = sphinxapi.SphinxClient()
|
||||
self.client_sugg.SetServer("localhost", 9312)
|
||||
self.client_sugg.SetServer("127.0.0.1", 9312)
|
||||
self.client_sugg.SetLimits(0, 10)
|
||||
self.client_sugg.SetConnectTimeout(3.0)
|
||||
self.client_sugg.SetConnectTimeout(7.0)
|
||||
|
||||
self.client_show = sphinxapi.SphinxClient()
|
||||
self.client_show.SetServer("localhost", 9312)
|
||||
self.client_show.SetServer("127.0.0.1", 9312)
|
||||
self.client_show.SetLimits(0, 10)
|
||||
self.client_show.SetConnectTimeout(3.0)
|
||||
self.client_show.SetConnectTimeout(7.0)
|
||||
|
||||
def __configure(self, index_name, wlen=None):
|
||||
if index_name == "idx_fias_sugg":
|
||||
@@ -42,7 +43,7 @@ class SphinxSearch:
|
||||
self.client_sugg.SetSortMode(sphinxapi.SPH_SORT_EXTENDED, "krank DESC")
|
||||
else:
|
||||
self.client_show.SetMatchMode(sphinxapi.SPH_MATCH_EXTENDED2)
|
||||
self.client_show.SetRankingMode(sphinxapi.SPH_RANK_BM25)
|
||||
#self.client_show.SetRankingMode(sphinxapi.SPH_RANK_BM25)
|
||||
|
||||
def __get_suggest(self, word, rating_limit, count):
|
||||
word_len = str(len(word) / 2)
|
||||
@@ -101,6 +102,7 @@ class SphinxSearch:
|
||||
if word != '':
|
||||
we = WordEntry(self.db, word)
|
||||
self.__add_word_variations(we, strong)
|
||||
|
||||
if we.get_variations() == "()":
|
||||
raise BaseException("Cannot process sentence.")
|
||||
yield we
|
||||
@@ -111,7 +113,13 @@ class SphinxSearch:
|
||||
sentence = "{}".format(" MAYBE ".join(x.get_variations() for x in word_entries))
|
||||
|
||||
self.__configure(sphinx_index_addjobj)
|
||||
logging.info("QUERY "+sentence)
|
||||
rs = self.client_show.Query(sentence, sphinx_index_addjobj)
|
||||
logging.info("OK")
|
||||
|
||||
print json.dumps(rs)
|
||||
|
||||
logging.info("OK")
|
||||
|
||||
results = []
|
||||
for ma in rs['matches']:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
import logging
|
||||
|
||||
|
||||
class WordEntry:
|
||||
@@ -65,7 +66,7 @@ class WordEntry:
|
||||
return "({})".format(" | ".join(self.variations))
|
||||
|
||||
def __get_ranks(self):
|
||||
word_len = len(self.word)
|
||||
word_len = len(unicode(self.word))
|
||||
sql_qry = "SELECT COUNT(*), NULL FROM \"AOTRIG\" WHERE word LIKE '{}%' AND LENGTH(word) > {} " \
|
||||
"UNION ALL SELECT COUNT(*), NULL FROM \"AOTRIG\" WHERE word='{}' " \
|
||||
"UNION ALL SELECT COUNT(*), MAX(scname) FROM \"SOCRBASE\" WHERE socrname ILIKE '{}'" \
|
||||
|
||||
Reference in New Issue
Block a user