Skip to content

Instantly share code, notes, and snippets.

@unexpand
Last active April 18, 2019 13:54
Show Gist options
  • Save unexpand/228f79ff69f4d76907dd5d3a54bc9419 to your computer and use it in GitHub Desktop.
Save unexpand/228f79ff69f4d76907dd5d3a54bc9419 to your computer and use it in GitHub Desktop.
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"strconv"
"github.com/blevesearch/bleve"
type Info struct {
ID string `json:"id"`
FirstNm string `json:"firstNm"`
MidNm string `json:"midNm"`
LastNm string `json:"lastNm"`
Link string `json:"link"`
ActvAGReg string `json:"actvAGReg"`
IndPK string `json:"indPK"`
}
func main() {
mapping := bleve.NewIndexMapping()
index, err := bleve.New("searchadv.scorch", mapping)
if err != nil {
fmt.Println(err)
return
}
// batch := index.NewBatch()
for i := 1; i < 21; i++ {
path := "data/usrs/feed" + strconv.Itoa(i) + ".json"
raw, err := ioutil.ReadFile(path)
if err != nil {
log.Fatal(err)
}
var f []Indvls
json.Unmarshal([]byte(raw), &f)
for j := 0; j <= (len(f) - 1); j++ {
docb := map[string]interface{}{
"FirstNm": f[kk].Indvl.CrntUsrs.FirstNm,
"MidNm" : f[j].Indvl.CrntUsrs.MidNm,
"LastNm": f[j].Indvl.CrntUsrs.LastNm,
"Link": f[j].Indvl.CrntUsrs.Link,
"ActvAGReg": f[j].Indvl.CrntUsrs.ActvAGReg,
"IndPK": f[j].Indvl.CrntUsrs.IndPK,
}
err = index.Index(f[j].Indvl.Info.ID, docb)
if err != nil {
log.Println(err)
}
}
}
log.Print("done")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment