diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-04-29 13:06:13 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2013-04-29 13:06:13 -0400 |
| commit | 8217bafb2402792acc6a8d4a2348d0370977aa0a (patch) | |
| tree | 8e90a9f698ad1102ab5852a1b905f9b22cd4b0cd /MediaBrowser.Server.Implementations/Library | |
| parent | 33f4b2ed53b90af6dca441cdd52c6f41a66cac17 (diff) | |
use regex instead of indexof with search
Diffstat (limited to 'MediaBrowser.Server.Implementations/Library')
| -rw-r--r-- | MediaBrowser.Server.Implementations/Library/LuceneSearchEngine.cs | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/MediaBrowser.Server.Implementations/Library/LuceneSearchEngine.cs b/MediaBrowser.Server.Implementations/Library/LuceneSearchEngine.cs index e46ce0120..2dc4ecbb8 100644 --- a/MediaBrowser.Server.Implementations/Library/LuceneSearchEngine.cs +++ b/MediaBrowser.Server.Implementations/Library/LuceneSearchEngine.cs @@ -1,4 +1,5 @@ -using Lucene.Net.Analysis.Standard; +using System.Text.RegularExpressions; +using Lucene.Net.Analysis.Standard; using Lucene.Net.Documents; using Lucene.Net.Index; using Lucene.Net.QueryParsers; @@ -240,15 +241,20 @@ namespace MediaBrowser.Server.Implementations.Library return new Tuple<string, int>(searchInput, 0); } - var index = input.IndexOf(searchInput, StringComparison.OrdinalIgnoreCase); + var match = Regex.Match(input, searchInput, RegexOptions.IgnoreCase); - if (index == 0) + if (match.Success) { - return new Tuple<string, int>(searchInput, 1); - } - if (index > 0) - { - return new Tuple<string, int>(searchInput, 2); + var index = match.Index; + + if (index == 0) + { + return new Tuple<string, int>(searchInput, 1); + } + if (index > 0) + { + return new Tuple<string, int>(searchInput, 2); + } } var items = GetWords(input); @@ -266,15 +272,20 @@ namespace MediaBrowser.Server.Implementations.Library return new Tuple<string, int>(searchTerm, 3 + (i + 1) * (j + 1)); } - index = item.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase); + match = Regex.Match(item, searchTerm, RegexOptions.IgnoreCase); - if (index == 0) + if (match.Success) { - return new Tuple<string, int>(searchTerm, 4 + (i + 1) * (j + 1)); - } - if (index > 0) - { - return new Tuple<string, int>(searchTerm, 5 + (i + 1) * (j + 1)); + var index = match.Index; + + if (index == 0) + { + return new Tuple<string, int>(searchTerm, 4 + (i + 1) * (j + 1)); + } + if (index > 0) + { + return new Tuple<string, int>(searchTerm, 5 + (i + 1) * (j + 1)); + } } } } |
