Django sphinx 仅在应用程序重新启动后才起作用

发布于 2024-09-01 17:48:40 字数 2910 浏览 10 评论 0原文

我已经在我的项目中设置了 django-sphinx,它只能完美运行一段时间。后来它总是返回空结果集。令人惊讶的是,重新启动 django 应用程序可以修复它。搜索再次工作,但再次仅持续很短的时间(或查询数量非常有限)。这是我的 sphinx.conf:

source src_questions
{
    # data source
    type        = mysql
    sql_host    = xxxxxx
    sql_user    = xxxxxx #replace with your db username
    sql_pass    = xxxxxx #replace with your db password
    sql_db      = xxxxxx #replace with your db name
    # these two are optional
    sql_port    = xxxxxx
    #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
    sql_query       =       SELECT q.id AS id, q.title AS title, q.tagnames AS tags, q.html AS text, q.level AS level \
                            FROM question AS q \
                            WHERE q.deleted=0 \

    # optional - used by command-line search utility to display document information
    sql_query_info  = SELECT title, id, level FROM question WHERE id=$id

    sql_attr_uint   = level
}

index questions {
    # which document source to index
    source      = src_questions

    # this is path and index file name without extension
    # you may need to change this path or create this folder
    path            = /home/rafal/index/index_questions
    # docinfo (ie. per-document attribute values) storage strategy
    docinfo     = extern

    # morphology
    morphology  = stem_en

    # stopwords file
    #stopwords  = /var/data/sphinx/stopwords.txt

    # minimum word length
    min_word_len    = 3

    # uncomment next 2 lines to allow wildcard (*) searches
    min_infix_len = 1
    enable_star = 1

    # charset encoding type
    charset_type    = utf-8
}

# indexer settings
indexer
{
    # 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

    # port on which search daemon will listen
    port        = 3312

    # searchd run info is logged here - create or change the folder
    log     = ../log/sphinx.log

    # all the search queries are logged here
    query_log   = ../log/query.log

    # client read timeout, seconds
    read_timeout    = 5

    # maximum amount of children to fork
    max_children    = 30

    # a file which will contain searchd process ID
    pid_file    = searchd.pid

    # maximum amount of matches this daemon would ever retrieve
    # from each index and serve to client
    max_matches = 1000
} 

这是我的views.py 中的搜索部分:

content = Question.search.query(keywords)
    if level:
        content = content.filter(level=level)#level is array of integers

任何日志中都没有错误,它只是没有返回任何结果。我已将“indexer --rotate --all”设置为在 cron 中每 5 分钟运行一次,并且 searchd 始终启动并运行。 我们将非常感谢所有帮助。

I've set up django-sphinx in my project, which works perfectly only for some time. Later it always returns empty result set. Surprisingly restarting django app fixes it. And search works again but again only for short time (or very limiter number of queries). Heres my sphinx.conf:

source src_questions
{
    # data source
    type        = mysql
    sql_host    = xxxxxx
    sql_user    = xxxxxx #replace with your db username
    sql_pass    = xxxxxx #replace with your db password
    sql_db      = xxxxxx #replace with your db name
    # these two are optional
    sql_port    = xxxxxx
    #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
    sql_query       =       SELECT q.id AS id, q.title AS title, q.tagnames AS tags, q.html AS text, q.level AS level \
                            FROM question AS q \
                            WHERE q.deleted=0 \

    # optional - used by command-line search utility to display document information
    sql_query_info  = SELECT title, id, level FROM question WHERE id=$id

    sql_attr_uint   = level
}

index questions {
    # which document source to index
    source      = src_questions

    # this is path and index file name without extension
    # you may need to change this path or create this folder
    path            = /home/rafal/index/index_questions
    # docinfo (ie. per-document attribute values) storage strategy
    docinfo     = extern

    # morphology
    morphology  = stem_en

    # stopwords file
    #stopwords  = /var/data/sphinx/stopwords.txt

    # minimum word length
    min_word_len    = 3

    # uncomment next 2 lines to allow wildcard (*) searches
    min_infix_len = 1
    enable_star = 1

    # charset encoding type
    charset_type    = utf-8
}

# indexer settings
indexer
{
    # 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

    # port on which search daemon will listen
    port        = 3312

    # searchd run info is logged here - create or change the folder
    log     = ../log/sphinx.log

    # all the search queries are logged here
    query_log   = ../log/query.log

    # client read timeout, seconds
    read_timeout    = 5

    # maximum amount of children to fork
    max_children    = 30

    # a file which will contain searchd process ID
    pid_file    = searchd.pid

    # maximum amount of matches this daemon would ever retrieve
    # from each index and serve to client
    max_matches = 1000
} 

and heres my search part from views.py:

content = Question.search.query(keywords)
    if level:
        content = content.filter(level=level)#level is array of integers

There are no errors in any logs, it just isnt returning any results. I have set 'indexer --rotate --all' to be run every 5 mins in cron, and searchd is up and running all time.
All help would be most appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苦妄 2024-09-08 17:48:40

斯芬克斯是什么版本的? Django 狮身人面像?狮身人面像搜索 API? Python?

无论如何,尝试从 cron 中删除 indexer看看这个问题是否仍然存在。让我知道事情进展如何。

What's the version of sphinx? django-sphinx? sphinxsearch api? python?

Anyway, try to remove the indexer from the cron & see if this problem persists. Let me know how this goes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文