Skip to content
This repository
Browse code

Merge branch 'master' into live

  • Loading branch information...
commit 9d130ad9fb6845d4109543afbe6bfa98709cd517 2 parents 0d6b523 + 2723299
Jeff Handley authored July 03, 2012
17  Website/Infrastructure/Lucene/LuceneSearchService.cs
@@ -90,8 +90,6 @@ private static Query ParseQuery(string searchTerm)
90 90
             var fields = new Dictionary<string, float> { { "Id", 1.2f }, { "Title", 1.0f }, { "Tags", 0.8f }, { "Description", 0.1f }, 
91 91
                                                          { "Author", 1.0f } };
92 92
             var analyzer = new StandardAnalyzer(LuceneCommon.LuceneVersion);
93  
-            searchTerm = QueryParser.Escape(searchTerm).ToLowerInvariant();
94  
-
95 93
             var queryParser = new MultiFieldQueryParser(LuceneCommon.LuceneVersion, fields.Keys.ToArray(), analyzer, fields);
96 94
 
97 95
             var conjuctionQuery = new BooleanQuery();
@@ -100,9 +98,12 @@ private static Query ParseQuery(string searchTerm)
100 98
             disjunctionQuery.SetBoost(0.1f);
101 99
             var wildCardQuery = new BooleanQuery();
102 100
             wildCardQuery.SetBoost(0.5f);
103  
-            var exactIdQuery = new TermQuery(new Term("Id-Exact", searchTerm));
  101
+
  102
+            // Escape the entire term we use for exact searches.
  103
+            var escapedSearchTerm = Escape(searchTerm);
  104
+            var exactIdQuery = new TermQuery(new Term("Id-Exact", escapedSearchTerm));
104 105
             exactIdQuery.SetBoost(2.5f);
105  
-            var wildCardIdQuery = new WildcardQuery(new Term("Id-Exact", "*" + searchTerm + "*"));
  106
+            var wildCardIdQuery = new WildcardQuery(new Term("Id-Exact", "*" + escapedSearchTerm + "*"));
106 107
             
107 108
             foreach(var term in GetSearchTerms(searchTerm))
108 109
             {
@@ -127,7 +128,13 @@ private static IEnumerable<string> GetSearchTerms(string searchTerm)
127 128
         {
128 129
             return searchTerm.Split(new[] { ' ', '.', '-' }, StringSplitOptions.RemoveEmptyEntries)
129 130
                              .Concat(new[] { searchTerm })
130  
-                             .Distinct(StringComparer.OrdinalIgnoreCase);
  131
+                             .Distinct(StringComparer.OrdinalIgnoreCase)
  132
+                             .Select(Escape);
  133
+        }
  134
+
  135
+        private static string Escape(string term)
  136
+        {
  137
+            return QueryParser.Escape(term).ToLowerInvariant();
131 138
         }
132 139
     }
133 140
 }

0 notes on commit 9d130ad

Please sign in to comment.
Something went wrong with that request. Please try again.