forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmore_like_this_token.go
42 lines (33 loc) · 908 Bytes
/
more_like_this_token.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package ravendb
import "strings"
var _ queryToken = &moreLikeThisToken{}
type moreLikeThisToken struct {
documentParameterName string
optionsParameterName string
whereTokens []queryToken
}
func newMoreLikeThisToken() *moreLikeThisToken {
return &moreLikeThisToken{}
}
func (t *moreLikeThisToken) writeTo(writer *strings.Builder) error {
writer.WriteString("moreLikeThis(")
if t.documentParameterName == "" {
var prevToken queryToken
for _, whereToken := range t.whereTokens {
documentQueryHelperAddSpaceIfNeeded(prevToken, whereToken, writer)
whereToken.writeTo(writer)
prevToken = whereToken
}
} else {
writer.WriteString("$")
writer.WriteString(t.documentParameterName)
}
if t.optionsParameterName == "" {
writer.WriteString(")")
return nil
}
writer.WriteString(", $")
writer.WriteString(t.optionsParameterName)
writer.WriteString(")")
return nil
}