コード例 #1
0
ファイル: search.py プロジェクト: abhinavthomas/allura
def search_artifact(atype, q, history=False, rows=10, short_timeout=False, filter=None, **kw):
    """Performs SOLR search.

    Raises SearchError if SOLR returns an error.
    """
    # first, grab an artifact and get the fields that it indexes
    a = atype.query.find().first()
    if a is None:
        return  # if there are no instance of atype, we won't find anything
    fields = a.index()
    # Now, we'll translate all the fld:
    q = atype.translate_query(q, fields)
    fq = [
        'type_s:%s' % fields['type_s'],
        'project_id_s:%s' % c.project._id,
        'mount_point_s:%s' % c.app.config.options.mount_point ]
    for name, values in (filter or {}).iteritems():
        field_name = name + '_s'
        parts = []
        for v in values:
            # Specific solr syntax for empty fields
            if v == '' or v is None:
                part = '(-%s:[* TO *] AND *:*)' % (field_name,)
            else:
                part = '%s:%s' % (field_name, escape_solr_arg(v))
            parts.append(part)
        fq.append(' OR '.join(parts))
    if not history:
        fq.append('is_history_b:False')
    return search(q, fq=fq, rows=rows, short_timeout=short_timeout, ignore_errors=False, **kw)
コード例 #2
0
ファイル: search.py プロジェクト: heiths/allura
def search_artifact(atype, q, history=False, rows=10, short_timeout=False, filter=None, **kw):
    """Performs SOLR search.

    Raises SearchError if SOLR returns an error.
    """
    # first, grab an artifact and get the fields that it indexes
    a = atype.query.find().first()
    if a is None:
        return  # if there are no instance of atype, we won't find anything
    fields = a.index()
    # Now, we'll translate all the fld:
    q = atype.translate_query(q, fields)
    fq = [
        'type_s:%s' % fields['type_s'],
        'project_id_s:%s' % c.project._id,
        'mount_point_s:%s' % c.app.config.options.mount_point]
    fq += kw.pop('fq', [])
    for name, values in (filter or {}).iteritems():
        field_name = name + '_s'
        parts = []
        for v in values:
            # Specific solr syntax for empty fields
            if v == '' or v is None:
                part = '(-%s:[* TO *] AND *:*)' % (field_name,)
            else:
                part = '%s:%s' % (field_name, escape_solr_arg(v))
            parts.append(part)
        fq.append(' OR '.join(parts))
    if not history:
        fq.append('is_history_b:False')
    return search(q, fq=fq, rows=rows, short_timeout=short_timeout, ignore_errors=False, **kw)
コード例 #3
0
 def test_escape_solr_arg_with_backslash(self):
     text = 'some: weird "text" with \\ backslash'
     escaped_text = escape_solr_arg(text)
     assert_equal(escaped_text, r'some\: weird \"text\" with \\ backslash')
コード例 #4
0
 def test_escape_solr_arg(self):
     text = 'some: weird "text" with symbols'
     escaped_text = escape_solr_arg(text)
     assert_equal(escaped_text, r'some\: weird \"text\" with symbols')