use the same regex for lucene escapes, close #143

The escapes for the value were updated recently but the escapes for the
query were forgotten.
Now we use a variable for the regex to reduce duplication.
Ah, sure - I was waiting for a reply to my question about escaping `query`
and you got in with the patch before me ;)
No worries.

As for this patch, I'm happy to have the regex inside the method. Either as
a compiled object or as is - it doesn't bother me.


On Mon, Jul 21, 2014 at 12:43 AM, Johannes Dewender <
notifications@github.com> wrote:

> In musicbrainzngs/musicbrainz.py:
>
> > @@ -677,12 +677,13 @@ def _do_mb_search(entity, query='', fields={},
> >  	for the given entity type.
> >  	"""
> >  	# Encode the query terms as a Lucene query string.
> > +	lucene_special = r'([+\-&|!(){}\[\]\^"~*?:\\\/])'
>
> Not sure why or where performance/efficiency comes in place all of a
> sudden. That regex is not really a bottleneck here or something where we
> can actually gain performance.
> We are using a regex for replacement in a 1-line string, then sending data
> over the net and then receiving an even bigger amount of data and parsing
> xml.
> See also the note about compiling regexes in the python docs
> <https://docs.python.org/2/library/re.html#module-contents>. Short:
> compiling regexes is absolutely unnecessary unless you are tackling a
> specific bottleneck. It does not make the code more readable.
>
> About the module level constant. I don't care much either way. Having it
> at the top is nice, because having constants at the top is nice in general.
> Having it in the function is nice, because this way you can see "the whole"
> thing (algo, constant) with "one look".
>
> @alastair <https://github.com/alastair>: Better push your patch to some
> branch and leave a note. I certainly wouldn't have made one myself then ;-)
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/alastair/python-musicbrainzngs/pull/144/files#r15152469>
> .
>