From cd3113118823f89194f0edf758aae0d9923436ea Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Fri, 6 Nov 2015 09:46:36 -0500 Subject: Fixing searching for quotations --- model/search_params.go | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'model/search_params.go') diff --git a/model/search_params.go b/model/search_params.go index 144e8e461..17a64d980 100644 --- a/model/search_params.go +++ b/model/search_params.go @@ -16,7 +16,7 @@ type SearchParams struct { var searchFlags = [...]string{"from", "channel", "in"} -func splitWords(text string) []string { +func splitWordsNoQuotes(text string) []string { words := []string{} for _, word := range strings.Fields(text) { @@ -31,6 +31,32 @@ func splitWords(text string) []string { return words } +func splitWords(text string) []string { + words := []string{} + + foundQuote := false + location := 0 + for i, char := range text { + if char == '"' { + if foundQuote { + // Grab the quoted section + word := text[location : i+1] + words = append(words, word) + foundQuote = false + location = i + 1 + } else { + words = append(words, splitWordsNoQuotes(text[location:i])...) + foundQuote = true + location = i + } + } + } + + words = append(words, splitWordsNoQuotes(text[location:])...) + + return words +} + func parseSearchFlags(input []string) ([]string, [][2]string) { words := []string{} flags := [][2]string{} @@ -127,7 +153,7 @@ func ParseSearchParams(text string) []*SearchParams { } // special case for when no terms are specified but we still have a filter - if len(plainTerms) == 0 && len(hashtagTerms) == 0 { + if len(plainTerms) == 0 && len(hashtagTerms) == 0 && (len(inChannels) != 0 || len(fromUsers) != 0) { paramsList = append(paramsList, &SearchParams{ Terms: "", IsHashtag: true, -- cgit v1.2.3-1-g7c22