コード例 #1
0
 def test_time_indexing(self):
     update_index(Article.objects.all(),
                  'Article',
                  start_date=datetime.strftime(datetime.now(),
                                               '%Y-%m-%d %H:%M'))
     update_index(NoUpdatedField.objects.all(),
                  'NoUpdatedField',
                  end_date=datetime.strftime(datetime.now(), '%Y-%m-%d'))
コード例 #2
0
    def run(self, model, instance_pks, **kwargs):
        settings = Bungiesearch.BUNGIE.get('SIGNALS', {})
        buffer_size = settings.get('BUFFER_SIZE', 100)

        try:
            update_index(instance_pks, model.__name__, action='delete', bulk_size=buffer_size)
        except TransportError as e:
            if e.status_code == 404:
                return
            raise
コード例 #3
0
    def test_time_indexing(self):
        try:
            update_index(
                Article.objects.all(), "Article", start_date=datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M")
            )
        except Exception as e:
            self.fail("update_index with a start date failed for model Article: {}.".format(e))

        self.assertRaises(
            ValueError,
            update_index,
            **{
                "model_items": NoUpdatedField.objects.all(),
                "model_name": "NoUpdatedField",
                "end_date": datetime.strftime(datetime.now(), "%Y-%m-%d"),
            }
        )
コード例 #4
0
    def run(self, model, instance_pks, **kwargs):
        settings = Bungiesearch.BUNGIE.get("SIGNALS", {})
        buffer_size = settings.get("BUFFER_SIZE", 100)
        refresh = kwargs.get("refresh", self.refresh)

        try:
            update_index(instance_pks, model.__name__, action="delete", bulk_size=buffer_size, refresh=refresh)

        except BulkIndexError as e:
            for error in e.errors:
                if error["delete"] and error["delete"]["status"] == 404:
                    continue
                raise

        except TransportError as e:
            if e.status_code == 404:
                return
            raise
コード例 #5
0
    def test_bulk_delete(self):
        '''
        This tests that using the update_index function with 'delete' as the action performs a bulk delete operation on the data.
        '''
        bulk_art1 = {'title': 'Title four',
                     'description': 'Bulk delete first',
                     'link': 'http://example.com/bd1',
                     'published': pytz.UTC.localize(datetime(year=2015, month=7, day=13)),
                     'updated': pytz.UTC.localize(datetime(year=2015, month=7, day=20)),
                     'tweet_count': 20,
                     'source_hash': 159159159159,
                     'missing_data': '',
                     'positive_feedback': 50,
                     'negative_feedback': 5}
        bulk_art2 = {'title': 'Title five',
                     'description': 'Bulk delete second',
                     'link': 'http://example.com/bd2',
                     'published': pytz.UTC.localize(datetime(year=2015, month=7, day=13)),
                     'updated': pytz.UTC.localize(datetime(year=2015, month=7, day=20)),
                     'tweet_count': 20,
                     'source_hash': 159159159159,
                     'missing_data': '',
                     'positive_feedback': 50,
                     'negative_feedback': 5}

        bulk_obj1 = Article.objects.create(**bulk_art1)
        bulk_obj2 = Article.objects.create(**bulk_art2)

        find_five = Article.objects.search.query('match', title='five')
        self.assertEqual(len(find_five), 2, 'Searching for "five" in title did not return exactly two results (got {})'.format(find_five))

        model_items = [bulk_obj1.pk, bulk_obj2.pk]
        model_name = Article.__name__
        update_index(model_items, model_name, action='delete', bulk_size=2, num_docs=-1, start_date=None, end_date=None, refresh=True)

        find_four = Article.objects.search.query('match', title='four')
        self.assertEqual(len(find_four), 0, 'Searching for "four" in title did not return exactly zero results (got {})'.format(find_four))
        find_five = Article.objects.search.query('match', title='five')
        self.assertEqual(len(find_five), 0, 'Searching for "five" in title did not return exactly zero results (got {})'.format(find_five))
コード例 #6
0
    def test_bulk_delete(self):
        '''
        This tests that using the update_index function with 'delete' as the action performs a bulk delete operation on the data.
        '''
        bulk_art1 = {'title': 'Title four',
                     'description': 'Bulk delete first',
                     'link': 'http://example.com/bd1',
                     'published': pytz.UTC.localize(datetime(year=2015, month=7, day=13)),
                     'updated': pytz.UTC.localize(datetime(year=2015, month=7, day=20)),
                     'tweet_count': 20,
                     'source_hash': 159159159159,
                     'missing_data': '',
                     'positive_feedback': 50,
                     'negative_feedback': 5}
        bulk_art2 = {'title': 'Title five',
                     'description': 'Bulk delete second',
                     'link': 'http://example.com/bd2',
                     'published': pytz.UTC.localize(datetime(year=2015, month=7, day=13)),
                     'updated': pytz.UTC.localize(datetime(year=2015, month=7, day=20)),
                     'tweet_count': 20,
                     'source_hash': 159159159159,
                     'missing_data': '',
                     'positive_feedback': 50,
                     'negative_feedback': 5}

        bulk_obj1 = Article.objects.create(**bulk_art1)
        bulk_obj2 = Article.objects.create(**bulk_art2)

        find_five = Article.objects.search.query('match', title='five')
        self.assertEqual(len(find_five), 2, 'Searching for "five" in title did not return exactly two results (got {})'.format(find_five))

        model_items = [bulk_obj1.pk, bulk_obj2.pk]
        model_name = Article.__name__
        update_index(model_items, model_name, action='delete', bulk_size=2, num_docs=-1, start_date=None, end_date=None, refresh=True)

        find_four = Article.objects.search.query('match', title='four')
        self.assertEqual(len(find_four), 0, 'Searching for "four" in title did not return exactly zero results (got {})'.format(find_four))
        find_five = Article.objects.search.query('match', title='five')
        self.assertEqual(len(find_five), 0, 'Searching for "five" in title did not return exactly zero results (got {})'.format(find_five))
コード例 #7
0
    def run(self, action, instance, **kwargs):
        '''
        Trigger the actual index handler depending on the
        given action ('save', 'delete').
        '''
        model_class = type(instance)
        model_name = model_class.__name__

        if action not in ('save', 'delete'):
            raise ValueError("Unrecognized action: %s" % action)

        if action == 'save':
            indexing_query = get_model_indexing_query(model_class)
            should_index = indexing_query.filter(pk=instance.pk).exists()

            if should_index:
                update_index([instance], model_name)
            else:
                delete_index_item(instance, model_name)

        elif action == 'delete':
            delete_index_item(instance, model_name)
コード例 #8
0
    def run(self, action, instance, **kwargs):
        '''
        Trigger the actual index handler depending on the
        given action ('save', 'delete').
        '''
        model_class = type(instance)
        model_name = model_class.__name__

        if action not in ('save', 'delete'):
            raise ValueError("Unrecognized action: %s" % action)

        if action == 'save':
            indexing_query = get_model_indexing_query(model_class)
            should_index = indexing_query.filter(pk=instance.pk).exists()

            if should_index:
                update_index([instance], model_name)
            else:
                delete_index_item(instance, model_name)

        elif action == 'delete':
            delete_index_item(instance, model_name)
コード例 #9
0
    def run(self, action, instance, **kwargs):
        """
        Trigger the actual index handler depending on the
        given action ('save', 'delete').
        """
        model_class = type(instance)
        model_name = model_class.__name__

        if action not in ("save", "delete"):
            raise ValueError("Unrecognized action: %s" % action)

        refresh = kwargs.get("refresh", self.refresh)

        if action == "save":
            indexing_query = get_model_indexing_query(model_class)
            should_index = indexing_query.filter(pk=instance.pk).exists()

            if should_index:
                update_index([instance], model_name, refresh=refresh)
            else:
                delete_index_item(instance, model_name)

        elif action == "delete":
            delete_index_item(instance, model_name, refresh=refresh)
コード例 #10
0
 def test_time_indexing(self):
     update_index(Article.objects.all(), 'Article', start_date=datetime.strftime(datetime.now(), '%Y-%m-%d %H:%M'))
     update_index(NoUpdatedField.objects.all(), 'NoUpdatedField', end_date=datetime.strftime(datetime.now(), '%Y-%m-%d'))
コード例 #11
0
 def run(self, model, instances, **kwargs):
     settings = Bungiesearch.BUNGIE.get('SIGNALS', {})
     buffer_size = settings.get('BUFFER_SIZE', 100)
     update_index(instances, model.__name__, action='delete', bulk_size=buffer_size)
コード例 #12
0
    def test_bulk_delete(self):
        """
        This tests that using the update_index function with 'delete' as the action performs a bulk delete operation on the data.
        """
        bulk_art1 = {
            "title": "Title four",
            "description": "Bulk delete first",
            "link": "http://example.com/bd1",
            "published": pytz.UTC.localize(datetime(year=2015, month=7, day=13)),
            "updated": pytz.UTC.localize(datetime(year=2015, month=7, day=20)),
            "tweet_count": 20,
            "source_hash": 159159159159,
            "missing_data": "",
            "positive_feedback": 50,
            "negative_feedback": 5,
        }
        bulk_art2 = {
            "title": "Title five",
            "description": "Bulk delete second",
            "link": "http://example.com/bd2",
            "published": pytz.UTC.localize(datetime(year=2015, month=7, day=13)),
            "updated": pytz.UTC.localize(datetime(year=2015, month=7, day=20)),
            "tweet_count": 20,
            "source_hash": 159159159159,
            "missing_data": "",
            "positive_feedback": 50,
            "negative_feedback": 5,
        }

        bulk_obj1 = Article.objects.create(**bulk_art1)
        bulk_obj2 = Article.objects.create(**bulk_art2)

        find_five = Article.objects.search.query("match", title="five")
        self.assertEqual(
            len(find_five),
            2,
            'Searching for "five" in title did not return exactly two results (got {})'.format(find_five),
        )

        model_items = [bulk_obj1, bulk_obj2]
        model_name = Article.__name__
        update_index(
            model_items,
            model_name,
            action="delete",
            bulk_size=2,
            num_docs=-1,
            start_date=None,
            end_date=None,
            refresh=True,
        )

        find_four = Article.objects.search.query("match", title="four")
        self.assertEqual(
            len(find_four),
            0,
            'Searching for "four" in title did not return exactly zero results (got {})'.format(find_four),
        )
        find_five = Article.objects.search.query("match", title="five")
        self.assertEqual(
            len(find_five),
            0,
            'Searching for "five" in title did not return exactly zero results (got {})'.format(find_five),
        )