django xapian-haystack 权限问题
我一直在尝试让 xapian 使用 django haystack 来完成我正在从事的一个项目,该项目需要一些搜索功能,但遇到了一些困难!基本上我按照说明安装了所有内容,因此:
运行 xapian-core 和 xapian 绑定的 make install 运行 pip install haystack 和 pip install xapian-haystack 并正确安装所有内容
当我使用 django cms 应用程序时,我只是复制了他们的示例以测试搜索功能并遇到此错误
InvalidIndexError at /search/
Unable to open index at /home/mike/sites/xapian_search
我尝试了几种不同的 HAYSTACK_XAPIAN_PATH 设置路径,还遇到了另一个错误,
OSError at /
(13, 'Permission denied')
文件夹 xapain_search 已被授予完全权限(chmod 777),并且 xapian_index.php 文件也具有完全权限。我不确定我在这里缺少什么,但我迫切希望尝试让它发挥作用!
我的干草堆设置看起来像
HAYSTACK_SITECONF = 'lactoseintolerant.lactose_search'
HAYSTACK_SEARCH_ENGINE = 'xapian'
HAYSTACK_XAPIAN_PATH = '/home/mike/sites/xapian_search'
HAYSTACK_SEARCH_RESULTS_PER_PAGE = 50
任何建议将不胜感激!
编辑
又嗨了 我认为这个错误与没有索引这一事实有关(是吗?)我运行了命令 update_index重建索引清除索引所有这些命令似乎没有做任何事情,没有输出错误,但索引似乎从未出现过运行命令时构建
我有一个名为lactose_search的应用程序,我的HAYSTACK_SITECONF指向该应用程序文件夹中的projectname.lactose_search,我有一个名为search_indexs.py的文件。现在我只需 c+p 来自 django cms 站点的示例,因为它是我要搜索的 cms_app 内容 该文件看起来像
from django.conf import settings
from django.utils.translation import string_concat, ugettext_lazy
from haystack import indexes, site
from cms.models.managers import PageManager
from cms.models.pagemodel import Page
def page_index_factory(lang, lang_name):
if isinstance(lang_name, basestring):
lang_name = ugettext_lazy(lang_name)
def get_absolute_url(self):
return '/%s%s' % (lang, Page.get_absolute_url(self))
class Meta:
proxy = True
app_label = 'cms'
verbose_name = string_concat(Page._meta.verbose_name, ' (', lang_name, ')')
verbose_name_plural = string_concat(Page._meta.verbose_name_plural, ' (', lang_name, ')')
attrs = {'__module__': Page.__module__,
'Meta': Meta,
'objects': PageManager(),
'get_absolute_url': get_absolute_url}
_PageProxy = type("Page%s" % lang.title() , (Page,), attrs)
_PageProxy._meta.parent_attr = 'parent'
_PageProxy._meta.left_attr = 'lft'
_PageProxy._meta.right_attr = 'rght'
_PageProxy._meta.tree_id_attr = 'tree_id'
class _PageIndex(indexes.SearchIndex):
language = lang
text = indexes.CharField(document=True, use_template=False)
pub_date = indexes.DateTimeField(model_attr='publication_date')
login_required = indexes.BooleanField(model_attr='login_required')
url = indexes.CharField(stored=True, indexed=False, model_attr='get_absolute_url')
title = indexes.CharField(stored=True, indexed=False, model_attr='get_title')
def prepare(self, obj):
self.prepared_data = super(_PageIndex, self).prepare(obj)
plugins = obj.cmsplugin_set.filter(language=lang)
text = ''
for plugin in plugins:
instance, _ = plugin.get_plugin_instance()
if hasattr(instance, 'search_fields'):
text += ''.join(getattr(instance, field) for field in instance.search_fields)
self.prepared_data['text'] = text
return self.prepared_data
def get_queryset(self):
return _PageProxy.objects.published().filter(title_set__language=lang, publisher_is_draft=False).distinct()
return _PageProxy, _PageIndex
for lang_tuple in settings.LANGUAGES:
lang, lang_name = lang_tuple
site.register(*page_index_factory(lang, lang_name))
并且可以在这里找到 http://docs .django-cms.org/en/2.1.3/extending_cms/searchdocs.html
希望这些额外的信息可以使回答这个问题变得更容易!
I have been trying to get xapian working django haystack for a project im working on that requires some search functionality but have run into a bit of a wall!! Basically i got everything installed per the instructions, so:
ran make install for xapian-core and the xapian bindings
ran pip install haystack and pip install xapian-haystack and everything installed correctly
As im using the django cms app i simply copied thier example over to give the search functionality a test and ran into this error
InvalidIndexError at /search/
Unable to open index at /home/mike/sites/xapian_search
I have tried several different paths for the HAYSTACK_XAPIAN_PATH setting and have also encountered another error
OSError at /
(13, 'Permission denied')
the folder xapain_search has been given full perms (chmod 777) and theres an xapian_index.php file with full perms too. Im not sure what im missing here but im desperate to try and get this working!!
my haystack settings look like
HAYSTACK_SITECONF = 'lactoseintolerant.lactose_search'
HAYSTACK_SEARCH_ENGINE = 'xapian'
HAYSTACK_XAPIAN_PATH = '/home/mike/sites/xapian_search'
HAYSTACK_SEARCH_RESULTS_PER_PAGE = 50
Any advice would be greatly appreciated!!
edit
Hey again
i think this error is relating to the fact that there are no indexes(is that right?) i have run the commands update_index rebuild_index clear_index all of which dont seem to do anything, there are no errors outputted but still the indexs never seem to be built when the commands are run
i have an app called lactose_search which my HAYSTACK_SITECONF points to like so projectname.lactose_search in this app folder i have a file called search_indexs.py. For now i have simply c+p the example from the django cms site as it is the cms_app content i want to search
this file looks like
from django.conf import settings
from django.utils.translation import string_concat, ugettext_lazy
from haystack import indexes, site
from cms.models.managers import PageManager
from cms.models.pagemodel import Page
def page_index_factory(lang, lang_name):
if isinstance(lang_name, basestring):
lang_name = ugettext_lazy(lang_name)
def get_absolute_url(self):
return '/%s%s' % (lang, Page.get_absolute_url(self))
class Meta:
proxy = True
app_label = 'cms'
verbose_name = string_concat(Page._meta.verbose_name, ' (', lang_name, ')')
verbose_name_plural = string_concat(Page._meta.verbose_name_plural, ' (', lang_name, ')')
attrs = {'__module__': Page.__module__,
'Meta': Meta,
'objects': PageManager(),
'get_absolute_url': get_absolute_url}
_PageProxy = type("Page%s" % lang.title() , (Page,), attrs)
_PageProxy._meta.parent_attr = 'parent'
_PageProxy._meta.left_attr = 'lft'
_PageProxy._meta.right_attr = 'rght'
_PageProxy._meta.tree_id_attr = 'tree_id'
class _PageIndex(indexes.SearchIndex):
language = lang
text = indexes.CharField(document=True, use_template=False)
pub_date = indexes.DateTimeField(model_attr='publication_date')
login_required = indexes.BooleanField(model_attr='login_required')
url = indexes.CharField(stored=True, indexed=False, model_attr='get_absolute_url')
title = indexes.CharField(stored=True, indexed=False, model_attr='get_title')
def prepare(self, obj):
self.prepared_data = super(_PageIndex, self).prepare(obj)
plugins = obj.cmsplugin_set.filter(language=lang)
text = ''
for plugin in plugins:
instance, _ = plugin.get_plugin_instance()
if hasattr(instance, 'search_fields'):
text += ''.join(getattr(instance, field) for field in instance.search_fields)
self.prepared_data['text'] = text
return self.prepared_data
def get_queryset(self):
return _PageProxy.objects.published().filter(title_set__language=lang, publisher_is_draft=False).distinct()
return _PageProxy, _PageIndex
for lang_tuple in settings.LANGUAGES:
lang, lang_name = lang_tuple
site.register(*page_index_factory(lang, lang_name))
and can be found here http://docs.django-cms.org/en/2.1.3/extending_cms/searchdocs.html
Hope this extra info may make answering this question abit easier!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您更有可能没有使用以下命令构建索引,
同样的事情也发生在我身上,只需要运行上面的命令。
it's more likely that you have not built the index using following command
same thing happens to me, just needed to run above command.
这是一个相当奇怪的问题,我还没有遇到过(而且还没有人在这里报告过:https ://github.com/notanumber/xapian-haystack/issues)
旧版本的 Xapian-Haystack 需要写入权限(以便能够创建索引),并且在启动时进行了检查以验证情况确实如此,但是这已被删除。
只要进程可以读取
HAYSTACK_XAPIAN_PATH
文件夹,您就不会收到任何Permission Denied
错误。您能确认您使用的后端版本是什么吗?如果可能的话,我还建议尝试用 Whoosh 替换后端,作为健全性检查,确保没有发生任何做作的事情。
This is a rather strange issue that I haven't yet encountered (and no one has yet reported here: https://github.com/notanumber/xapian-haystack/issues)
Older versions of the Xapian-Haystack required write permission (to be able create indexes) and had a check at startup that verified this was the case, but this was removed.
As long as the process can read the
HAYSTACK_XAPIAN_PATH
folder you shouldn't be receiving anyPermission Denied
errors.Can you confirm what version of the backend you are using? If possible, I'd also suggest trying to swap out the backend with Whoosh just as a sanity check that there's not something hokey going on.
我弄清楚我的问题在这里,当我将软件包安装到我的环境中时,我运行 sudo pip install 而不是简单地使用 pip。我无法解释为什么这会影响 haystack 安装,但是一旦我删除了所有软件包并重新安装它们,我就设法让 haystack 运行
I figured out what my issue was here, when i installed the packages to my env i ran sudo pip install instead of simply using pip. I cant explain why this affected the haystack install but once i removed all the packages and re-installed them i managed to get haystack running