Escaping search queries for Google's full text search service

后端 未结 1 1235
南旧
南旧 2021-02-10 03:42

This is a cross-post of https://groups.google.com/d/topic/google-appengine/97LY3Yfd_14/discussion

I\'m working with the new full text search service in gae 1.6.6 and I\'

1条回答
  •  无人及你
    2021-02-10 04:19

    As briefly explained in the documentation, the query parameter is a string that should conform our query language. Which we should document better.

    For now, I recommend you to wrap your queries (or at least some of the words/terms) in double quotes. In that way you would be able to pass all printable characters, but " and \. The following example shows the result.

    import string
    from google.appengine.api.search import Query
    Query('"%s"' % string.printable.replace('"', '').replace('\\', ''))
    

    and you could even pass non printable characters

    Query('"%s"' % ''.join(chr(i) for i in xrange(128)).replace('"','').replace('\\', ''))
    

    EDIT: Note that anything that is enclosed in double quotes is an exact match, that is "foo bar" would match against ...foo bar... but no ...bar foo..

    0 讨论(0)
提交回复
热议问题