On 6/7/2016 2:59 PM, sz wrote: > Hi all, Recently I run into issue indexing and searching path value. > For example, I have field with solr type "string". I tried to store a > file path with value '\\root\path1\path2'. After successfully > indexing, I checked via Solr Admin UI and see the value is > '\\\\root\\path1\\path2'. Apparently Solr/Lucense added the escape > character '\' automatically to '\' in original value. And to search > this value, I have to manually added '\' to my search term. I am > wondering why Solr add it automatically during indexing and I have to > add it manual during query. My issues with it is that even I added the > escape '\' manually, it wont' work in join query (search in > subdocuments).
The backslash character is the escape character in the syntax of a lot of languages and data formats. When you get JSON results, if there is a literal backslash, it shows up as two backslashes -- one to say "the next character is escaped" and then the escaped character. When the data returned by a query (which is stored internally with only one backslash) is run through standard JSON encoding, the backslashes are escaped. If you were to ask for XML results, I think you'd find that there's only one backslash, because XML works very differently than JSON. Solr queries are the same way. Characters that should be treated literally are preceded by a backslash, so if you want an actual backslash in your query, you have to put two of them, or run your query through a function that will escape special characters, which is going to add a backslash to each special character -- including existing backslashes. Thanks, Shawn