代码之家  ›  专栏  ›  技术社区  ›  James H.

Django+Haystack+Whoosh,没有生产结果

  •  0
  • James H.  · 技术社区  · 9 年前

    我正在构建一个Django应用程序,使用Haystack+Whoosh进行搜索。在开发环境中,搜索按预期工作。但是,在生产中,搜索始终不返回结果。

    发展:

    $> python manage.py rebuild_index
    ...
    All documents removed.
    Indexing 8 categories
    Indexing 4 documents
    
    $> python manage.py shell
    ...
    >>> from haystack.query import SearchQuerySet
    >>> SearchQuerySet().all().count()
    12
    

    生产:

    $> dokku run proj python manage.py rebuild_index -v2
    ...
    All documents removed.
    Skipping '<class 'django.contrib.admin.models.LogEntry'>' - no index.
    ...
    Skipping '<class 'django.contrib.sessions.models.Session'>' - no index.
    Indexing 7 categories
      indexed 1 - 7 of 7 (worker PID: 8).
    Indexing 13 documents
      indexed 1 - 13 of 13 (worker PID: 8).
    [INFO/MainProcess] process shutting down
    
    $> dokku run proj python manage.py shell
    ...
    >>> from haystack.query import SearchQuerySet
    >>> SearchQuerySet().all().count()
    0
    >>> from django.conf import settings
    >>> settings.HAYSTACK_CONNECTIONS['default']['PATH']
    '/app/whoosh/index'
    
    $> dokku run proj ls -la /app/whoosh
    total 8
    drwxr-xr-x  2 herokuishuser herokuishuser 4096 Nov 21 16:44 .
    drwxr-xr-x 21 herokuishuser herokuishuser 4096 Nov 22 17:42 ..
    -rw-r--r--  1 herokuishuser herokuishuser    0 Nov 21 16:43 .gitkeep
    

    文件/设置:

    # requirements.txt
    Django==1.10.3
    django-haystack==2.5.1
    gunicorn==19.6.0
    psycopg2==2.6.2
    whitenoise==3.2.2
    Whoosh==2.7.4
    ...
    
    # runtime.txt
    python-3.5.2
    
    # proj/settings.py
    ...
    HAYSTACK_CONNECTIONS = {
        'default': {
            'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
            'PATH': os.path.join(BASE_DIR, 'whoosh', 'index'),
        },
    }
    ...
    

    找到问题有什么指导吗?

    2 回复  |  直到 9 年前
        1
  •  0
  •   François Constant    9 年前

    这可能是权限问题。

    您可以在详细模式下运行,您可以从中获得启示:

    dokku run proj python manage.py rebuild_index -v2
    

    你的设置是什么?你应该有这样的东西:

    HAYSTACK_CONNECTIONS = {
        'default': {
            'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine',
            'PATH': os.path.join(self.BASE, '_whoosh', 'whoosh_index'),
        },
    }
    

    打印出来 settings.HAYSTACK_CONNECTIONS['default']['PATH'] 。请确保此文件不在临时文件夹中,并且可以访问( ls -la ... ).

        2
  •  0
  •   Fawaz    6 年前

    首先,确保提供了正确的权限:

    sudo chown :www-data YourDjangoProject/
    sudo chmod 775 YourDjangoProject/
    

    最后:

    sudo chown :www-data YourDjangoProject/YourDjangoProject/whoosh_index/