Skip to content

Instantly share code, notes, and snippets.

@sippylabs
Last active October 20, 2015 16:22
Show Gist options
  • Save sippylabs/b4e7d7ce6ae8f982f754 to your computer and use it in GitHub Desktop.
Save sippylabs/b4e7d7ce6ae8f982f754 to your computer and use it in GitHub Desktop.
wat
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