datadavev / DwC_views

Implements viewers for Darwin Core record repositories
1 stars 0 forks source link

Escape terms in SOLR filters #39

Closed datadavev closed 13 years ago

datadavev commented 13 years ago

When programmatically generating filters being sent to SOLR, it is necessary to ensure that any values in the filter expression are properly escaped.

Filter expressions entered by the user should be assumed to be properly escaped.

A script that does this in python (from solrclient.py):


  def escapeQueryTerm(self, term):
    '''
    + - && || ! ( ) { } [ ] ^ " ~ * ? : \
    '''
    reserved = ['+','-','&','|','!','(',')','{','}','[',']','^','"','~','*','?',':',]
    term = term.replace(u'\\',u'\\\\')
    for c in reserved:
      term = term.replace(c,u"\%s" % c)
    return term
coreyo commented 13 years ago

solrEscapeValue() has been created, takes a string and returns the string with the solrEscapeCharacter inserted in front of each special character, as listed in solrSpecialCharacters. Various functions are now using this function.