diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-07-17 00:04:16 -0400 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2011-07-17 00:04:16 -0400 |
commit | b5e3e403a37aecc4f4c6ffb8c42e76e78ca1bee6 (patch) | |
tree | 401f03c2d93f5464b5f2b6bce2bf4774db6433ff | |
parent | 57a3961d4915f1a2b73b4f31dd993f5dd8070884 (diff) | |
download | askbot-b5e3e403a37aecc4f4c6ffb8c42e76e78ca1bee6.tar.gz askbot-b5e3e403a37aecc4f4c6ffb8c42e76e78ca1bee6.tar.bz2 askbot-b5e3e403a37aecc4f4c6ffb8c42e76e78ca1bee6.zip |
started working on reviving sphinx search
-rw-r--r-- | askbot/__init__.py | 11 | ||||
-rw-r--r-- | askbot/management/commands/get_askbot_sphinx_search_config.py | 18 | ||||
-rw-r--r-- | askbot/models/question.py | 6 | ||||
-rw-r--r-- | askbot/search/sphinx/sphinx.conf | 114 |
4 files changed, 92 insertions, 57 deletions
diff --git a/askbot/__init__.py b/askbot/__init__.py index a88b27ab..23d4c92d 100644 --- a/askbot/__init__.py +++ b/askbot/__init__.py @@ -28,6 +28,17 @@ def get_install_directory(): """ return os.path.dirname(__file__) +def get_path_to(relative_path): + """returns absolute path to a file + relative to ``askbot`` directory + ``relative_path`` must use only forward slashes + and must not start with a slash + """ + root_dir = get_install_directory() + assert(relative_path[0] != 0) + path_bits = relative_path.split('/') + return os.path.join(root_dir, *path_bits) + def get_version(): """returns version of the askbot app diff --git a/askbot/management/commands/get_askbot_sphinx_search_config.py b/askbot/management/commands/get_askbot_sphinx_search_config.py new file mode 100644 index 00000000..5c7fb5b0 --- /dev/null +++ b/askbot/management/commands/get_askbot_sphinx_search_config.py @@ -0,0 +1,18 @@ +"""the management command that outputs configuration +for sphinx search""" +from django.conf import settings +from django.core.management.base import BaseCommand +from django.template import Template, Context +import askbot + +class Command(BaseCommand): + + def handle(self, *args, **noargs): + tpl_file = open(askbot.get_path_to('search/sphinx/sphinx.conf')) + tpl = Template(tpl_file.read()) + context = Context({ + 'db_name': settings.DATABASE_NAME, + 'db_user': settings.DATABASE_USER, + 'db_password': settings.DATABASE_PASSWORD + }) + print tpl.render(context) diff --git a/askbot/models/question.py b/askbot/models/question.py index 1171cda2..a6a141fd 100644 --- a/askbot/models/question.py +++ b/askbot/models/question.py @@ -129,6 +129,8 @@ class QuestionQuerySet(models.query.QuerySet): """returns a query set of questions, matching the full text query """ + if getattr(settings, 'USE_SPHINX_SEARCH', False): + return Question.sphinx_search(search_query) if settings.DATABASE_ENGINE == 'mysql' and mysql.supports_full_text_search(): return self.filter( models.Q(title__search = search_query) \ @@ -431,6 +433,10 @@ class Question(content.Content, DeletableContent): objects = QuestionManager() + if getattr(settings, 'USE_SPHINX_SEARCH', False): + from djangosphinx.models import SphinxSearch + sphinx_search = SphinxSearch(settings.ASKBOT_SPHINX_SEARCH_INDEX) + class Meta(content.Content.Meta): db_table = u'question' diff --git a/askbot/search/sphinx/sphinx.conf b/askbot/search/sphinx/sphinx.conf index bf4bdc8b..d66acd2b 100644 --- a/askbot/search/sphinx/sphinx.conf +++ b/askbot/search/sphinx/sphinx.conf @@ -2,22 +2,22 @@ #periodically merge the diff index to the main #this is not important until you get to hundreds of thousands posts -source src_cnprog +source src_askbot { - # data source - type = mysql - sql_host = localhost - sql_user = cnprog #replace with your db username - sql_pass = secret #replace with your db password - sql_db = cnprog #replace with your db name - # these two are optional - #sql_port = 3306 - #sql_sock = /var/lib/mysql/mysql.sock - - # pre-query, executed before the main fetch query - sql_query_pre = SET NAMES utf8 - - # main document fetch query - change the table names if you are using a prefix + # data source + type = mysql + sql_host = localhost + sql_user = {{ db_username }} #replace with your db username + sql_pass = {{ db_password }} #replace with your db password + sql_db = {{ db_name }} #replace with your db name + # these two are optional + #sql_port = 3306 + #sql_sock = /var/lib/mysql/mysql.sock + + # pre-query, executed before the main fetch query + sql_query_pre = SET NAMES utf8 + + # main document fetch query - change the table names if you are using a prefix # this query creates a flat document from each question that includes only latest # revisions of the question and all of it's answers sql_query = SELECT q.id as id, q.title AS title, q.tagnames as tags, qr.text AS text, answers_combined.text AS answers \ @@ -56,72 +56,72 @@ source src_cnprog AS answers_combined ON q.id=answers_combined.question_id \ WHERE q.deleted=0; - # optional - used by command-line search utility to display document information - sql_query_info = SELECT title, id FROM question WHERE id=$id + # optional - used by command-line search utility to display document information + sql_query_info = SELECT title, id FROM question WHERE id=$id } -index cnprog { - # which document source to index - source = src_cnprog +index askbot { + # which document source to index + source = src_askbot - # this is path and index file name without extension - # you may need to change this path or create this folder - path = /var/data/sphinx/cnprog_main + # this is path and index file name without extension + # you may need to change this path or create this folder + path = /var/data/sphinx/askbot_main - # docinfo (ie. per-document attribute values) storage strategy - docinfo = extern + # docinfo (ie. per-document attribute values) storage strategy + docinfo = extern - # morphology - morphology = stem_en + # morphology + morphology = stem_en - # stopwords file - #stopwords = /var/data/sphinx/stopwords.txt + # stopwords file + #stopwords = /var/data/sphinx/stopwords.txt - # minimum word length - min_word_len = 1 + # minimum word length + min_word_len = 1 - # uncomment next 2 lines to allow wildcard (*) searches - #min_infix_len = 1 - #enable_star = 1 + # uncomment next 2 lines to allow wildcard (*) searches + #min_infix_len = 1 + #enable_star = 1 - # charset encoding type - charset_type = utf-8 + # charset encoding type + charset_type = utf-8 } # indexer settings indexer { - # memory limit (default is 32M) - mem_limit = 64M + # memory limit (default is 32M) + mem_limit = 64M } # searchd settings searchd { - # IP address on which search daemon will bind and accept - # optional, default is to listen on all addresses, - # ie. address = 0.0.0.0 - address = 127.0.0.1 + # IP address on which search daemon will bind and accept + # optional, default is to listen on all addresses, + # ie. address = 0.0.0.0 + address = 127.0.0.1 - # port on which search daemon will listen - port = 3312 + # port on which search daemon will listen + port = 3312 - # searchd run info is logged here - create or change the folder - log = /var/log/sphinx/searchd.log + # searchd run info is logged here - create or change the folder + log = /var/log/sphinx/searchd.log - # all the search queries are logged here - query_log = /var/log/sphinx/query.log + # all the search queries are logged here + query_log = /var/log/sphinx/query.log - # client read timeout, seconds - read_timeout = 5 + # client read timeout, seconds + read_timeout = 5 - # maximum amount of children to fork - max_children = 30 + # maximum amount of children to fork + max_children = 30 - # a file which will contain searchd process ID - pid_file = /var/log/sphinx/searchd.pid + # a file which will contain searchd process ID + pid_file = /var/log/sphinx/searchd.pid - # maximum amount of matches this daemon would ever retrieve - # from each index and serve to client - max_matches = 1000 + # maximum amount of matches this daemon would ever retrieve + # from each index and serve to client + max_matches = 1000 } |