RealTimePageIndex.get_model()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 2
Ratio 100 %

Importance

Changes 0
Metric Value
dl 2
loc 2
rs 10
c 0
b 0
f 0
cc 1
1
# -*- coding: utf-8 -*-
2
"""Django haystack `SearchIndex` module."""
3
from pages.models import Page
4
from pages import settings
5
6
from haystack.indexes import SearchIndex, CharField, DateTimeField, Indexable
7
8
# This is obsolete if you use haystack 2.0, use the HAYSTACK_SIGNAL_PROCESSOR
9
# setting instead
10
if settings.PAGE_REAL_TIME_SEARCH:
11
    
12
    from haystack.indexes import RealTimeSearchIndex
13
14 View Code Duplication
    class RealTimePageIndex(RealTimeSearchIndex, Indexable):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
15
        """Search index for pages content."""
16
        text = CharField(document=True, use_template=True)
17
        title = CharField(model_attr='title')
18
        url = CharField(model_attr='get_absolute_url')
19
        publication_date = DateTimeField(model_attr='publication_date')
20
21
        def index_queryset(self, using=None):
22
            """Haystack 2.0 requires this method now"""
23
            return self.get_model().objects.published()
24
25
        def get_queryset(self):
26
            """Used when the entire index for model is updated."""
27
            return Page.objects.published()
28
29
        def get_model(self):
30
            return Page
31
32
        def should_update(self, instance, **kwargs):
33
            return instance.status == Page.PUBLISHED
34
35
else:
36
    
37 View Code Duplication
    class PageIndex(SearchIndex, Indexable):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
38
        """Search index for pages content."""
39
        text = CharField(document=True, use_template=True)
40
        title = CharField(model_attr='title')
41
        url = CharField(model_attr='get_absolute_url')
42
        publication_date = DateTimeField(model_attr='publication_date')
43
44
        def index_queryset(self, using=None):
45
            """Used when the entire index for model is updated."""
46
            return Page.objects.published()
47
48
        def get_model(self):
49
            return Page
50
51
        def should_update(self, instance, **kwargs):
52
            return instance.status == Page.PUBLISHED
53
54