Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

solr sanitizing query

I am using solr with ruby on rails. It's all working well, I just need to know if there's any existing code to sanitize user input, like a query starting with ? or *

like image 232
Ori Avatar asked Jul 15 '09 19:07

Ori


People also ask

How do I debug Solr query?

The essential tool for debugging search results is the “explain” mechanism of Solr which is triggered by adding &debug=true to search queries. This produces detail scoring information for each document. A sample of the debug output is shown below, with explanations.

How do you write a query in Solr?

If you do not specify a field in a query, Solr searches only the default field. Alternatively, you can specify a different field or a combination of fields in a query. To specify a field, type the field name followed by a colon ":" and then the term you are searching for within the field.

How do I query Solr admin?

You can search for "solr" by loading the Admin UI Query tab, enter "solr" in the q param (replacing *:* , which matches all documents), and "Execute Query". See the Searching section below for more information. To index your own data, re-run the directory indexing command pointed to your own directory of documents.

What is Q in Solr query?

The defType parameter selects the query parser that Solr should use to process the main query parameter ( q ) in the request.


1 Answers

I don't know any code that does this, but theoretically it could be done by looking at the parsing code in Lucene and searching for throw new ParseException (only 16 matches!).

In practice, I think you're better off just catching any solr exceptions in your code and showing an "invalid query" message or something like that.

EDIT: Here are a couple of "sanitizers":

  • http://pivotallabs.com/users/zach/blog/articles/937-sanitizing-solr-requests
  • http://github.com/jvoorhis/lucene_query
  • http://e-mats.org/2010/01/escaping-characters-in-a-solr-query-solr-url/
like image 147
Mauricio Scheffer Avatar answered Oct 05 '22 23:10

Mauricio Scheffer