-
Notifications
You must be signed in to change notification settings - Fork 5
/
query.go
52 lines (42 loc) · 1.07 KB
/
query.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
43
44
45
46
47
48
49
50
51
52
package stalefish
type MatchAllQuery struct{}
func NewMatchAllQuery() MatchAllQuery {
return MatchAllQuery{}
}
func (q MatchAllQuery) Searcher(storage Storage) Searcher {
return NewMatchAllSearcher(storage)
}
type MatchQuery struct {
keyword string
logic Logic
analyzer Analyzer
sorter Sorter
}
func NewMatchQuery(keyword string, logic Logic, analyzer Analyzer, sorter Sorter) MatchQuery {
return MatchQuery{
keyword: keyword,
logic: logic,
analyzer: analyzer,
sorter: sorter,
}
}
func (q MatchQuery) Searcher(storage Storage) Searcher {
tokenStream := q.analyzer.Analyze(q.keyword)
return NewMatchSearcher(tokenStream, q.logic, storage, q.sorter)
}
type PhraseQuery struct {
phrase string
analyzer Analyzer
sorter Sorter
}
func NewPhraseQuery(phrase string, analyzer Analyzer, sorter Sorter) PhraseQuery {
return PhraseQuery{
phrase: phrase,
analyzer: analyzer,
sorter: sorter,
}
}
func (q PhraseQuery) Searcher(storage Storage) Searcher {
terms := q.analyzer.Analyze(q.phrase)
return NewPhraseSearcher(terms, storage, q.sorter)
}