Created
January 13, 2014 16:28
-
-
Save BartDM/8403197 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Parse the givven query string to a Lucene Query object | |
/// </summary> | |
/// <param name="searchQuery">The query string</param> | |
/// <param name="parser">The Lucense QueryParser</param> | |
/// <returns>A Lucene Query object</returns> | |
private Query ParseQuery(string searchQuery, QueryParser parser) | |
{ | |
parser.AllowLeadingWildcard = true; | |
Query q; | |
try | |
{ | |
q = parser.Parse(searchQuery); | |
} | |
catch (ParseException e) | |
{ | |
Log.Error("Query parser exception", e); | |
q = null; | |
} | |
if (q == null || string.IsNullOrEmpty(q.ToString())) | |
{ | |
string cooked = Regex.Replace(searchQuery, @"[^\w\.@-]", " "); | |
q = parser.Parse(cooked); | |
} | |
Log.DebugFormat("Parsed query for Lucene: \"{0}\"", q); | |
return q; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment