简体   繁体   中英

Why can't I have a colon in a Retrieve and Rank Solr query?

If I send a natural-language query to Retrieve and Rank (Solr), it will return an error if the query contains a colon. It seems to be attempting to interpret the word just prior to the colon as a field name.

Is there any way to prevent this, and are there other characters like this to which I should be aware?

The list of characters you'll need to handle is at http://www.ibm.com/watson/developercloud/doc/retrieve-rank/plugin_query_syntax.shtml - it's at the bottom of the page under the heading "Reserved characters". (This also includes how to handle them)

These include:

Colon (:)
Escape a colon in a query with a backslash.

Double quotation marks (")
Escape double quotation marks in a query with a backslash in field queries.

Backslash (\\) Escape character
Escape a backslash in a query with another backslash.

You'll have to escape the colon - if your Solr library isn't doing this for you automagically. Escaping uses \\ as in most other cases, so foo\\:bar should work. Another option might be to wrap the value in quotes ( field:"foo:bar" ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM