Skip to content

Commit

Permalink
Fixes: #11
Browse files Browse the repository at this point in the history
  • Loading branch information
Shazwazza committed Apr 1, 2015
1 parent fab1f23 commit f4d3f73
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
15 changes: 14 additions & 1 deletion Projects/Examine.Test/Search/StringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,23 @@ public void Search_Remove_Stop_Words()
var parsed1 = stringPhrase1.RemoveStopWords();
var parsed2 = stringPhrase2.RemoveStopWords();

Assert.AreEqual("hello my name \"Shannon Deminick\" \"and I like to code\", here stop word two", parsed1);
Assert.AreEqual("hello my name \"Shannon Deminick\" \"and I like to code\" , here stop word two", parsed1);
Assert.AreEqual("\"into the darkness\" sentence quote \"the front and the end\"", parsed2);
}

[Test]
public void Search_Remove_Stop_Words_Uneven_Quotes()
{

var stringPhrase1 = "hello my name is \"Shannon Deminick \"and I like to code\", here is a stop word and or two";

var parsed1 = stringPhrase1.RemoveStopWords();

Assert.AreEqual("hello my name \"Shannon Deminick\" I like code , here stop word two", parsed1);

}


public override void TestSetup()
{

Expand Down
27 changes: 19 additions & 8 deletions Projects/Examine/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ public static string RemoveStopWords(this string searchText)
if (!IsStandardAnalyzerStopWord(t))
{
innerBuilder.Append(t);
innerBuilder.Append(" ");
innerBuilder.Append(" ");
}
}
b.Append(innerBuilder.ToString().TrimEnd(' '));
b.Append(innerBuilder.ToString());
};

var builder = new StringBuilder();
Expand All @@ -75,9 +75,18 @@ public static string RemoveStopWords(this string searchText)
{
//move to next quote
carrat = searchText.IndexOf("\"", quoteIndex + 1) + 1;
//add phrase to builder
builder.Append(searchText.Substring(quoteIndex, carrat - quoteIndex));
//builder.Append(' ');

if (carrat > 0)
{
//add phrase to builder
var phraseWithoutQuotes = searchText.Substring(quoteIndex + 1, carrat - quoteIndex - 2);
builder.Append("\"" + phraseWithoutQuotes.Trim() + "\" ");
}
else
{
//there are not more quotes
carrat = quoteIndex + 1;
}
}
else
{
Expand All @@ -87,9 +96,11 @@ public static string RemoveStopWords(this string searchText)
{
nextCarrat = searchText.Length;
}
var terms = searchText.Substring(carrat, nextCarrat - carrat);
removeWords(terms, builder);
if (terms.EndsWith(" ")) builder.Append(' ');
var terms = searchText.Substring(carrat, nextCarrat - carrat).Trim();
if (!string.IsNullOrWhiteSpace(terms))
{
removeWords(terms, builder);
}
carrat = nextCarrat;
}
}
Expand Down

0 comments on commit f4d3f73

Please sign in to comment.