From 6e9da3bab72a62f4768339c677c6d84a51116c2c Mon Sep 17 00:00:00 2001 From: Marty Schoch Date: Sun, 6 Dec 2015 14:01:53 -0500 Subject: [PATCH] allow running prefix queries through bleve_query command --- utils/bleve_query/main.go | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/utils/bleve_query/main.go b/utils/bleve_query/main.go index 068e131d..f7b3939c 100644 --- a/utils/bleve_query/main.go +++ b/utils/bleve_query/main.go @@ -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