Add support for more fields
This commit is contained in:
parent
2b6f5c4aed
commit
a671683fe8
6 changed files with 773 additions and 437 deletions
2
go.mod
2
go.mod
|
@ -3,11 +3,11 @@ module github.com/lbryio/hub
|
|||
go 1.16
|
||||
|
||||
require (
|
||||
github.com/btcsuite/btcutil v1.0.2
|
||||
github.com/golang/protobuf v1.5.2 // indirect
|
||||
github.com/olivere/elastic/v7 v7.0.24
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
|
||||
golang.org/x/sys v0.0.0-20210317225723-c4fcb01b228e // indirect
|
||||
google.golang.org/grpc v1.36.0
|
||||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 // indirect
|
||||
google.golang.org/protobuf v1.26.0
|
||||
)
|
||||
|
|
31
go.sum
31
go.sum
|
@ -1,10 +1,22 @@
|
|||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
|
||||
github.com/aws/aws-sdk-go v1.38.3/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro=
|
||||
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
|
||||
github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
|
||||
github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg=
|
||||
github.com/btcsuite/btcutil v1.0.2 h1:9iZ1Terx9fMIOtq1VrwdqfsATL9MC2l8ZrUY6YZ2uts=
|
||||
github.com/btcsuite/btcutil v1.0.2/go.mod h1:j9HUFwoQRsZL3V4n+qG+CUnEGHOarIxfC3Le2Yhbcts=
|
||||
github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
|
||||
github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY=
|
||||
github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc=
|
||||
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
|
||||
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
|
||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
|
||||
github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
|
||||
|
@ -13,6 +25,7 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.m
|
|||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=
|
||||
github.com/fortytw2/leaktest v1.3.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
|
@ -28,8 +41,6 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD
|
|||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.1 h1:jAbXjIeW2ZSW2AwFxlGTDoc2CjI2XujLkV3ArsZFCvc=
|
||||
github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx4u74HPM=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
|
@ -41,14 +52,21 @@ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
|||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
|
||||
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
|
||||
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
|
||||
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
|
||||
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
|
||||
github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ=
|
||||
github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4=
|
||||
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
|
||||
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
|
||||
github.com/olivere/elastic/v7 v7.0.24 h1:9ZcCQP3Pvgese7TaypYiVAL49sCEphyIwkVxtRf8jb8=
|
||||
github.com/olivere/elastic/v7 v7.0.24/go.mod h1:OuWmD2DiuYhddWegBKPWQuelVKBLrW0fa/VUYgxuGTY=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
|
@ -62,7 +80,9 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
|
|||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E=
|
||||
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200115085410-6d4e4cb37c7d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
|
@ -70,6 +90,7 @@ golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvx
|
|||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
|
@ -81,6 +102,7 @@ golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJ
|
|||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
|
@ -111,8 +133,6 @@ google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8
|
|||
google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc=
|
||||
google.golang.org/grpc v1.36.0 h1:o1bcQ6imQMIOpdrO3SWf2z5RV72WbDwdXuK0MDlc8As=
|
||||
google.golang.org/grpc v1.36.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
|
||||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 h1:M1YKkFIboKNieVO5DLUEVzQfGwJD30Nv2jfUgzb5UcE=
|
||||
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
|
@ -126,6 +146,9 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
|
|||
google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
37
main.go
37
main.go
|
@ -2,11 +2,11 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
pb "github.com/lbryio/hub/protobuf/go"
|
||||
|
@ -19,6 +19,32 @@ const (
|
|||
port = ":50051"
|
||||
)
|
||||
|
||||
func parseArgs(searchRequest *pb.SearchRequest) {
|
||||
query:= flag.String("query", "", "query string")
|
||||
claimType := flag.String("claimType", "", "claim type")
|
||||
id := flag.String("id", "", "_id")
|
||||
author := flag.String("author", "", "author")
|
||||
title := flag.String("title", "", "title")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if *query != "" {
|
||||
searchRequest.Query = *query
|
||||
}
|
||||
if *claimType != "" {
|
||||
searchRequest.ClaimType = []string{*claimType}
|
||||
}
|
||||
if *id != "" {
|
||||
searchRequest.XId = [][]byte{[]byte(*id)}
|
||||
}
|
||||
if *author != "" {
|
||||
searchRequest.Author = []string{*author}
|
||||
}
|
||||
if *title != "" {
|
||||
searchRequest.Title = []string{*title}
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
if len(os.Args) == 2 && os.Args[1] == "serve" {
|
||||
l, err := net.Listen("tcp", port)
|
||||
|
@ -44,6 +70,7 @@ func main() {
|
|||
|
||||
c := pb.NewHubClient(conn)
|
||||
|
||||
/*
|
||||
var query string
|
||||
if len(os.Args) > 1 {
|
||||
query = strings.Join(os.Args[1:], " ")
|
||||
|
@ -51,13 +78,15 @@ func main() {
|
|||
log.Printf("error: no search query provided\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
*/
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
|
||||
//searchRequest := &pb.SearchRequest{Query: query}
|
||||
//searchRequest := &pb.SearchRequest{XId: [][]byte{[]byte(query)}}
|
||||
searchRequest := &pb.SearchRequest{ClaimType: []string{query}}
|
||||
searchRequest := &pb.SearchRequest{}
|
||||
|
||||
parseArgs(searchRequest)
|
||||
|
||||
r, err := c.Search(ctx, searchRequest)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
@ -8,6 +8,18 @@ service Hub {
|
|||
rpc Search (SearchRequest) returns (SearchReply) {}
|
||||
}
|
||||
|
||||
message RangeQuery {
|
||||
enum Op {
|
||||
EQ = 0;
|
||||
LTE = 1;
|
||||
GTE = 2;
|
||||
LT = 3;
|
||||
GT = 4;
|
||||
}
|
||||
Op op = 1;
|
||||
repeated string value = 2;
|
||||
}
|
||||
|
||||
message SearchRequest {
|
||||
string query = 1;
|
||||
string name = 2;
|
||||
|
@ -17,52 +29,52 @@ message SearchRequest {
|
|||
int32 offset = 6;
|
||||
bool is_controlling = 7;
|
||||
string last_take_over_height = 20;
|
||||
string claim_id = 21;
|
||||
string claim_name = 22;
|
||||
string normalized = 23;
|
||||
string tx_position = 24;
|
||||
string amount = 25;
|
||||
string timestamp = 26;
|
||||
string creation_timestamp = 27;
|
||||
string height = 28;
|
||||
string creation_height = 29;
|
||||
string activation_height = 30;
|
||||
string expiration_height = 31;
|
||||
string release_time = 32;
|
||||
string short_url = 33;
|
||||
string canonical_url = 34;
|
||||
string title = 35;
|
||||
string author = 36;
|
||||
string description = 37;
|
||||
repeated string claim_id = 21;
|
||||
repeated string claim_name = 22;
|
||||
repeated string normalized = 23;
|
||||
RangeQuery tx_position = 24;
|
||||
RangeQuery amount = 25;
|
||||
RangeQuery timestamp = 26;
|
||||
RangeQuery creation_timestamp = 27;
|
||||
RangeQuery height = 28;
|
||||
RangeQuery creation_height = 29;
|
||||
RangeQuery activation_height = 30;
|
||||
RangeQuery expiration_height = 31;
|
||||
RangeQuery release_time = 32;
|
||||
repeated string short_url = 33;
|
||||
repeated string canonical_url = 34;
|
||||
repeated string title = 35;
|
||||
repeated string author = 36;
|
||||
repeated string description = 37;
|
||||
repeated string claim_type = 38;
|
||||
string reposted = 39;
|
||||
string stream_type = 40;
|
||||
string media_type = 41;
|
||||
string fee_amount = 42;
|
||||
string fee_currency = 43;
|
||||
string duration = 44;
|
||||
RangeQuery reposted = 39;
|
||||
repeated string stream_type = 40;
|
||||
repeated string media_type = 41;
|
||||
RangeQuery fee_amount = 42;
|
||||
repeated string fee_currency = 43;
|
||||
RangeQuery duration = 44;
|
||||
string reposted_claim_hash = 45;
|
||||
string censor_type = 46;
|
||||
RangeQuery censor_type = 46;
|
||||
string claims_in_channel = 47;
|
||||
string channel_join = 48;
|
||||
RangeQuery channel_join = 48;
|
||||
string signature_valid = 49;
|
||||
string effective_amount = 50;
|
||||
string support_amount = 51;
|
||||
string trending_group = 52;
|
||||
string trending_mixed = 53;
|
||||
string trending_local = 54;
|
||||
string trending_global = 55;
|
||||
string channel_id = 56;
|
||||
string tx_id = 57;
|
||||
RangeQuery effective_amount = 50;
|
||||
RangeQuery support_amount = 51;
|
||||
RangeQuery trending_group = 52;
|
||||
RangeQuery trending_mixed = 53;
|
||||
RangeQuery trending_local = 54;
|
||||
RangeQuery trending_global = 55;
|
||||
repeated string channel_id = 56;
|
||||
repeated string tx_id = 57;
|
||||
string tx_nout = 58;
|
||||
string signature = 59;
|
||||
string signature_digest = 60;
|
||||
string public_key_bytes = 61;
|
||||
string public_key_hash = 62;
|
||||
repeated string signature = 59;
|
||||
repeated string signature_digest = 60;
|
||||
repeated string public_key_bytes = 61;
|
||||
repeated string public_key_hash = 62;
|
||||
string public_key_id = 63;
|
||||
repeated bytes _id = 64;
|
||||
string tags = 65;
|
||||
string reposted_claim_id = 66;
|
||||
repeated string tags = 65;
|
||||
repeated string reposted_claim_id = 66;
|
||||
}
|
||||
|
||||
message SearchReply {
|
||||
|
|
File diff suppressed because it is too large
Load diff
106
server/search.go
106
server/search.go
|
@ -7,6 +7,7 @@ import (
|
|||
"log"
|
||||
"reflect"
|
||||
|
||||
"github.com/btcsuite/btcutil/base58"
|
||||
"github.com/olivere/elastic/v7"
|
||||
)
|
||||
|
||||
|
@ -15,12 +16,52 @@ type record struct {
|
|||
Nout uint32 `json:"tx_nout"`
|
||||
}
|
||||
|
||||
func reverseBytes(s []byte) {
|
||||
func ReverseBytes(s []byte) {
|
||||
for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
|
||||
s[i], s[j] = s[j], s[i]
|
||||
}
|
||||
}
|
||||
|
||||
func StrArrToInterface(arr []string) []interface{} {
|
||||
searchVals := make([]interface{}, len(arr))
|
||||
for i := 0; i < len(arr); i++ {
|
||||
searchVals[i] = arr[i]
|
||||
}
|
||||
return searchVals
|
||||
}
|
||||
|
||||
func AddTermsQuery(arr []string, name string, q *elastic.BoolQuery) *elastic.BoolQuery {
|
||||
if len(arr) > 0 {
|
||||
searchVals := StrArrToInterface(arr)
|
||||
return q.Must(elastic.NewTermsQuery(name, searchVals...))
|
||||
}
|
||||
return q
|
||||
}
|
||||
|
||||
func AddRangeQuery(rq *pb.RangeQuery, name string, q *elastic.BoolQuery) *elastic.BoolQuery {
|
||||
if rq == nil {
|
||||
return q
|
||||
}
|
||||
|
||||
if len(rq.Value) > 1 {
|
||||
if rq.Op != pb.RangeQuery_EQ {
|
||||
return q
|
||||
}
|
||||
return AddTermsQuery(rq.Value, name, q)
|
||||
}
|
||||
if rq.Op == pb.RangeQuery_EQ {
|
||||
return AddTermsQuery(rq.Value, name, q)
|
||||
} else if rq.Op == pb.RangeQuery_LT {
|
||||
return q.Must(elastic.NewRangeQuery(name).Lt(rq.Value))
|
||||
} else if rq.Op == pb.RangeQuery_LTE {
|
||||
return q.Must(elastic.NewRangeQuery(name).Lte(rq.Value))
|
||||
} else if rq.Op == pb.RangeQuery_GT {
|
||||
return q.Must(elastic.NewRangeQuery(name).Gt(rq.Value))
|
||||
} else { // pb.RangeQuery_GTE
|
||||
return q.Must(elastic.NewRangeQuery(name).Gte(rq.Value))
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Server) Search(ctx context.Context, in *pb.SearchRequest) (*pb.SearchReply, error) {
|
||||
// TODO: reuse elastic client across requests
|
||||
client, err := elastic.NewClient(elastic.SetSniff(false))
|
||||
|
@ -64,12 +105,71 @@ func (s *Server) Search(ctx context.Context, in *pb.SearchRequest) (*pb.SearchRe
|
|||
if len(in.XId) > 0 {
|
||||
searchVals := make([]interface{}, len(in.XId))
|
||||
for i := 0; i < len(in.XId); i++ {
|
||||
reverseBytes(in.XId[i])
|
||||
ReverseBytes(in.XId[i])
|
||||
searchVals[i] = hex.Dump(in.XId[i])
|
||||
}
|
||||
q = q.Must(elastic.NewTermsQuery("_id", searchVals...))
|
||||
if len(in.XId) == 1 && len(in.XId[0]) < 20 {
|
||||
q = q.Must(elastic.NewPrefixQuery("_id", string(in.XId[0])))
|
||||
} else {
|
||||
q = q.Must(elastic.NewTermsQuery("_id", searchVals...))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if len(in.ClaimId) > 0 {
|
||||
searchVals := StrArrToInterface(in.ClaimId)
|
||||
if len(in.ClaimId) == 1 && len(in.ClaimId[0]) < 20 {
|
||||
q = q.Must(elastic.NewPrefixQuery("claim_id.keyword", in.ClaimId[0]))
|
||||
} else {
|
||||
q = q.Must(elastic.NewTermsQuery("claim_id.keyword", searchVals...))
|
||||
}
|
||||
}
|
||||
|
||||
if in.PublicKeyId != "" {
|
||||
value := hex.Dump(base58.Decode(in.PublicKeyId)[1:21])
|
||||
q = q.Must(elastic.NewTermQuery("public_key_hash.keyword", value))
|
||||
}
|
||||
|
||||
q = AddTermsQuery(in.PublicKeyHash, "public_key_hash.keyword", q)
|
||||
q = AddTermsQuery(in.Author, "author.keyword", q)
|
||||
q = AddTermsQuery(in.Title, "title.keyword", q)
|
||||
q = AddTermsQuery(in.CanonicalUrl, "canonical_url.keyword", q)
|
||||
q = AddTermsQuery(in.ChannelId, "channel_id.keyword", q)
|
||||
q = AddTermsQuery(in.ClaimName, "claim_name.keyword", q)
|
||||
q = AddTermsQuery(in.Description, "description.keyword", q)
|
||||
q = AddTermsQuery(in.MediaType, "media_type.keyword", q)
|
||||
q = AddTermsQuery(in.Normalized, "normalized.keyword", q)
|
||||
q = AddTermsQuery(in.PublicKeyBytes, "public_key_bytes.keyword", q)
|
||||
q = AddTermsQuery(in.ShortUrl, "short_url.keyword", q)
|
||||
q = AddTermsQuery(in.Signature, "signature.keyword", q)
|
||||
q = AddTermsQuery(in.SignatureDigest, "signature_digest.keyword", q)
|
||||
q = AddTermsQuery(in.StreamType, "stream_type.keyword", q)
|
||||
q = AddTermsQuery(in.TxId, "tx_id.keyword", q)
|
||||
q = AddTermsQuery(in.FeeCurrency, "fee_currency.keyword", q)
|
||||
q = AddTermsQuery(in.RepostedClaimId, "reposted_claim_id.keyword", q)
|
||||
q = AddTermsQuery(in.Tags, "tags.keyword", q)
|
||||
|
||||
q = AddRangeQuery(in.TxPosition, "tx_position", q)
|
||||
q = AddRangeQuery(in.Amount, "amount", q)
|
||||
q = AddRangeQuery(in.Timestamp, "timestamp", q)
|
||||
q = AddRangeQuery(in.CreationTimestamp, "creation_timestamp", q)
|
||||
q = AddRangeQuery(in.Height, "height", q)
|
||||
q = AddRangeQuery(in.CreationHeight, "creation_height", q)
|
||||
q = AddRangeQuery(in.ActivationHeight, "activation_height", q)
|
||||
q = AddRangeQuery(in.ExpirationHeight, "expiration_height", q)
|
||||
q = AddRangeQuery(in.ReleaseTime, "release_time", q)
|
||||
q = AddRangeQuery(in.Reposted, "reposted", q)
|
||||
q = AddRangeQuery(in.FeeAmount, "fee_amount", q)
|
||||
q = AddRangeQuery(in.Duration, "duration", q)
|
||||
q = AddRangeQuery(in.CensorType, "censor_type", q)
|
||||
q = AddRangeQuery(in.ChannelJoin, "channel_join", q)
|
||||
q = AddRangeQuery(in.EffectiveAmount, "effective_amount", q)
|
||||
q = AddRangeQuery(in.SupportAmount, "support_amount", q)
|
||||
q = AddRangeQuery(in.TrendingGroup, "trending_group", q)
|
||||
q = AddRangeQuery(in.TrendingMixed, "trending_mixed", q)
|
||||
q = AddRangeQuery(in.TrendingLocal, "trending_local", q)
|
||||
q = AddRangeQuery(in.TrendingGlobal, "trending_global", q)
|
||||
|
||||
if in.Query != "" {
|
||||
textQuery := elastic.NewSimpleQueryStringQuery(in.Query).
|
||||
FieldWithBoost("claim_name", 4).
|
||||
|
|
Loading…
Reference in a new issue