z22401750 2011-05-25 09:41
浏览 266
已采纳

谁能告诉我这段代码 什么意思 在什么地方用的?

[code="java"]
import re

Solr/Lucene special characters: + - ! ( ) { } [ ] ^ " ~ * ? : \

There are also operators && and ||, but we're just going to escape

the individual ampersand and pipe chars.

Also, we're not going to escape backslashes!

http://lucene.apache.org/java/2_9_1/queryparsersyntax.html#Escaping+Special+Characters

ESCAPE_CHARS_RE = re.compile(r'(?<!\)(?P[&|+-!(){}[]^"~*?:])')

def solr_escape(value):
r"""Escape un-escaped special characters and return escaped value.

>>> solr_escape(r'foo+') == r'foo\+'
True
>>> solr_escape(r'foo\+') == r'foo\+'
True
>>> solr_escape(r'foo\\+') == r'foo\\+'
True
"""
return ESCAPE_CHARS_RE.sub(r'\\\g<char>', value)

[/code]

  • 写回答

3条回答 默认 最新

  • fmjsjx 2011-05-25 09:50
    关注

    楼主居然把python代码发到Java区来了……
    这个方法意思就是返回不转义的字符串,通过正则来弄。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?