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

32
main.go
View file

@ -18,13 +18,13 @@ import (
)
const (
defaultHost = "0.0.0.0"
defaultPort = "50051"
defaultEsHost = "http://localhost"
defaultEsPort = "9200"
defaultHost = "0.0.0.0"
defaultPort = "50051"
defaultEsHost = "http://localhost"
defaultEsIndex = "claims"
defaultEsPort = "9200"
)
func GetEnvironment(data []string, getkeyval func(item string) (key, val string)) map[string]string {
items := make(map[string]string)
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})
port := parser.String("", "rpcport", &argparse.Options{Required: false, Help: "port", Default: defaultPort})
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})
dev := parser.Flag("", "dev", &argparse.Options{Required: false, Help: "port", Default: false})
text := parser.String("", "text", &argparse.Options{Required: false, Help: "text query"})
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))
}
args := &server.Args{
Serve: false,
Host: *host,
Port: ":" + *port,
EsHost: *esHost,
EsPort: *esPort,
Dev: *dev,
Serve: false,
Host: *host,
Port: ":" + *port,
EsHost: *esHost,
EsPort: *esPort,
EsIndex: *esIndex,
}
if esHost, ok := environment["ELASTIC_HOST"]; ok {
@ -95,8 +94,8 @@ func parseArgs(searchRequest *pb.SearchRequest) *server.Args {
}
/*
Verify no invalid argument combinations
*/
Verify no invalid argument combinations
*/
if len(*channelIds) > 0 && *channelId != "" {
log.Fatal("Cannot specify both channel_id and channel_ids")
}
@ -108,7 +107,7 @@ func parseArgs(searchRequest *pb.SearchRequest) *server.Args {
if *text != "" {
searchRequest.Text = *text
}
if *name!= "" {
if *name != "" {
searchRequest.Name = []string{*name}
}
if *claimType != "" {
@ -174,7 +173,6 @@ func main() {
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
r, err := c.Search(ctx, searchRequest)
if err != nil {
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 orderBy []orderField
var searchIndices = []string{}
searchIndices = make([]string, 0, 1)
searchIndices = append(searchIndices, s.Args.EsIndex)
q := elastic.NewBoolQuery()
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 {
searchIndices = in.SearchIndices
}
@ -185,7 +171,6 @@ func (s *Server) Search(ctx context.Context, in *pb.SearchRequest) (*pb.Outputs,
Query(q). // specify the query
From(0).Size(DefaultSearchSize)
for _, x := range orderBy {
search = search.Sort(x.Field, x.IsAsc)
}

View file

@ -11,7 +11,7 @@ import (
type Server struct {
GrpcServer *grpc.Server
Args *Args
Args *Args
MultiSpaceRe *regexp.Regexp
WeirdCharsRe *regexp.Regexp
EsClient *elastic.Client
@ -19,12 +19,12 @@ type Server struct {
}
type Args struct {
Serve bool
Host string
Port string
EsHost string
EsPort string
Dev bool
Serve bool
Host string
Port string
EsHost string
EsPort string
EsIndex string
}
/*
@ -79,12 +79,12 @@ func MakeHubServer(args *Args) *Server {
log.Fatal(err)
}
s := &Server {
GrpcServer: grpcServer,
Args: args,
s := &Server{
GrpcServer: grpcServer,
Args: args,
MultiSpaceRe: multiSpaceRe,
WeirdCharsRe: weirdCharsRe,
}
return s
}
}