1
votes

I am writing a SOLR query for faceted searching, and my fields can possibly have quotes or other bad characters in them, so I am using the raw operator to construct the query. However, if the user selects multiple facet values, I can't see how to use an OR in the query.

For example, the following returns results for a Manufacturer of Nike:

{!raw f=Manufacturer}Nike

The following returns results only for a Manufacturer of Adidas:

{!raw f=Manufacturer}Nike OR {!raw f=Manufacturer}Adidas

And the following returns no results:

{!raw f=Manufacturer}Nike OR Adidas

Is there a way to do this?

1
When selecting multiple facets, you should be building multiple filter queries, not appending to the main query.Mauricio Scheffer
@Mauricio: but if I add another query, won't it work as an intersection? I need to union the results from Nike and Adidas, in this example.Mark Avenius
oops, my bad, didn't read thoroughly, you're rightMauricio Scheffer

1 Answers

2
votes

Have you considered escaping the special characters, instead of using the raw operator? http://lucene.apache.org/java/2_4_0/queryparsersyntax.html#Escaping%20Special%20Characters

Escaping is pretty trivial to implement and the OR operator should work as expected. Here's an example of how to escape the special characters in PHP:

static public function escapeSolrValue($string)
{
    $match = array('\\', '+', '-', '&', '|', '!', '(', ')', '{', '}', '[', ']', '^', '~', '*', '?', ':', '"', ';', ' ');
    $replace = array('\\\\', '\\+', '\\-', '\\&', '\\|', '\\!', '\\(', '\\)', '\\{', '\\}', '\\[', '\\]', '\\^', '\\~', '\\*', '\\?', '\\:', '\\"', '\\;', '\\ ');
    $string = str_replace($match, $replace, $string);

    return $string;
}

Source: http://e-mats.org/2010/01/escaping-characters-in-a-solr-query-solr-url/