func (p *Page) AddQueryWord(word string) { word = strings.TrimSpace(word) if word == "" { return } word = strings.ToLower(word) words := strings.Fields(word) for _, aWord := range words { if !p.wordValid(aWord) { aWord = "" } aWord = string(stemmer.Stem([]byte(aWord))) } word = strings.Join(words, " ") wordObj, exists := p.words[word] position := p.wordCount + 1 if !exists { wordObj = NewWord(word) } wordObj.positions = append(wordObj.positions, position) p.words[word] = wordObj p.wordCount++ }
// Sequentially adds word to the list of words for the page. // The word will be assigned the next position. // If the word already exists only the position is added. // Duplicates and stopwords are ignored. func (p *Page) addWordFromText(word string) { word = strings.TrimSpace(word) if word == "" { return } word = strings.ToLower(word) if !p.wordValid(word) { return } word = string(stemmer.Stem([]byte(word))) wordObj, exists := p.words[word] position := p.wordCount + 1 if !exists { wordObj = NewWord(word) } wordObj.positions = append(wordObj.positions, position) p.words[word] = wordObj p.wordCount++ }