當前位置: 首頁>>代碼示例>>Golang>>正文


Golang structs.Index類代碼示例

本文整理匯總了Golang中structs.Index的典型用法代碼示例。如果您正苦於以下問題:Golang Index類的具體用法?Golang Index怎麽用?Golang Index使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Index類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: listAll

func listAll(index *structs.Index) {
	fmt.Println("Contents of the index:")
	for doc := range index.IteratorDocs() {
		fmt.Printf("%v\n", doc)
		for keyword := range index.IteratorKeywordsByDoc(doc) {
			fmt.Printf("\t%v\n", keyword)
		}
	}
}
開發者ID:just-another-one-timmy,項目名稱:injackted,代碼行數:9,代碼來源:sampleclient.go

示例2: listAllDocs

func listAllDocs(index *structs.Index) {
	fmt.Println("There are next docs in the index:")
	count := 0
	for doc := range index.IteratorDocs() {
		count++
		fmt.Printf("\t%v\n", doc)
	}
	fmt.Printf("%v in total\n", count)
}
開發者ID:just-another-one-timmy,項目名稱:injackted,代碼行數:9,代碼來源:sampleclient.go

示例3: 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)
}
開發者ID:just-another-one-timmy,項目名稱:injackted,代碼行數:9,代碼來源:sampleclient.go

示例4: listKeywords

func listKeywords(index *structs.Index, doc string) {
	fmt.Printf("Keywords contained in %q:\n", doc)
	count := 0
	for keyword := range index.IteratorKeywordsByDoc(doc) {
		count++
		fmt.Printf("\t%v\n", keyword)
	}
	fmt.Printf("%v in total\n", count)
}
開發者ID:just-another-one-timmy,項目名稱:injackted,代碼行數:9,代碼來源:sampleclient.go

示例5: listDocs

func listDocs(index *structs.Index, keyword string) {
	fmt.Printf("Documents which contain keyword %q:\n", keyword)
	count := 0
	for doc := range index.IteratorDocsByKeyword(keyword) {
		count++
		fmt.Printf("\t%v\n", doc)
	}
	fmt.Printf("%v in total\n", count)
}
開發者ID:just-another-one-timmy,項目名稱:injackted,代碼行數:9,代碼來源:sampleclient.go

示例6: 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)
}
開發者ID:just-another-one-timmy,項目名稱:injackted,代碼行數:34,代碼來源:sampleclient.go

示例7: crawl

func crawl(index *structs.Index, fileNames []string) {
	// channel to recieve doc-keyword pairs.
	c := make(chan DocKeywordPair)
	// channel to count number of go-routines.
	w := make(chan string)

	semaphore := make(chan interface{}, MAX_FILES_OPEN)

	goroutinesCount := len(fileNames)
	for _, fileName := range fileNames {
		go processFile(fileName, c, w, semaphore)
	}
	for goroutinesCount > 0 {
		select {
		case docKeywordPair := <-c:
			index.ConnectKeywordDoc(docKeywordPair.Keyword,
				docKeywordPair.Doc)
		case name := <-w:
			goroutinesCount--
			percentage := (1.0 - float64(goroutinesCount)/float64(len(fileNames))) * 100
			fmt.Printf("Processed file %v\t%6.2f%%\n", name, percentage)
		}
	}
}
開發者ID:just-another-one-timmy,項目名稱:injackted,代碼行數:24,代碼來源:crawler.go

示例8: connect

func connect(index *structs.Index, keyword string, doc string) {
	index.ConnectKeywordDoc(keyword, doc)
	fmt.Printf("%q and %q were connected in the index\n", keyword, doc)
}
開發者ID:just-another-one-timmy,項目名稱:injackted,代碼行數:4,代碼來源:sampleclient.go


注:本文中的structs.Index類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。