Created
December 1, 2017 20:25
-
-
Save mschoch/1bc53ce7929ea5dead9fff029f11e8fc to your computer and use it in GitHub Desktop.
test scorch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"os" | |
"github.com/blevesearch/bleve" | |
"github.com/blevesearch/bleve/index/scorch" | |
"github.com/blevesearch/bleve/search/highlight/highlighter/ansi" | |
) | |
func main() { | |
os.RemoveAll("/tmp/scorch") | |
m := bleve.NewIndexMapping() | |
idx, err := bleve.NewUsing("/tmp/scorch", m, scorch.Name, scorch.Name, nil) | |
//idx, err := bleve.New("/tmp/scorch", m) | |
if err != nil { | |
log.Fatal(err) | |
} | |
batch := idx.NewBatch() | |
err = batch.Index("a", map[string]interface{}{ | |
"name": "marty", | |
"tags": []string{"cold", "dark"}, | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
err = batch.Index("b", map[string]interface{}{ | |
"name": "joe", | |
"tags": []string{"hot", "dark", "hot"}, | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
err = idx.Batch(batch) | |
if err != nil { | |
log.Fatal(err) | |
} | |
// second Batch | |
batch = idx.NewBatch() | |
err = batch.Index("c", map[string]interface{}{ | |
"name": "steve", | |
"tags": []string{"cold", "dark"}, | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
err = batch.Index("d", map[string]interface{}{ | |
"name": "rob", | |
"tags": []string{"hot", "dark", "hot"}, | |
}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
// try a delete | |
batch.Delete("b") | |
err = idx.Batch(batch) | |
if err != nil { | |
log.Fatal(err) | |
} | |
q := bleve.NewTermQuery("rob") | |
req := bleve.NewSearchRequest(q) | |
//req.Fields = []string{"*"} | |
req.Highlight = bleve.NewHighlightWithStyle(ansi.Name) | |
//req.Explain = true | |
res, err := idx.Search(req) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Println(res) | |
//fmt.Printf("loc %v\n", res.Hits[0].Locations) | |
err = idx.Close() | |
if err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment