Exemple #1
0
func indexDocument(engine factory.SearchEngine) (timeTook int64) {
	data, err := utils.ReadFile(*pathToDoc)
	utils.ErrorCheck(err)
	fmt.Printf("Indexing document: %s\n", *pathToDoc)
	doc := factory.Document{utils.FixIdSyntax(*pathToDoc), data}
	timeTook, err = engine.Index(&doc)
	utils.ErrorCheck(err)
	return timeTook
}
Exemple #2
0
func indexDocuments(engine factory.SearchEngine) (int64, int) {
	// prepare documents for batch index
	files, err := ioutil.ReadDir(*pathToFolder)
	utils.ErrorCheck(err)
	var docCount int = 0
	var documents = make([]*factory.Document, len(files))
	for _, file := range files {
		if file.IsDir() {
			continue // expected flat structure
		}
		path := *pathToFolder + "/" + file.Name()
		data, err := utils.ReadFile(path)
		utils.ErrorCheck(err)
		documents[docCount] = &factory.Document{utils.FixIdSyntax(path), data}
		docCount++
	}
	// index in batch
	timeTook, err := engine.BatchIndex(documents)
	utils.ErrorCheck(err)
	return timeTook, docCount
}