0
0

allow running prefix queries through bleve_query command

This commit is contained in:
Marty Schoch 2015-12-06 14:01:53 -05:00
parent a73a178923
commit 6e9da3bab7

View File

@ -29,6 +29,8 @@ var explain = flag.Bool("explain", false, "explain scores")
var includeHighlights = flag.Bool("highlight", true, "highlight matches")
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")
var repeat = flag.Int("repeat", 1, "repeat query n times")
var qtype = flag.String("queryType", "query_string", "type of query to execute: query_string, prefix")
var qfield = flag.String("field", "", "the field to query, not applicable to query_string queries")
func main() {
@ -67,9 +69,21 @@ func main() {
}()
for i := 0; i < *repeat; i++ {
// build a search with the provided parameters
queryString := strings.Join(flag.Args(), " ")
query := bleve.NewQueryStringQuery(queryString)
var query bleve.Query
switch *qtype {
case "prefix":
pquery := bleve.NewPrefixQuery(strings.Join(flag.Args(), " "))
if *qfield != "" {
pquery.SetField(*qfield)
}
query = pquery
default:
// build a search with the provided parameters
queryString := strings.Join(flag.Args(), " ")
query = bleve.NewQueryStringQuery(queryString)
}
searchRequest := bleve.NewSearchRequestOptions(query, *limit, *skip, *explain)
// enable highlights if requested