Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' into live

  • Loading branch information...
commit 9d130ad9fb6845d4109543afbe6bfa98709cd517 2 parents 0d6b523 + 2723299
Jeff Handley jeffhandley authored
Showing with 12 additions and 5 deletions.
  1. +12 −5 Website/Infrastructure/Lucene/LuceneSearchService.cs
17 Website/Infrastructure/Lucene/LuceneSearchService.cs
View
@@ -90,8 +90,6 @@ private static Query ParseQuery(string searchTerm)
var fields = new Dictionary<string, float> { { "Id", 1.2f }, { "Title", 1.0f }, { "Tags", 0.8f }, { "Description", 0.1f },
{ "Author", 1.0f } };
var analyzer = new StandardAnalyzer(LuceneCommon.LuceneVersion);
- searchTerm = QueryParser.Escape(searchTerm).ToLowerInvariant();
-
var queryParser = new MultiFieldQueryParser(LuceneCommon.LuceneVersion, fields.Keys.ToArray(), analyzer, fields);
var conjuctionQuery = new BooleanQuery();
@@ -100,9 +98,12 @@ private static Query ParseQuery(string searchTerm)
disjunctionQuery.SetBoost(0.1f);
var wildCardQuery = new BooleanQuery();
wildCardQuery.SetBoost(0.5f);
- var exactIdQuery = new TermQuery(new Term("Id-Exact", searchTerm));
+
+ // Escape the entire term we use for exact searches.
+ var escapedSearchTerm = Escape(searchTerm);
+ var exactIdQuery = new TermQuery(new Term("Id-Exact", escapedSearchTerm));
exactIdQuery.SetBoost(2.5f);
- var wildCardIdQuery = new WildcardQuery(new Term("Id-Exact", "*" + searchTerm + "*"));
+ var wildCardIdQuery = new WildcardQuery(new Term("Id-Exact", "*" + escapedSearchTerm + "*"));
foreach(var term in GetSearchTerms(searchTerm))
{
@@ -127,7 +128,13 @@ private static IEnumerable<string> GetSearchTerms(string searchTerm)
{
return searchTerm.Split(new[] { ' ', '.', '-' }, StringSplitOptions.RemoveEmptyEntries)
.Concat(new[] { searchTerm })
- .Distinct(StringComparer.OrdinalIgnoreCase);
+ .Distinct(StringComparer.OrdinalIgnoreCase)
+ .Select(Escape);
+ }
+
+ private static string Escape(string term)
+ {
+ return QueryParser.Escape(term).ToLowerInvariant();
}
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.