Sunday, April 3, 2011

Solr search with escaping solr reserved keywords

How do i query fields that contain solr reserved keywords as ":" in solr?

For instance,

q = 'uri:http://www.example.com'

throws up an error for "http://www.example.com" containing reserved word ":"

From stackoverflow
  • Escape/replace Lucene reserved characters during indexing and store original value in separate field (stored="true" indexed="false" in schema). If you replace reserved characters with space, you'll get http www.example.com in indexed field and http://www.example.com in stored. Depending on the type of indexed field, you'd be able to query for exact value (if it is plain string) or for tokens (if it has analyzer).

  • I just tested this and it seem that simply escaping ":" like "\:" does the trick:

    q = 'uri:http\://www.example.com'
    

    For my the index of my own site I tend to simply store the path of the URL though as I know the domain myself so that wasn't an issue for me before. But if you index external URLs then of course you need the full URL.

0 comments:

Post a Comment