summaryrefslogtreecommitdiffstats
path: root/model/search_params.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-11-06 09:46:36 -0500
committerChristopher Speller <crspeller@gmail.com>2015-11-06 10:09:51 -0500
commitcd3113118823f89194f0edf758aae0d9923436ea (patch)
treee0f35d3814c5985f17414fdbcfe4cdc254e1f553 /model/search_params.go
parentff38c402cb793bbea8881f9cdc8123d0959e6e08 (diff)
downloadchat-cd3113118823f89194f0edf758aae0d9923436ea.tar.gz
chat-cd3113118823f89194f0edf758aae0d9923436ea.tar.bz2
chat-cd3113118823f89194f0edf758aae0d9923436ea.zip
Fixing searching for quotations
Diffstat (limited to 'model/search_params.go')
-rw-r--r--model/search_params.go30
1 files changed, 28 insertions, 2 deletions
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,