Небольшие правки
This commit is contained in:
parent
77f122ecd3
commit
c2fd52c825
@ -1,5 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from aore.fias.search import SphinxSearch
|
from aore.fias.search import SphinxSearch
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
class FiasFactory:
|
class FiasFactory:
|
||||||
@ -7,11 +8,11 @@ class FiasFactory:
|
|||||||
self.searcher = SphinxSearch()
|
self.searcher = SphinxSearch()
|
||||||
|
|
||||||
# text - строка поиска
|
# text - строка поиска
|
||||||
# strong - строгий поиск или "мягкий" (с допущением ошибок, опечаток)
|
# strong - строгий поиск (True) или "мягкий" (False) (с допущением ошибок, опечаток)
|
||||||
# out_format - "full" or "simple" - полный (подробно для каждого подпункта) или простой (только строка и AOID)
|
# out_format - "full" or "simple" - полный (подробно для каждого подпункта) или простой (только строка и AOID)
|
||||||
def find(self, text, strong=False, out_format="simple"):
|
def find(self, text, strong=False, out_format="simple"):
|
||||||
try:
|
try:
|
||||||
results = self.searcher.find(text, strong)
|
results = self.searcher.find(text, strong)
|
||||||
|
print results
|
||||||
except:
|
except:
|
||||||
return []
|
return []
|
||||||
|
@ -5,6 +5,7 @@ import re
|
|||||||
import Levenshtein
|
import Levenshtein
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import sphinxapi
|
import sphinxapi
|
||||||
|
import logging
|
||||||
|
|
||||||
from aore.config import db as dbparams, sphinx_index_sugg, sphinx_index_addjobj
|
from aore.config import db as dbparams, sphinx_index_sugg, sphinx_index_addjobj
|
||||||
from aore.dbutils.dbimpl import DBImpl
|
from aore.dbutils.dbimpl import DBImpl
|
||||||
@ -23,14 +24,14 @@ class SphinxSearch:
|
|||||||
self.db = DBImpl(psycopg2, dbparams)
|
self.db = DBImpl(psycopg2, dbparams)
|
||||||
|
|
||||||
self.client_sugg = sphinxapi.SphinxClient()
|
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.SetLimits(0, 10)
|
||||||
self.client_sugg.SetConnectTimeout(3.0)
|
self.client_sugg.SetConnectTimeout(7.0)
|
||||||
|
|
||||||
self.client_show = sphinxapi.SphinxClient()
|
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.SetLimits(0, 10)
|
||||||
self.client_show.SetConnectTimeout(3.0)
|
self.client_show.SetConnectTimeout(7.0)
|
||||||
|
|
||||||
def __configure(self, index_name, wlen=None):
|
def __configure(self, index_name, wlen=None):
|
||||||
if index_name == "idx_fias_sugg":
|
if index_name == "idx_fias_sugg":
|
||||||
@ -42,7 +43,7 @@ class SphinxSearch:
|
|||||||
self.client_sugg.SetSortMode(sphinxapi.SPH_SORT_EXTENDED, "krank DESC")
|
self.client_sugg.SetSortMode(sphinxapi.SPH_SORT_EXTENDED, "krank DESC")
|
||||||
else:
|
else:
|
||||||
self.client_show.SetMatchMode(sphinxapi.SPH_MATCH_EXTENDED2)
|
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):
|
def __get_suggest(self, word, rating_limit, count):
|
||||||
word_len = str(len(word) / 2)
|
word_len = str(len(word) / 2)
|
||||||
@ -101,6 +102,7 @@ class SphinxSearch:
|
|||||||
if word != '':
|
if word != '':
|
||||||
we = WordEntry(self.db, word)
|
we = WordEntry(self.db, word)
|
||||||
self.__add_word_variations(we, strong)
|
self.__add_word_variations(we, strong)
|
||||||
|
|
||||||
if we.get_variations() == "()":
|
if we.get_variations() == "()":
|
||||||
raise BaseException("Cannot process sentence.")
|
raise BaseException("Cannot process sentence.")
|
||||||
yield we
|
yield we
|
||||||
@ -111,7 +113,13 @@ class SphinxSearch:
|
|||||||
sentence = "{}".format(" MAYBE ".join(x.get_variations() for x in word_entries))
|
sentence = "{}".format(" MAYBE ".join(x.get_variations() for x in word_entries))
|
||||||
|
|
||||||
self.__configure(sphinx_index_addjobj)
|
self.__configure(sphinx_index_addjobj)
|
||||||
|
logging.info("QUERY "+sentence)
|
||||||
rs = self.client_show.Query(sentence, sphinx_index_addjobj)
|
rs = self.client_show.Query(sentence, sphinx_index_addjobj)
|
||||||
|
logging.info("OK")
|
||||||
|
|
||||||
|
print json.dumps(rs)
|
||||||
|
|
||||||
|
logging.info("OK")
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
for ma in rs['matches']:
|
for ma in rs['matches']:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import re
|
import re
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
class WordEntry:
|
class WordEntry:
|
||||||
@ -65,7 +66,7 @@ class WordEntry:
|
|||||||
return "({})".format(" | ".join(self.variations))
|
return "({})".format(" | ".join(self.variations))
|
||||||
|
|
||||||
def __get_ranks(self):
|
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) > {} " \
|
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(*), NULL FROM \"AOTRIG\" WHERE word='{}' " \
|
||||||
"UNION ALL SELECT COUNT(*), MAX(scname) FROM \"SOCRBASE\" WHERE socrname ILIKE '{}'" \
|
"UNION ALL SELECT COUNT(*), MAX(scname) FROM \"SOCRBASE\" WHERE socrname ILIKE '{}'" \
|
||||||
|
@ -4,4 +4,7 @@ CREATE INDEX "sphinx_ind_livestatus" ON "ADDROBJ" USING btree ("actstatus", "liv
|
|||||||
CREATE INDEX "sphinx_ind_aoguid" ON "ADDROBJ" USING btree ("aoguid");
|
CREATE INDEX "sphinx_ind_aoguid" ON "ADDROBJ" USING btree ("aoguid");
|
||||||
CREATE INDEX "SOCRBASE_scname_idx" ON "SOCRBASE" USING btree ("scname");
|
CREATE INDEX "SOCRBASE_scname_idx" ON "SOCRBASE" USING btree ("scname");
|
||||||
CREATE INDEX "SOCRBASE_socrname_idx" ON "SOCRBASE" USING btree ("socrname");
|
CREATE INDEX "SOCRBASE_socrname_idx" ON "SOCRBASE" USING btree ("socrname");
|
||||||
|
CREATE INDEX "SOCRBASE_scname_gin_idx" ON "SOCRBASE" USING gin(scname gin_trgm_ops);
|
||||||
|
CREATE INDEX "SOCRBASE_socrname_gin_idx" ON "SOCRBASE" USING gin(socrname gin_trgm_ops);
|
||||||
CREATE INDEX "AOTRIG_word_idx" ON "AOTRIG" USING btree ("word");
|
CREATE INDEX "AOTRIG_word_idx" ON "AOTRIG" USING btree ("word");
|
||||||
|
CREATE INDEX "AOTRIG_word_gin_idx" ON "AOTRIG" USING gin(word gin_trgm_ops);
|
||||||
|
@ -72,7 +72,7 @@ class Updater:
|
|||||||
self.__init_update_entries(updates_generator)
|
self.__init_update_entries(updates_generator)
|
||||||
self.db_handler.pre_update()
|
self.db_handler.pre_update()
|
||||||
|
|
||||||
for update_entry in self.updates_generator:
|
for update_entry in self.updalist_generator:
|
||||||
logging.info("Processing update #{}".format(update_entry['intver']))
|
logging.info("Processing update #{}".format(update_entry['intver']))
|
||||||
for table_entry in self.tablelist_generator(update_entry['delta_url']):
|
for table_entry in self.tablelist_generator(update_entry['delta_url']):
|
||||||
self.process_single_entry(table_entry.operation_type, table_entry)
|
self.process_single_entry(table_entry.operation_type, table_entry)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import optparse
|
import optparse
|
||||||
|
|
||||||
from aore.fias.search import SphinxSearch
|
from aore.fias.fiasfactory import FiasFactory
|
||||||
from aore.miscutils.sphinx import SphinxHelper
|
from aore.miscutils.sphinx import SphinxHelper
|
||||||
from aore.updater.updater import Updater
|
from aore.updater.updater import Updater
|
||||||
from aore.updater.soapreceiver import SoapReceiver
|
from aore.updater.soapreceiver import SoapReceiver
|
||||||
@ -116,8 +116,8 @@ def main():
|
|||||||
|
|
||||||
# 4 Debug purposes..
|
# 4 Debug purposes..
|
||||||
if options.test:
|
if options.test:
|
||||||
sph = SphinxSearch()
|
sph = FiasFactory()
|
||||||
sph.find('кедровая пасраул')
|
sph.find('ул кемровая пасраул алтай майминский р-н')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user