How to identify and quote reserved solr words

1,077 views
Skip to first unread message

Oliver Gould

unread,
Apr 11, 2013, 3:05:14 PM4/11/13
to php-sol...@googlegroups.com
I noticed that there are methods like escape and escapePhrase written in to the Apache_Solr_service class, but I don't see a way to identify and quote reserved solr words. Is there a list of reserved words somewhere I can use? Is there some other method for dealing with reserved words in user-inputted search phrases?

Donovan Jimenez

unread,
Apr 11, 2013, 3:54:42 PM4/11/13
to php-sol...@googlegroups.com
Typically, you're better off not worrying about it and just passing the user query unaltered onto solr as it is. Anything you need to do in addition to the user query (extra conditionals, etc) can be done in a separate fq paramter(s) or added automatically by the default parameters in your solr-config.xml. An accidental 'and', 'or', etc that's not escaped will not be the end of the world for the user, the results will still be reasonably correct. Additionally, your power users can actively use them to their advantage.

If you really want to protect the user from themselves then you could go down the road of full query parsing (and the dealing with syntax errors). There was a lucene query parser in the zend framework zend_search_lucene classes that you could probably dig up. You could also restrict your users to a simpler query language than full syntax and just do find / replaces. Because this can be so usage specific, I didn't really try to address this directly in the client, but I have had to do query manipulation in the past, and its never seems to turn out super pretty.

Donovan 


On Thu, Apr 11, 2013 at 3:05 PM, Oliver Gould <oliver.l...@gmail.com> wrote:
I noticed that there are methods like escape and escapePhrase written in to the Apache_Solr_service class, but I don't see a way to identify and quote reserved solr words. Is there a list of reserved words somewhere I can use? Is there some other method for dealing with reserved words in user-inputted search phrases?

--
You received this message because you are subscribed to the Google Groups "PHP Solr Client" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-solr-clie...@googlegroups.com.
To post to this group, send email to php-sol...@googlegroups.com.
Visit this group at http://groups.google.com/group/php-solr-client?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Oliver Gould

unread,
Apr 17, 2013, 2:34:18 PM4/17/13
to php-sol...@googlegroups.com
Donovan, thanks for your response. Currently I am working with a customised version of Drupal_Solr_Query_Interface with a site that implements a heavily customised version of Drupal 6. The problem I am facing deals with filtering results for the state of Oregon. Because of how the library parses subqueries and filters, I end up with a portion of the Solr query that looks like this:

ss_state:OR

which the Solr query parser cannot handle. I realize that hacking the Drupal library in question is outside the scope of this board, but just wanted to ask to see if I'm in the ballpark here. At the moment, the library disassembles any passed subquery phrase like:

ss_state:"OR"

and then puts it back together again as I have written above. The library will only wrap the key phrase in double quotes if it sees a space character or sees a range query using a regex. I believe I need to add another condition that detects when the entire key phrase is a reserved Solr keyword.
Reply all
Reply to author
Forward
0 new messages