specify index, remove --dev

This commit is contained in:
Victor Shyba 2021-08-11 00:39:37 -03:00
parent 228fc6f54b
commit d2d17bee3b
3 changed files with 28 additions and 45 deletions

View file

@ -21,10 +21,10 @@ const (
defaultHost = "0.0.0.0" defaultHost = "0.0.0.0"
defaultPort = "50051" defaultPort = "50051"
defaultEsHost = "http://localhost" defaultEsHost = "http://localhost"
defaultEsIndex = "claims"
defaultEsPort = "9200" defaultEsPort = "9200"
) )
func GetEnvironment(data []string, getkeyval func(item string) (key, val string)) map[string]string { func GetEnvironment(data []string, getkeyval func(item string) (key, val string)) map[string]string {
items := make(map[string]string) items := make(map[string]string)
for _, item := range data { for _, item := range data {
@ -53,8 +53,8 @@ func parseArgs(searchRequest *pb.SearchRequest) *server.Args {
host := parser.String("", "rpchost", &argparse.Options{Required: false, Help: "host", Default: defaultHost}) host := parser.String("", "rpchost", &argparse.Options{Required: false, Help: "host", Default: defaultHost})
port := parser.String("", "rpcport", &argparse.Options{Required: false, Help: "port", Default: defaultPort}) port := parser.String("", "rpcport", &argparse.Options{Required: false, Help: "port", Default: defaultPort})
esHost := parser.String("", "eshost", &argparse.Options{Required: false, Help: "host", Default: defaultEsHost}) esHost := parser.String("", "eshost", &argparse.Options{Required: false, Help: "host", Default: defaultEsHost})
esIndex := parser.String("", "esindex", &argparse.Options{Required: false, Help: "host", Default: defaultEsIndex})
esPort := parser.String("", "esport", &argparse.Options{Required: false, Help: "port", Default: defaultEsPort}) esPort := parser.String("", "esport", &argparse.Options{Required: false, Help: "port", Default: defaultEsPort})
dev := parser.Flag("", "dev", &argparse.Options{Required: false, Help: "port", Default: false})
text := parser.String("", "text", &argparse.Options{Required: false, Help: "text query"}) text := parser.String("", "text", &argparse.Options{Required: false, Help: "text query"})
name := parser.String("", "name", &argparse.Options{Required: false, Help: "name"}) name := parser.String("", "name", &argparse.Options{Required: false, Help: "name"})
@ -72,14 +72,13 @@ func parseArgs(searchRequest *pb.SearchRequest) *server.Args {
log.Fatalln(parser.Usage(err)) log.Fatalln(parser.Usage(err))
} }
args := &server.Args{ args := &server.Args{
Serve: false, Serve: false,
Host: *host, Host: *host,
Port: ":" + *port, Port: ":" + *port,
EsHost: *esHost, EsHost: *esHost,
EsPort: *esPort, EsPort: *esPort,
Dev: *dev, EsIndex: *esIndex,
} }
if esHost, ok := environment["ELASTIC_HOST"]; ok { if esHost, ok := environment["ELASTIC_HOST"]; ok {
@ -174,7 +173,6 @@ func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second) ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel() defer cancel()
r, err := c.Search(ctx, searchRequest) r, err := c.Search(ctx, searchRequest)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View file

@ -153,27 +153,13 @@ func (s *Server) Search(ctx context.Context, in *pb.SearchRequest) (*pb.Outputs,
var pageSize = 10 var pageSize = 10
var orderBy []orderField var orderBy []orderField
var searchIndices = []string{} var searchIndices = []string{}
searchIndices = make([]string, 0, 1)
searchIndices = append(searchIndices, s.Args.EsIndex)
q := elastic.NewBoolQuery() q := elastic.NewBoolQuery()
q = s.setupEsQuery(q, in, &pageSize, &from, &orderBy) q = s.setupEsQuery(q, in, &pageSize, &from, &orderBy)
if s.Args.Dev && len(in.SearchIndices) == 0 {
// If we're running in dev mode ignore the mainnet claims index
indices, err := client.IndexNames()
if err != nil {
log.Fatalln(err)
}
var numIndices = len(indices)
searchIndices = make([]string, 0, numIndices)
for i := 0; i < numIndices; i++ {
if indices[i] == "claims" {
continue
}
searchIndices = append(searchIndices, indices[i])
}
}
if len(in.SearchIndices) > 0 { if len(in.SearchIndices) > 0 {
searchIndices = in.SearchIndices searchIndices = in.SearchIndices
} }
@ -185,7 +171,6 @@ func (s *Server) Search(ctx context.Context, in *pb.SearchRequest) (*pb.Outputs,
Query(q). // specify the query Query(q). // specify the query
From(0).Size(DefaultSearchSize) From(0).Size(DefaultSearchSize)
for _, x := range orderBy { for _, x := range orderBy {
search = search.Sort(x.Field, x.IsAsc) search = search.Sort(x.Field, x.IsAsc)
} }

View file

@ -24,7 +24,7 @@ type Args struct {
Port string Port string
EsHost string EsHost string
EsPort string EsPort string
Dev bool EsIndex string
} }
/* /*