def search_model_catalog(self,
                          query,
                          start=0,
                          limit=None,
                          order_by=None,
                          reverse=False,
                          fields=None,
                          commit_dirty=False,
                          facets_for_field=None):
     """
     @returns: SearchResults
     """
     catalog_results = []
     brains = []
     count = 0
     search_params = SearchParams(query,
                                  start=start,
                                  limit=limit,
                                  order_by=order_by,
                                  reverse=reverse,
                                  fields=fields)
     if facets_for_field:
         search_params.facet_field = facets_for_field
     catalog_results = self.model_catalog_client.search(
         search_params, self.context, commit_dirty=commit_dirty)
     return catalog_results
 def search_model_catalog(self, query, start=0, limit=None, order_by=None, reverse=False,
                          fields=None, commit_dirty=False, facets_for_field=None):
     """
     @returns: SearchResults
     """
     catalog_results = []
     brains = []
     count = 0
     search_params = SearchParams(query, start=start, limit=limit, order_by=order_by, reverse=reverse, fields=fields)
     if facets_for_field:
         search_params.facet_field=facets_for_field
     catalog_results = self.model_catalog_client.search(search_params, self.context, commit_dirty=commit_dirty)
     return catalog_results
def reset_model_catalog():
    """
    Deletes temporary documents from previous tests.
    They should be cleaned by abort() but just in case
    """
    model_index = zope.component.createObject('ModelIndex', get_solr_config(test=True))
    model_index.unindex_search(SearchParams(query="NOT tx_state:0"))
def get_uids(index_client, root="", types=()):
    start = 0
    need_results = True
    query = [Eq("tx_state", 0)]
    if root:
        root = root.rstrip('/')
        query.append(
            Or(Eq("uid", "{}".format(root)),
               MatchGlob("uid", "{}/*".format(root))))

    if not isinstance(types, (tuple, list)):
        types = (types, )

    if types:
        query.append(In("objectImplements", [dottedname(t) for t in types]))

    while need_results:
        search_results = index_client.search(
            SearchParams(query=And(*query),
                         start=start,
                         limit=MODEL_INDEX_BATCH_SIZE,
                         order_by="uid",
                         fields=["uid"]))
        start += MODEL_INDEX_BATCH_SIZE
        for result in search_results.results:
            yield result.uid
        need_results = start < search_results.total_count
 def search_brain(self, uid, context, fields=None, commit_dirty=False):
     """ """
     tx_state = self._get_tx_state()
     if commit_dirty:
         self.do_mid_transaction_commit()
     query = Eq(OBJECT_UID_FIELD, uid)
     search_params = SearchParams(query, fields=fields)
     search_params = self._add_tx_state_query(search_params, tx_state)
     return self._do_search(search_params, context)
Example #6
0
 def _delete_temporary_tx_documents(self):
     tx_state = self._get_tx_state()
     if tx_state and tx_state.are_there_indexed_updates():
         try:
             query = {TX_STATE_FIELD:tx_state.tid}
             self.model_index.unindex_search(SearchParams(query))
         except Exception as e:
             log.fatal("Exception trying to abort current transaction. {0} / {1}".format(e, e.message))
             raise ModelCatalogError("Model Catalog error trying to abort transaction")
 def unindex_by_uid(self, uid):
     query = {UID: uid}
     search_params = SearchParams(query=query)
     self.model_index.unindex_search(
         search_params, collection=ZENOSS_MODEL_COLLECTION_NAME)