Ejemplo n.º 1
0
def Match(columns, expr, modifier=None):
    if isinstance(columns, (list, tuple)):
        match = fn.MATCH(*columns)  # Tuple of one or more columns / fields.
    else:
        match = fn.MATCH(columns)  # Single column / field.
    args = expr if modifier is None else NodeList((expr, SQL(modifier)))
    return NodeList((match, fn.AGAINST(args)))
Ejemplo n.º 2
0
Archivo: text.py Proyecto: zhill/quay
def match_mysql(field, search_query):
    """ Generates a full-text match query using a Match operation, which is needed for MySQL.
  """
    if field.name.find("`") >= 0:  # Just to be safe.
        raise Exception(
            "How did field name '%s' end up containing a backtick?" %
            field.name)

    # Note: There is a known bug in MySQL (https://bugs.mysql.com/bug.php?id=78485) that causes
    # queries of the form `*` to raise a parsing error. If found, simply filter out.
    search_query = search_query.replace("*", "")

    # Just to be absolutely sure.
    search_query = search_query.replace("'", "")
    search_query = search_query.replace('"', "")
    search_query = search_query.replace("`", "")

    return NodeList((fn.MATCH(SQL(
        "`%s`" % field.name)), fn.AGAINST(SQL("%s", [search_query]))),
                    parens=True)