def test_querybuilderresults_search_on_multiple_sites_if_set(self): for i in range(10): push_to_solr({ "title": "Document {} from another site".format(i), "UID": "foo{}".format(i), "id": "doc-another-site-{}".format(i), "portal_type": "Document", "site_name": "Another site", "url": "http://www.plone.com/doc-{}".format(i), }) query = [ { "i": "portal_type", "o": "plone.app.querystring.operation.selection.any", "v": ["Event", "Document"], }, { "i": "searchWithSolr", "o": "plone.app.querystring.operation.boolean.isTrue", "v": "", }, { "i": "solr_sites", "o": "plone.app.querystring.operation.selection.any", "v": ["Another site", "Plone site"], }, ] results = self.get_results(query=query) self.assertEqual(results.sequence_length, 30)
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())
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)
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.assertEqual(solr_results.docs[0].get("Description", ""), "") self.published_doc.setDescription("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")
def commit(self, wait=None): if self.active and self.queue: # TODO: è possibile con sol anche mandare un set di comandi (add+delete) in un # unica volta, anzichè uno alla volta, valutare le due opzioni # Sort so unindex operations come first # for iop, obj in sorted(res.values(), key=itemgetter(0)): for uid, iop, data, args in self.queue: try: if iop in (INDEX, REINDEX): push_to_solr(data) elif iop == UNINDEX: remove_from_solr(uid) except SolrError: logger.exception("error indexing %s %s", iop, uid) message = _( "content_indexed_error", default=u"There was a problem indexing or unindexing " u"this content. Please take note of this address and " u"contact site administrator.", ) api.portal.show_message( message=message, request=getRequest(), type="error" ) self.queue = []
def setUp(self): """ We create objects before initializing solr settings, so solr core is always empty on setUp. """ self.portal = self.layer["portal"] self.request = self.layer["request"] setRoles(self.portal, TEST_USER_ID, ["Manager"]) init_solr_push() commit() push_to_solr({ "title": "Document from site foo", "portal_type": "Document", "site_name": "foo", "UID": "000", }) push_to_solr({ "title": "Document from site foo with subject", "portal_type": "Document", "site_name": "foo", "Subject": ["foo-subject"], "UID": "111", }) push_to_solr({ "title": "Document from site bar", "portal_type": "Document", "site_name": "bar", "UID": "222", }) push_to_solr({ "title": "News Item from site bar", "portal_type": "News Item", "site_name": "bar", "Subject": ["bar-subject"], "UID": "333", })