Ejemplo n.º 1
0
def matched_regexp(conds):
    '''Return a regexp that reflects what the SearchConditions matched.

    Used to color the result, with the params returned by guess().
    '''

    # TODO: there's some duplication between this logic and search_by()
    # TODO: support word search

    reg = conds.query_s
    if not conds.regexp:
        reg = re.escape(reg)

    if conds.extent == 'whole':
        reg = '^' + reg + '$'
    elif conds.extent == 'beginning':
        reg = '^' + reg
    elif conds.extent == 'word':
        reg = r'\b' + reg + r'\b'

    if conds.case_sensitive:
        reg = tt.get_regexp(reg, 0)
    else:
        reg = tt.get_regexp(reg, re.I)

    return reg
Ejemplo n.º 2
0
def matched_regexp(search_params):
    '''Return a regexp that reflects what the search_params matched.

    Used to color the result, with the params returned by guess_search().
    '''

    # TODO: there's some duplication between this logic and search_by()

    reg = search_params['query']
    if not search_params['regexp']:
        reg = re.escape(reg)

    if search_params['extent'] == 'whole':
        reg = '^' + reg + '$'
    elif search_params['extent'] == 'beginning':
        reg = '^' + reg
    elif search_params['extent'] == 'word':
        reg = r'\b' + reg + r'\b'

    if search_params['case_sensitive']:
        reg = tt.get_regexp(reg, 0)
    else:
        reg = tt.get_regexp(reg, re.I)

    return reg
Ejemplo n.º 3
0
def matched_regexp(conds):
    '''Return a regexp that reflects what the SearchConditions matched.

    Used to color the result, with the params returned by guess().
    '''

    # TODO: there's some duplication between this logic and search_by()
    # TODO: support word search

    reg = conds.query_s
    if not conds.regexp:
        reg = re.escape(reg)

    if conds.extent == 'whole':
        reg = '^' + reg + '$'
    elif conds.extent == 'beginning':
        reg = '^' + reg
    elif conds.extent == 'word':
        reg = r'\b' + reg + r'\b'

    if conds.case_sensitive:
        reg = tt.get_regexp(reg, 0)
    else:
        reg = tt.get_regexp(reg, re.I)

    return reg
Ejemplo n.º 4
0
def regexp_insensitive(pattern, field):
    '''SQL hook function for case-insensitive regexp matching.'''
    reg = get_regexp(pattern, re.I)
    return reg.search(field) is not None
Ejemplo n.º 5
0
def regexp_sensitive(pattern, field):
    '''SQL hook function for case-sensitive regexp matching.'''
    reg = get_regexp(pattern, 0)
    return reg.search(field) is not None
Ejemplo n.º 6
0
def match_word_insensitive(word, field):
    '''SQL hook function for whole-word, case-sensitive, non-regexp matching.'''

    reg = get_regexp(r'\b' + re.escape(word) + r'\b', re.I)
    return reg.search(field) is not None