Поправлена генерация конфига
This commit is contained in:
parent
1e861f7285
commit
f91fb27150
@ -6,43 +6,49 @@ import os
|
|||||||
from bottle import template
|
from bottle import template
|
||||||
|
|
||||||
from aore.aoutils.aoxmltableentry import AoXmlTableEntry
|
from aore.aoutils.aoxmltableentry import AoXmlTableEntry
|
||||||
|
from aore.config import db as dbconfig, sphinx_index_addjobj, sphinx_var_dir, trashfolder, sphinx_index_sugg
|
||||||
from aore.dbutils.dbhandler import DbHandler
|
from aore.dbutils.dbhandler import DbHandler
|
||||||
from trigram import trigram
|
from trigram import trigram
|
||||||
|
|
||||||
from aore.config import db as dbconfig, sphinx_index_addjobj, sphinx_var_dir, trashfolder, sphinx_index_sugg
|
|
||||||
|
|
||||||
|
|
||||||
class SphinxHelper:
|
class SphinxHelper:
|
||||||
def __init__(self, ):
|
def __init__(self, ):
|
||||||
self.index_binary = None
|
self.index_binary = None
|
||||||
self.files = dict()
|
self.files = dict()
|
||||||
|
|
||||||
def configure_indexer(self, indexer_binary):
|
def configure_indexer(self, indexer_binary, config_filename):
|
||||||
logging.info("Start configuring Sphinx...")
|
logging.info("Start configuring Sphinx...")
|
||||||
self.index_binary = indexer_binary
|
self.index_binary = indexer_binary
|
||||||
|
|
||||||
# Create ADDROBJ config
|
# Create ADDROBJ config
|
||||||
self.files['addrobj.conf'] = self.__create_ao_index_config()
|
self.files['addrobj.conf'] = self.__create_ao_index_config()
|
||||||
|
|
||||||
# Indexing ADDROBJ config
|
|
||||||
run_index_cmd = "{} -c {} --all".format(self.index_binary, self.files['addrobj.conf'])
|
|
||||||
logging.info("Indexing main ({})...".format(sphinx_index_addjobj))
|
|
||||||
#os.system(run_index_cmd)
|
|
||||||
logging.info("{} index was created.".format(sphinx_index_addjobj))
|
|
||||||
|
|
||||||
# Produce dict file
|
# Produce dict file
|
||||||
self.files['dict.txt'] = self.__create_suggestion_dict()
|
self.files['dict.txt'] = self.__create_suggestion_dict()
|
||||||
|
|
||||||
# Put dict into db
|
# Put dict into db
|
||||||
#self.files['dict.csv'] = self.__dbexport_sugg_dict()
|
self.files['dict.csv'] = self.__dbexport_sugg_dict()
|
||||||
|
|
||||||
# Create SUGGEST config
|
# Create SUGGEST config
|
||||||
self.files['suggest.conf'] = self.__create_sugg_index_config()
|
self.files['suggest.conf'] = self.__create_sugg_index_config()
|
||||||
run_index_cmd = "{} -c {} --all".format(self.index_binary, self.files['suggest.conf'])
|
|
||||||
logging.info("Indexing main ({})...".format(sphinx_index_sugg))
|
|
||||||
os.system(run_index_cmd)
|
|
||||||
logging.info("{} index was created.".format(sphinx_index_sugg))
|
|
||||||
|
|
||||||
|
# Create main config (sphinx.conf)
|
||||||
|
out_fname = self.__create_main_config(config_filename)
|
||||||
|
|
||||||
|
# Indexing both configs
|
||||||
|
run_index_cmd = "{} -c {} --all".format(self.index_binary, out_fname)
|
||||||
|
logging.info("Indexing main ({})...".format(out_fname))
|
||||||
|
os.system(run_index_cmd)
|
||||||
|
logging.info("All indexes were created.".format(out_fname))
|
||||||
|
|
||||||
|
# remove temp files
|
||||||
|
for fname, fpath in self.files.iteritems():
|
||||||
|
try:
|
||||||
|
os.remove(fpath)
|
||||||
|
except:
|
||||||
|
logging.warning("Cannot delete {}. Not accessible.".format(fpath))
|
||||||
|
logging.info("Temporary files removed.")
|
||||||
|
logging.info("Successfully configured. Please restart searchd.")
|
||||||
|
|
||||||
def __create_sugg_index_config(self):
|
def __create_sugg_index_config(self):
|
||||||
fname = os.path.abspath(trashfolder + "suggest.conf")
|
fname = os.path.abspath(trashfolder + "suggest.conf")
|
||||||
@ -115,11 +121,27 @@ class SphinxHelper:
|
|||||||
run_builddict_cmd = "{} {} -c {} --buildstops {} 200000 --buildfreqs".format(self.index_binary,
|
run_builddict_cmd = "{} {} -c {} --buildstops {} 200000 --buildfreqs".format(self.index_binary,
|
||||||
sphinx_index_addjobj,
|
sphinx_index_addjobj,
|
||||||
self.files['addrobj.conf'], fname)
|
self.files['addrobj.conf'], fname)
|
||||||
#os.system(run_builddict_cmd)
|
os.system(run_builddict_cmd)
|
||||||
logging.info("Done.")
|
logging.info("Done.")
|
||||||
|
|
||||||
return fname
|
return fname
|
||||||
|
|
||||||
|
def __create_main_config(self, config_fname):
|
||||||
|
out_filename = os.path.abspath(config_fname)
|
||||||
|
logging.info("Creating main config {}...".format(out_filename))
|
||||||
|
|
||||||
# TRASH
|
conf_data = template('aore/templates/sphinx/sphinx.conf', sphinx_var_path=sphinx_var_dir)
|
||||||
# conf_data = template('aore/templates/sphinx/sphinx.conf', sphinx_var_path=sphinx_var_dir)
|
|
||||||
|
f = open(out_filename, "w")
|
||||||
|
for fname, fpath in self.files.iteritems():
|
||||||
|
if ".conf" in fname:
|
||||||
|
with open(fpath, "r") as conff:
|
||||||
|
for line in conff:
|
||||||
|
f.write(line)
|
||||||
|
f.write('\n')
|
||||||
|
f.write(conf_data)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
logging.info("Done.")
|
||||||
|
|
||||||
|
return out_filename
|
||||||
|
12
manage.py
12
manage.py
@ -30,6 +30,8 @@ def main():
|
|||||||
help="Configure sphinx. Creates sphinx.conf in working direcory")
|
help="Configure sphinx. Creates sphinx.conf in working direcory")
|
||||||
p.add_option('--indexer-path', '-i',
|
p.add_option('--indexer-path', '-i',
|
||||||
help="Path to sphinx indexer binary. Must be specified for '--sphinx-configure'")
|
help="Path to sphinx indexer binary. Must be specified for '--sphinx-configure'")
|
||||||
|
p.add_option('--output-conf', '-o',
|
||||||
|
help="Output config filename. Must be specified for '--sphinx-configure'")
|
||||||
|
|
||||||
options, arguments = p.parse_args()
|
options, arguments = p.parse_args()
|
||||||
|
|
||||||
@ -41,11 +43,11 @@ def main():
|
|||||||
if options.database == "update":
|
if options.database == "update":
|
||||||
update_base(options.source, int(options.update_count))
|
update_base(options.source, int(options.update_count))
|
||||||
|
|
||||||
if options.sphinx and options.indexer_path:
|
if options.sphinx and options.indexer_path and options.output_conf:
|
||||||
sphinxh = SphinxHelper()
|
sphinxh = SphinxHelper()
|
||||||
sphinxh.configure_indexer(options.indexer_path)
|
sphinxh.configure_indexer(options.indexer_path, options.output_conf)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
sph = SphinxSearch()
|
#sph = SphinxSearch()
|
||||||
sph.get_suggest('апасьево')
|
#sph.get_suggest('апасьево')
|
||||||
#main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user