Last active
October 20, 2015 16:22
-
-
Save sippylabs/b4e7d7ce6ae8f982f754 to your computer and use it in GitHub Desktop.
wat
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
terms = terms.Replace("-", " "); // e.g, "Berwick-upon-Tweed" => "Berwick upon Tweed" | |
terms = terms.ToAlphanumericOrWhitespace(); // remove all other apostrophes etc | |
List<string> parts = null; | |
var sb = new StringBuilder(); | |
bool haveAppendedWord = false; | |
IEnumerable<string> TermsSplitBySpace = terms.SplitByDelimiter(' '); | |
if (TermsSplitBySpace != null) | |
{ | |
parts = TermsSplitBySpace.ToList(); | |
bool appendWord = true; | |
foreach (string s in parts) | |
{ | |
if (stMode == SearchTermMode.AllWords && !IsSearchableWord(s)) | |
{ | |
appendWord = false; | |
} | |
if (appendWord && haveAppendedWord) | |
{ | |
switch (stMode) | |
{ | |
case SearchTermMode.AnyWords: | |
sb.Append(" OR "); | |
break; | |
case SearchTermMode.AllWords: | |
sb.Append(" AND "); | |
break; | |
default: | |
sb.Append(" "); | |
break; | |
} | |
} | |
if (appendWord) | |
{ | |
haveAppendedWord = true; | |
sb.Append(s); | |
} | |
appendWord = true; | |
} | |
} | |
string parsedTerms = sb.ToString(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment