예제 #1
0
 def tearDown(self):
     solr = get_solr_connection()
     solr.delete(q="*:*", commit=True)
     set_registry_record("qf", u"", interface=IRerSolrpushSettings)
     set_registry_record("bq", u"", interface=IRerSolrpushSettings)
     set_registry_record("bf", u"", interface=IRerSolrpushSettings)
     commit()
예제 #2
0
def remove_from_solr(uid):
    """
    Perform remove item from solr
    """
    if not is_solr_active():
        return
    solr = get_solr_connection()
    portal = api.portal.get()
    if not solr:
        logger.error("Unable to push to solr. Configuration is incomplete.")
        return
    try:
        solr.delete(
            q="UID:{}".format(uid),
            commit=should_force_commit(),
        )
    except (pysolr.SolrError, TypeError) as err:
        logger.error(err)
        message = _(
            "content_remove_error",
            default=u"There was a problem removing this content from SOLR. "
            " Please contact site administrator.",
        )
        api.portal.show_message(
            message=message, request=portal.REQUEST, type="error"
        )
예제 #3
0
def reset_solr():
    solr = get_solr_connection()
    if not solr:
        logger.error("Unable to push to solr. Configuration is incomplete.")
        return
    solr.delete(
        q='site_name:"{}"'.format(get_site_title()),
        commit=should_force_commit(),
    )
예제 #4
0
def search(
    query,
    fl=None,
    facets=False,
    facet_fields=["Subject", "portal_type"],
    **kwargs
):
    """[summary] TODO

    Args:
        query ([type]): [description] TODO
        fl (str, optional): [description]. Defaults to "".
        facets (bool, optional): [description]. Defaults to False.
        facet_fields (list, optional): [description].
        Defaults to ["Subject", "portal_type"].

    Returns:
        [type]: [description]
    """
    solr = get_solr_connection()
    if not solr:
        msg = u"Unable to search using solr. Configuration is incomplete."
        logger.error(msg)
        return {
            "error": True,
            "message": translate(
                _("solr_configuration_error_label", default=msg),
                context=api.portal.get().REQUEST,
            ),
        }
    solr_query = generate_query(
        query,
        fl=fl,
        facets=facets,
        facet_fields=facet_fields,
    )
    try:
        _set_query_debug(solr=solr, params=solr_query)
        res = solr.search(**solr_query)
        return res
    except Exception as e:
        logger.exception(e)
        return {
            "error": True,
            "message": translate(
                _(
                    "search_error_label",
                    default=u"Unable to perform a search with SOLR."
                    u" Please contact the site administrator or wait some"
                    u" minutes.",
                ),
                context=api.portal.get().REQUEST,
            ),
        }
예제 #5
0
def push_to_solr(item_or_obj):
    """
    Perform push to solr
    """
    solr = get_solr_connection()
    if not solr:
        logger.error("Unable to push to solr. Configuration is incomplete.")
        return
    if not isinstance(item_or_obj, dict):
        if can_index(item_or_obj):
            item_or_obj = create_index_dict(item_or_obj)
        else:
            item_or_obj = None
    if not item_or_obj:
        return False
    attachment = item_or_obj.pop("attachment", None)
    if attachment:
        add_with_attachment(
            solr=solr, attachment=attachment, fields=item_or_obj
        )
    else:
        solr.add(docs=[item_or_obj], commit=should_force_commit())
    return True
예제 #6
0
 def tearDown(self):
     solr = get_solr_connection()
     solr.delete(q="*:*", commit=True)
     commit()