本文整理匯總了Golang中structs.Index.IteratorKeywords方法的典型用法代碼示例。如果您正苦於以下問題:Golang Index.IteratorKeywords方法的具體用法?Golang Index.IteratorKeywords怎麽用?Golang Index.IteratorKeywords使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類structs.Index
的用法示例。
在下文中一共展示了Index.IteratorKeywords方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: queryIndex
func queryIndex(index *structs.Index, rexpstr string) {
r, err := regexp.Compile(rexpstr)
if err != nil {
fmt.Printf("%v\n", err.Error())
return
}
matchedDocsCount, matchedKeywordsCount := 0, 0
fmt.Println("Docs matched by regexp:")
for doc := range index.IteratorDocs() {
docStr := doc.(string)
if r.MatchString(docStr) {
matchedDocsCount++
fmt.Println(docStr)
}
}
fmt.Printf("%v total.\n", matchedDocsCount)
fmt.Println("Keywords matched by regexp:")
for keyword := range index.IteratorKeywords() {
keywordStr := keyword.(string)
if r.MatchString(keywordStr) {
fmt.Println(keyword)
matchedKeywordsCount++
inDocs := make([]string, 0)
for doc := range index.IteratorDocsByKeyword(keywordStr) {
inDocs = append(inDocs, doc.(string))
}
fmt.Printf("\tFound in the next %v documents:\n", len(inDocs))
for _, doc := range inDocs {
fmt.Printf("\t%v\n", doc)
}
}
}
fmt.Printf("%v total.\n", matchedKeywordsCount)
}
示例2: listAllKeywords
func listAllKeywords(index *structs.Index) {
fmt.Println("There are next keywords in the index:")
count := 0
for keyword := range index.IteratorKeywords() {
count++
fmt.Printf("\t%v\n", keyword)
}
fmt.Printf("%v in total\n", count)
}