Fixing searching for quotations

Этот коммит содержится в:
Christopher Speller
2015-11-06 09:46:36 -05:00
родитель ff38c402cb
Коммит cd31131188
4 изменённых файлов: 171 добавлений и 7 удалений

Просмотреть файл

@@ -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,