Ejemplo n.º 1
0
    def test_push_to_solr(self):
        solr_results = search(query={'*': '*', 'b_size': 100000}, fl='UID')
        self.assertEqual(solr_results.hits, 0)

        # try to push an indexable and published content
        push_to_solr(self.published_doc)
        solr_results = search(query={'*': '*', 'b_size': 100000}, fl='UID')
        self.assertEqual(solr_results.hits, 1)
        self.assertEqual(solr_results.docs[0]['UID'], self.published_doc.UID())

        # try to push an indexable and private content
        push_to_solr(self.unpublished_doc)
        solr_results = search(query={'*': '*', 'b_size': 100000}, fl='UID')
        self.assertEqual(solr_results.hits, 1)
        self.assertEqual(solr_results.docs[0]['UID'], self.published_doc.UID())

        # try to push a non indexable published content
        push_to_solr(self.published_news)
        solr_results = search(query={'*': '*', 'b_size': 100000}, fl='UID')
        self.assertEqual(solr_results.hits, 1)
        self.assertEqual(solr_results.docs[0]['UID'], self.published_doc.UID())

        # try to push a non indexable private content
        push_to_solr(self.unpublished_news)
        solr_results = search(query={'*': '*', 'b_size': 100000}, fl='UID')
        self.assertEqual(solr_results.hits, 1)
        self.assertEqual(solr_results.docs[0]['UID'], self.published_doc.UID())
Ejemplo n.º 2
0
    def test_reset_solr(self):
        solr_results = search(query={'*': '*', 'b_size': 100000}, fl='UID')
        self.assertEqual(solr_results.hits, 0)

        api.content.transition(obj=self.unpublished_doc, transition='publish')
        commit()
        # try to push an indexable and published content
        push_to_solr(self.published_doc)
        push_to_solr(self.unpublished_doc)
        solr_results = search(query={'*': '*', 'b_size': 100000}, fl='UID')
        self.assertEqual(solr_results.hits, 2)
        self.assertEqual(solr_results.docs[0]['UID'], self.published_doc.UID())

        # cleanup catalog
        reset_solr()
        solr_results = search(query={'*': '*', 'b_size': 100000}, fl='UID')
        self.assertEqual(solr_results.hits, 0)
Ejemplo n.º 3
0
 def commit(self, wait=None):
     # TODO: è possibile con sol anche mandare un set di comandi (add+delete) in un
     #  unica volta, anzichè uno alla volta, valutare le due opzioni
     for action, obj, args in self.queue:
         try:
             if action == INDEX:
                 push_to_solr(obj)
             elif action == UNINDEX:
                 remove_from_solr(obj.UID())
         except SolrError as err:
             logger.exception(err)
             message = _(
                 'content_indexed_error',
                 default=u'There was a problem indexing this content. Please '
                 'contact site administrator.',
             )
             api.portal.show_message(message=message,
                                     request=obj.REQUEST,
                                     type='error')
     self.queue = []
Ejemplo n.º 4
0
    def test_update_content(self):
        push_to_solr(self.published_doc)
        solr_results = search(
            query={'*': '*', 'b_size': 100000}, fl='UID Description'
        )
        self.assertEqual(solr_results.hits, 1)
        self.assertEqual(solr_results.docs[0]['UID'], self.published_doc.UID())
        self.assertNotIn('Description', solr_results.docs[0])

        self.published_doc.description = 'foo description'
        push_to_solr(self.published_doc)
        solr_results = search(
            query={'*': '*', 'b_size': 100000}, fl='UID Description'
        )
        self.assertEqual(solr_results.hits, 1)
        self.assertEqual(solr_results.docs[0]['UID'], self.published_doc.UID())
        self.assertIn('Description', solr_results.docs[0])
        self.assertEqual(
            solr_results.docs[0]['Description'], 'foo description'
        )
Ejemplo n.º 5
0
 def reindexPloneToSolr(self):
     if not self.solr_utility:
         return
     if not is_solr_active():
         logger.warning(
             "Trying to reindexing but solr is not set as active")
         return
     elapsed = timer()
     if self.solr_utility.enabled_types:
         brains_to_reindex = api.content.find(
             portal_type=self.solr_utility.enabled_types)
     else:
         pc = api.portal.get_tool(name="portal_catalog")
         brains_to_reindex = pc()
     status = self.setupAnnotations(
         items_len=brains_to_reindex.actual_result_count,
         message="Sync items to SOLR",
     )
     logger.info("##### SOLR REINDEX START #####")
     logger.info("Reindexing {} items.".format(
         brains_to_reindex.actual_result_count))
     for i, brain in enumerate(brains_to_reindex):
         status["counter"] = status["counter"] + 1
         commit()
         obj = brain.getObject()
         try:
             push_to_solr(obj)
             logger.info("[{index}/{total}] {path} ({type})".format(
                 index=i + 1,
                 total=brains_to_reindex.actual_result_count,
                 path=brain.getPath(),
                 type=brain.portal_type,
             ))
         except SolrError:
             status["in_progress"] = False
             status["error"] = True
             status["message"] = self.solr_error_message
             return
     status["in_progress"] = False
     elapsed_time = next(elapsed)
     logger.info("SOLR Reindex completed in {}".format(elapsed_time))