RealTimePageIndex   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
wmc 4
dl 20
loc 20
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A should_update() 2 2 1
A get_queryset() 3 3 1
A get_model() 2 2 1
A index_queryset() 3 3 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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