Beispiel #1
0
    def test_load_nonexistent(self):
        try:
            backend = loading.load_backend('foobar')
            self.fail()
        except ImproperlyConfigured as e:
            self.assertEqual(
                str(e),
                "The provided backend 'foobar' is not a complete Python path to a BaseEngine subclass."
            )

        try:
            backend = loading.load_backend('foobar.FooEngine')
            self.fail()
        except ImportError as e:
            pass

        try:
            backend = loading.load_backend(
                'haystack.backends.simple_backend.FooEngine')
            self.fail()
        except ImportError as e:
            self.assertEqual(
                str(e),
                "The Python module 'haystack.backends.simple_backend' has no 'FooEngine' class."
            )
Beispiel #2
0
 def test_load_solr(self):
     try:
         import pysolr
     except ImportError:
         warnings.warn("Pysolr doesn't appear to be installed. Unable to test loading the Solr backend.")
         return
     
     backend = loading.load_backend('haystack.backends.solr_backend.SolrEngine')
     self.assertEqual(backend.__name__, 'SolrEngine')
Beispiel #3
0
 def test_load_whoosh(self):
     try:
         import whoosh
     except ImportError:
         warnings.warn("Whoosh doesn't appear to be installed. Unable to test loading the Whoosh backend.")
         return
     
     backend = loading.load_backend('haystack.backends.whoosh_backend.WhooshEngine')
     self.assertEqual(backend.__name__, 'WhooshEngine')
Beispiel #4
0
 def test_load_elasticsearch(self):
     try:
         import pyelasticsearch
     except ImportError:
         warnings.warn("Pyelasticsearch doesn't appear to be installed. Unable to test loading the ElasticSearch backend.")
         return
     
     backend = loading.load_backend('haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine')
     self.assertEqual(backend.__name__, 'ElasticsearchSearchEngine')
    def test_load_nonexistent(self):
        try:
            backend = loading.load_backend('foobar')
            self.fail()
        except ImproperlyConfigured as e:
            self.assertEqual(str(e), "The provided backend 'foobar' is not a complete Python path to a BaseEngine subclass.")

        try:
            backend = loading.load_backend('foobar.FooEngine')
            self.fail()
        except ImportError as e:
            pass

        try:
            backend = loading.load_backend('haystack.backends.simple_backend.FooEngine')
            self.fail()
        except ImportError as e:
            self.assertEqual(str(e), "The Python module 'haystack.backends.simple_backend' has no 'FooEngine' class.")
Beispiel #6
0
    def __init__(self, **kwargs):
        conn_config = settings.HAYSTACK_CONNECTIONS[kwargs['using']]
        base_engine = load_backend(conn_config['BASE_ENGINE'])(**kwargs)

        backend_bases = (LanguageSearchBackend, base_engine.backend)
        backend_class = type('LanguageSearchBackend', backend_bases,
                             {'parent_class': base_engine.backend})
        self.backend = backend_class

        self.query = base_engine.query

        super(LanguageSearchEngine, self).__init__(**kwargs)
Beispiel #7
0
    def __init__(self, **kwargs):
        conn_config = settings.HAYSTACK_CONNECTIONS[kwargs['using']]
        base_engine = load_backend(conn_config['BASE_ENGINE'])(**kwargs)

        backend_bases = (LanguageSearchBackend, base_engine.backend)
        backend_class = type('LanguageSearchBackend', backend_bases,
                             {'parent_class': base_engine.backend})
        self.backend = backend_class

        self.query = base_engine.query

        super(LanguageSearchEngine, self).__init__(**kwargs)
Beispiel #8
0
    def __init__(self, model_attr=None, use_template=False, template_name=None,
                 document=False, indexed=True, stored=True, faceted=False,
                 default=NOT_PROVIDED, null=False, index_fieldname=None,
                 facet_class=None, boost=1.0, weight=None, solr_field_params=None):
        # Track what the index thinks this field is called.
        self.instance_name = None
        self.model_attr = model_attr
        self.use_template = use_template
        self.template_name = template_name
        self.document = document
        self.indexed = indexed
        self.stored = stored
        self.faceted = faceted
        self._default = default
        self.null = null
        self.index_fieldname = index_fieldname
        self.boost = weight or boost
        self.is_multivalued = False
        
        # `solr_field_params` should be a dict containing additional 
        # field arguments to be used in the Solr schema
        # e.g. {'termVectors': 'true'}.
        self.solr_field_params = solr_field_params
        if self.solr_field_params:
            from haystack.utils import loading
            from haystack.exceptions import MissingDependency
            try:
                loading.load_backend('haystack.backends.solr_backend.SolrEngine')
            except MissingDependency:
                raise NotImplementedError("""The solr_field_params attribute 
                                           requires a configured Solr search backend.""")
            
        # We supply the facet_class for making it easy to create a faceted
        # field based off of this field.
        self.facet_class = facet_class

        if self.facet_class is None:
            self.facet_class = FacetCharField

        self.set_instance_name(None)
    def _load_forwarded_engine(self):
        """Load a forwarded Haystack search engine.

        This will look up the current site configuration and determine the
        proper Review Board and Haystack search backends to load, setting any
        forwarding state.

        IF there's an issue at all with loading the search backends, an error
        will be logged and search will be disabled.

        This is thread-safe.
        """
        cur_load_gen = self._load_gen

        with self._load_lock:
            if self._load_gen == cur_load_gen:
                self.reset_forwarding()

                siteconfig = SiteConfiguration.objects.get_current()
                search_backend_id = siteconfig.get('search_backend_id')
                search_backend = search_backend_registry.get_search_backend(
                    search_backend_id)

                if search_backend is None:
                    logger.error(
                        'The search engine "%s" could not be found. '
                        'If this is provided by an extension, you '
                        'will have to make sure that extension is '
                        'enabled. Disabling search.', search_backend_id)
                    engine = None
                else:
                    try:
                        engine_cls = load_backend(
                            search_backend.haystack_backend_name)
                        engine = engine_cls(using=self.using)
                    except Exception as e:
                        logger.error(
                            'Error loading the search engine "%s": '
                            '%s', search_backend_id, e)
                        engine = None

                if engine is None:
                    # Disable search, since it's useless at this point.
                    siteconfig.set('search_enable', False)
                    siteconfig.save(update_fields=('settings', ))
                else:
                    self._forwarded_engine = engine
                    self._search_backend = None
                    self._forwarded_options = search_backend.configuration

                self._load_gen = cur_load_gen + 1
Beispiel #10
0
    def __init__(self, **kwargs):
        conn_config = settings.HAYSTACK_CONNECTIONS[kwargs["using"]]
        base_engine = load_backend(conn_config["BASE_ENGINE"])(**kwargs)

        backend_bases = (LanguageSearchBackend, base_engine.backend)
        backend_class = type(
            "LanguageSearchBackend",
            backend_bases,
            {"parent_class": base_engine.backend},
        )
        self.backend = backend_class

        self.query = base_engine.query

        super(LanguageSearchEngine, self).__init__(**kwargs)
Beispiel #11
0
class LoadBackendTestCase(TestCase):
    def test_load_solr(self):
        try:
            import pysolr
        except ImportError:
            warnings.warn("Pysolr doesn't appear to be installed. Unable to test loading the Solr backend.")
            return
        
        backend = loading.load_backend('haystack.backends.solr_backend.SolrEngine')
        self.assertEqual(backend.__name__, 'SolrEngine')
    
    def test_load_whoosh(self):
        try:
            import whoosh
        except ImportError:
            warnings.warn("Whoosh doesn't appear to be installed. Unable to test loading the Whoosh backend.")
            return
        
        backend = loading.load_backend('haystack.backends.whoosh_backend.WhooshEngine')
        self.assertEqual(backend.__name__, 'WhooshEngine')
    
    def test_load_elasticsearch(self):
        try:
            import pyelasticsearch
        except ImportError:
            warnings.warn("Pyelasticsearch doesn't appear to be installed. Unable to test loading the ElasticSearch backend.")
            return
        
        backend = loading.load_backend('haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine')
        self.assertEqual(backend.__name__, 'ElasticsearchSearchEngine')
    
    def test_load_simple(self):
        backend = loading.load_backend('haystack.backends.simple_backend.SimpleEngine')
        self.assertEqual(backend.__name__, 'SimpleEngine')
    
    def test_load_nonexistent(self):
        try:
            backend = loading.load_backend('foobar')
            self.fail()
        except ImproperlyConfigured, e:
            self.assertEqual(str(e), "The provided backend 'foobar' is not a complete Python path to a BaseEngine subclass.")
        
        try:
            backend = loading.load_backend('foobar.FooEngine')
            self.fail()
        except ImportError, e:
            pass
Beispiel #12
0
    def load_haystack_engine(self, **kwargs):
        """Load the Haystack backend engine.

        This will construct the engine with the provided parameters. A new
        instance will be constructed every time this is called.

        Args:
            **kwargs (dict):
                Keyword arguments to pass to the engine constructor.

        Returns:
            django_haystack.backends.BaseEngine:
            The resulting engine instance.
        """
        engine_cls = load_backend(self.haystack_backend_name)

        return engine_cls(**kwargs)
Beispiel #13
0
 def test_load_simple(self):
     backend = loading.load_backend("haystack.backends.simple_backend.SimpleEngine")
     self.assertEqual(backend.__name__, "SimpleEngine")
Beispiel #14
0
 def test_load_simple(self):
     backend = loading.load_backend('haystack.backends.simple_backend.SimpleEngine')
     self.assertEqual(backend.__name__, 'SimpleEngine')
Beispiel #15
0
            import pyelasticsearch
        except ImportError:
            warnings.warn("Pyelasticsearch doesn't appear to be installed. Unable to test loading the ElasticSearch backend.")
            return
        
        backend = loading.load_backend('haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine')
        self.assertEqual(backend.__name__, 'ElasticsearchSearchEngine')
    
    def test_load_simple(self):
        backend = loading.load_backend('haystack.backends.simple_backend.SimpleEngine')
        self.assertEqual(backend.__name__, 'SimpleEngine')
    
    def test_load_nonexistent(self):
        try:
            backend = loading.load_backend('foobar')
            self.fail()
        except ImproperlyConfigured, e:
            self.assertEqual(str(e), "The provided backend 'foobar' is not a complete Python path to a BaseEngine subclass.")
        
        try:
            backend = loading.load_backend('foobar.FooEngine')
            self.fail()
        except ImportError, e:
            pass
        
        try:
            backend = loading.load_backend('haystack.backends.simple_backend.FooEngine')
            self.fail()
        except ImportError, e:
            self.assertEqual(str(e), "The Python module 'haystack.backends.simple_backend' has no 'FooEngine' class.")
 def test_load_internalsearch_elasticsearch(self):
     backend = loading.load_backend(
         "djangocms_internalsearch.backends.elasticsearch2.InternalSearchESEngine"
     )
     self.assertEqual(backend.__name__, "InternalSearchESEngine")
Beispiel #17
0
 def test_load_nonexistent(self):
     try:
         backend = loading.load_backend('foobar')
         self.fail()
     except ImproperlyConfigured, e:
         self.assertEqual(str(e), "The provided backend 'foobar' is not a complete Python path to a BaseEngine subclass.")