views:

705

answers:

2

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 ":"

+1  A: 

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).

zgoda
+4  A: 

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.

MrTopf