-
Notifications
You must be signed in to change notification settings - Fork 3
/
wiki_search.go
50 lines (39 loc) · 1008 Bytes
/
wiki_search.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
package pitchfork
func Wiki_search(ctx PfCtx, pathroot string, c chan PfSearchResult, search string, abort <-chan bool) (err error) {
/* XXX: Namespace limiter (Groups) */
q := "SELECT DISTINCT ON (r.page_id) t.path, r.title, r.markdown " +
"FROM wiki_page_rev r " +
"INNER JOIN wiki_namespace t ON r.page_id = t.page_id " +
"INNER JOIN member ON r.member = member.ident " +
"WHERE t.path LIKE $1 " +
"AND r.markdown ILIKE $2 " +
"ORDER BY r.page_id, path DESC " +
"LIMIT 20"
pathq := pathroot + "%"
searchq := "%" + search + "%"
rows, err := DB.Query(q, pathq, searchq)
if err != nil {
return
}
defer rows.Close()
for rows.Next() {
/* First check if we need to abort */
select {
case <-abort:
return nil
default:
/* Nothing there, do work */
break
}
path := ""
title := ""
snippet := ""
err = rows.Scan(&path, &title, &snippet)
if err != nil {
return
}
/* The result */
SearchResult(c, "Wiki", title, path, snippet)
}
return nil
}