Mike Waites
Mike Waites

Reputation: 1728

django xapian-haystack permission problem

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!

Upvotes: 0

Views: 1118

Answers (3)

Vaibhav Mishra
Vaibhav Mishra

Reputation: 12102

it's more likely that you have not built the index using following command

python manage.py update_index

same thing happens to me, just needed to run above command.

Upvotes: 2

Mike Waites
Mike Waites

Reputation: 1728

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

Upvotes: 0

notanumber
notanumber

Reputation: 6549

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 any Permission 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.

Upvotes: 1

Related Questions