func (t *TextField) Analyze() (int, analysis.TokenFrequencies) { var tokens analysis.TokenStream if t.analyzer != nil { bytesToAnalyze := t.Value() if t.options.IsStored() { // need to copy bytesCopied := make([]byte, len(bytesToAnalyze)) copy(bytesCopied, bytesToAnalyze) bytesToAnalyze = bytesCopied } tokens = t.analyzer.Analyze(bytesToAnalyze) } else { tokens = analysis.TokenStream{ &analysis.Token{ Start: 0, End: len(t.value), Term: t.value, Position: 1, Type: analysis.AlphaNumeric, }, } } fieldLength := len(tokens) // number of tokens in this doc field tokenFreqs := analysis.TokenFrequency(tokens) return fieldLength, tokenFreqs }
func (n *DateTimeField) Analyze() (int, analysis.TokenFrequencies) { tokens := make(analysis.TokenStream, 0) tokens = append(tokens, &analysis.Token{ Start: 0, End: len(n.value), Term: n.value, Position: 1, Type: analysis.DateTime, }) original, err := n.value.Int64() if err == nil { shift := DefaultDateTimePrecisionStep for shift < 64 { shiftEncoded, err := numeric_util.NewPrefixCodedInt64(original, shift) if err != nil { break } token := analysis.Token{ Start: 0, End: len(shiftEncoded), Term: shiftEncoded, Position: 1, Type: analysis.DateTime, } tokens = append(tokens, &token) shift += DefaultDateTimePrecisionStep } } fieldLength := len(tokens) tokenFreqs := analysis.TokenFrequency(tokens) return fieldLength, tokenFreqs }