Documentation ¶
Index ¶
- Constants
- Variables
- func RegisterIndexServiceServer(s *grpc.Server, srv IndexServiceServer)
- type AffectedCount
- func (*AffectedCount) Descriptor() ([]byte, []int)
- func (m *AffectedCount) GetCount() uint32
- func (m *AffectedCount) Marshal() (dAtA []byte, err error)
- func (m *AffectedCount) MarshalTo(dAtA []byte) (int, error)
- func (m *AffectedCount) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*AffectedCount) ProtoMessage()
- func (m *AffectedCount) Reset()
- func (m *AffectedCount) Size() (n int)
- func (m *AffectedCount) String() string
- func (m *AffectedCount) Unmarshal(dAtA []byte) error
- func (m *AffectedCount) XXX_DiscardUnknown()
- func (m *AffectedCount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *AffectedCount) XXX_Merge(src proto.Message)
- func (m *AffectedCount) XXX_Size() int
- func (m *AffectedCount) XXX_Unmarshal(b []byte) error
- type CountRequest
- func (*CountRequest) Descriptor() ([]byte, []int)
- func (m *CountRequest) Marshal() (dAtA []byte, err error)
- func (m *CountRequest) MarshalTo(dAtA []byte) (int, error)
- func (m *CountRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*CountRequest) ProtoMessage()
- func (m *CountRequest) Reset()
- func (m *CountRequest) Size() (n int)
- func (m *CountRequest) String() string
- func (m *CountRequest) Unmarshal(dAtA []byte) error
- func (m *CountRequest) XXX_DiscardUnknown()
- func (m *CountRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *CountRequest) XXX_Merge(src proto.Message)
- func (m *CountRequest) XXX_Size() int
- func (m *CountRequest) XXX_Unmarshal(b []byte) error
- type DocId
- func (*DocId) Descriptor() ([]byte, []int)
- func (m *DocId) GetDocId() string
- func (m *DocId) Marshal() (dAtA []byte, err error)
- func (m *DocId) MarshalTo(dAtA []byte) (int, error)
- func (m *DocId) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*DocId) ProtoMessage()
- func (m *DocId) Reset()
- func (m *DocId) Size() (n int)
- func (m *DocId) String() string
- func (m *DocId) Unmarshal(dAtA []byte) error
- func (m *DocId) XXX_DiscardUnknown()
- func (m *DocId) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *DocId) XXX_Merge(src proto.Message)
- func (m *DocId) XXX_Size() int
- func (m *DocId) XXX_Unmarshal(b []byte) error
- type IIndexer
- type IServiceHub
- type IndexServiceClient
- type IndexServiceServer
- type IndexServiceWorker
- func (service *IndexServiceWorker) AddDoc(ctx context.Context, doc *types.Document) (*AffectedCount, error)
- func (service *IndexServiceWorker) Close()
- func (service *IndexServiceWorker) Count(ctx context.Context, request *CountRequest) (*AffectedCount, error)
- func (service *IndexServiceWorker) DeleteDoc(ctx context.Context, docId *DocId) (*AffectedCount, error)
- func (service *IndexServiceWorker) Init(workerIndex ...int) error
- func (service *IndexServiceWorker) Regist(etcdEndpoint []string, servicePort, heartRate int) error
- func (service *IndexServiceWorker) Search(ctx context.Context, request *SearchRequest) (*SearchResponse, error)
- type Indexer
- func (indexer *Indexer) AddDoc(doc types.Document) (int, error)
- func (indexer *Indexer) Close() error
- func (Indexer *Indexer) Count() int
- func (indexer *Indexer) DeleteDoc(docId string) int
- func (indexer *Indexer) Init(DocNumEstimate int, dbtype int, Data string) error
- func (indexer *Indexer) LoadFromIndexFile() int
- func (indexer *Indexer) Search(querys *types.TermQuery, onFlag, offFlag uint64, orFlags []uint64) []*types.Document
- type LoadBalancer
- type RandomSelect
- type RoundRobin
- type SearchRequest
- func (*SearchRequest) Descriptor() ([]byte, []int)
- func (m *SearchRequest) GetOffFlag() uint64
- func (m *SearchRequest) GetOnFlag() uint64
- func (m *SearchRequest) GetOrFlags() []uint64
- func (m *SearchRequest) GetQuery() *types.TermQuery
- func (m *SearchRequest) Marshal() (dAtA []byte, err error)
- func (m *SearchRequest) MarshalTo(dAtA []byte) (int, error)
- func (m *SearchRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*SearchRequest) ProtoMessage()
- func (m *SearchRequest) Reset()
- func (m *SearchRequest) Size() (n int)
- func (m *SearchRequest) String() string
- func (m *SearchRequest) Unmarshal(dAtA []byte) error
- func (m *SearchRequest) XXX_DiscardUnknown()
- func (m *SearchRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *SearchRequest) XXX_Merge(src proto.Message)
- func (m *SearchRequest) XXX_Size() int
- func (m *SearchRequest) XXX_Unmarshal(b []byte) error
- type SearchResponse
- func (*SearchResponse) Descriptor() ([]byte, []int)
- func (m *SearchResponse) GetDocuments() []*types.Document
- func (m *SearchResponse) Marshal() (dAtA []byte, err error)
- func (m *SearchResponse) MarshalTo(dAtA []byte) (int, error)
- func (m *SearchResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*SearchResponse) ProtoMessage()
- func (m *SearchResponse) Reset()
- func (m *SearchResponse) Size() (n int)
- func (m *SearchResponse) String() string
- func (m *SearchResponse) Unmarshal(dAtA []byte) error
- func (m *SearchResponse) XXX_DiscardUnknown()
- func (m *SearchResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *SearchResponse) XXX_Merge(src proto.Message)
- func (m *SearchResponse) XXX_Size() int
- func (m *SearchResponse) XXX_Unmarshal(b []byte) error
- type Sentinel
- func (sentinel *Sentinel) AddDoc(doc types.Document) (int, error)
- func (sentinel *Sentinel) Close() (err error)
- func (sentinel *Sentinel) Count() int
- func (sentinel *Sentinel) DeleteDoc(docId string) int
- func (sentinal *Sentinel) GetGrpcConn(endpoint string) *grpc.ClientConn
- func (sentinel *Sentinel) Search(querys *types.TermQuery, onFlag, offFlag uint64, orFlags []uint64) []*types.Document
- type ServiceHub
- func (hub *ServiceHub) Close()
- func (hub *ServiceHub) GetServiceEndpoint(service string) string
- func (hub *ServiceHub) GetServiceEndpoints(service string) []string
- func (hub *ServiceHub) Regist(service, endpoint string, leaseID etcdv3.LeaseID) (etcdv3.LeaseID, error)
- func (hub *ServiceHub) UnRegist(service, endpoint string) error
- type ServiceHubProxy
- type UnimplementedIndexServiceServer
- func (*UnimplementedIndexServiceServer) AddDoc(ctx context.Context, req *types.Document) (*AffectedCount, error)
- func (*UnimplementedIndexServiceServer) Count(ctx context.Context, req *CountRequest) (*AffectedCount, error)
- func (*UnimplementedIndexServiceServer) DeleteDoc(ctx context.Context, req *DocId) (*AffectedCount, error)
- func (*UnimplementedIndexServiceServer) Search(ctx context.Context, req *SearchRequest) (*SearchResponse, error)
Constants ¶
View Source
const (
INDEX_SERVICE = "index_service"
)
View Source
const (
SERVICE_ROOT_PATH = "/github.com/WlayRay/ElectricSearch/index" // etcd key的前缀
)
Variables ¶
Functions ¶
func RegisterIndexServiceServer ¶
func RegisterIndexServiceServer(s *grpc.Server, srv IndexServiceServer)
Types ¶
type AffectedCount ¶
type AffectedCount struct {
Count uint32 `protobuf:"varint,1,opt,name=Count,proto3" json:"Count,omitempty"`
}
func (*AffectedCount) Descriptor ¶
func (*AffectedCount) Descriptor() ([]byte, []int)
func (*AffectedCount) GetCount ¶
func (m *AffectedCount) GetCount() uint32
func (*AffectedCount) Marshal ¶
func (m *AffectedCount) Marshal() (dAtA []byte, err error)
func (*AffectedCount) MarshalToSizedBuffer ¶
func (m *AffectedCount) MarshalToSizedBuffer(dAtA []byte) (int, error)
func (*AffectedCount) ProtoMessage ¶
func (*AffectedCount) ProtoMessage()
func (*AffectedCount) Reset ¶
func (m *AffectedCount) Reset()
func (*AffectedCount) Size ¶
func (m *AffectedCount) Size() (n int)
func (*AffectedCount) String ¶
func (m *AffectedCount) String() string
func (*AffectedCount) Unmarshal ¶
func (m *AffectedCount) Unmarshal(dAtA []byte) error
func (*AffectedCount) XXX_DiscardUnknown ¶
func (m *AffectedCount) XXX_DiscardUnknown()
func (*AffectedCount) XXX_Marshal ¶
func (m *AffectedCount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*AffectedCount) XXX_Merge ¶
func (m *AffectedCount) XXX_Merge(src proto.Message)
func (*AffectedCount) XXX_Size ¶
func (m *AffectedCount) XXX_Size() int
func (*AffectedCount) XXX_Unmarshal ¶
func (m *AffectedCount) XXX_Unmarshal(b []byte) error
type CountRequest ¶
type CountRequest struct { }
func (*CountRequest) Descriptor ¶
func (*CountRequest) Descriptor() ([]byte, []int)
func (*CountRequest) Marshal ¶
func (m *CountRequest) Marshal() (dAtA []byte, err error)
func (*CountRequest) MarshalToSizedBuffer ¶
func (m *CountRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)
func (*CountRequest) ProtoMessage ¶
func (*CountRequest) ProtoMessage()
func (*CountRequest) Reset ¶
func (m *CountRequest) Reset()
func (*CountRequest) Size ¶
func (m *CountRequest) Size() (n int)
func (*CountRequest) String ¶
func (m *CountRequest) String() string
func (*CountRequest) Unmarshal ¶
func (m *CountRequest) Unmarshal(dAtA []byte) error
func (*CountRequest) XXX_DiscardUnknown ¶
func (m *CountRequest) XXX_DiscardUnknown()
func (*CountRequest) XXX_Marshal ¶
func (m *CountRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*CountRequest) XXX_Merge ¶
func (m *CountRequest) XXX_Merge(src proto.Message)
func (*CountRequest) XXX_Size ¶
func (m *CountRequest) XXX_Size() int
func (*CountRequest) XXX_Unmarshal ¶
func (m *CountRequest) XXX_Unmarshal(b []byte) error
type DocId ¶
type DocId struct {
DocId string `protobuf:"bytes,1,opt,name=DocId,proto3" json:"DocId,omitempty"`
}
func (*DocId) Descriptor ¶
func (*DocId) ProtoMessage ¶
func (*DocId) ProtoMessage()
func (*DocId) XXX_DiscardUnknown ¶
func (m *DocId) XXX_DiscardUnknown()
func (*DocId) XXX_Marshal ¶
func (*DocId) XXX_Unmarshal ¶
type IServiceHub ¶
type IServiceHub interface { Regist(service, endpoint string, leaseID etcdv3.LeaseID) (etcdv3.LeaseID, error) // 注册服务 UnRegist(service, endpoint string) error // 注销服务 GetServiceEndpoints(service string) []string // 服务发现 GetServiceEndpoint(service string) string // 根据负载均衡获取一台服务的endpoint Close() // 关闭etcd连接 }
type IndexServiceClient ¶
type IndexServiceClient interface { DeleteDoc(ctx context.Context, in *DocId, opts ...grpc.CallOption) (*AffectedCount, error) AddDoc(ctx context.Context, in *types.Document, opts ...grpc.CallOption) (*AffectedCount, error) Search(ctx context.Context, in *SearchRequest, opts ...grpc.CallOption) (*SearchResponse, error) Count(ctx context.Context, in *CountRequest, opts ...grpc.CallOption) (*AffectedCount, error) }
IndexServiceClient is the client API for IndexService service.
For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
func NewIndexServiceClient ¶
func NewIndexServiceClient(cc *grpc.ClientConn) IndexServiceClient
type IndexServiceServer ¶
type IndexServiceServer interface { DeleteDoc(context.Context, *DocId) (*AffectedCount, error) AddDoc(context.Context, *types.Document) (*AffectedCount, error) Search(context.Context, *SearchRequest) (*SearchResponse, error) Count(context.Context, *CountRequest) (*AffectedCount, error) }
IndexServiceServer is the server API for IndexService service.
type IndexServiceWorker ¶
type IndexServiceWorker struct { Indexer *Indexer // contains filtered or unexported fields }
IndexServiceWorker是一个grpc服务,用于索引文档
func (*IndexServiceWorker) AddDoc ¶
func (service *IndexServiceWorker) AddDoc(ctx context.Context, doc *types.Document) (*AffectedCount, error)
向索引中添加文档,如果文档已存在则会覆盖
func (*IndexServiceWorker) Close ¶
func (service *IndexServiceWorker) Close()
func (*IndexServiceWorker) Count ¶
func (service *IndexServiceWorker) Count(ctx context.Context, request *CountRequest) (*AffectedCount, error)
func (*IndexServiceWorker) DeleteDoc ¶
func (service *IndexServiceWorker) DeleteDoc(ctx context.Context, docId *DocId) (*AffectedCount, error)
从索引上删除文档
func (*IndexServiceWorker) Init ¶
func (service *IndexServiceWorker) Init(workerIndex ...int) error
func (*IndexServiceWorker) Regist ¶
func (service *IndexServiceWorker) Regist(etcdEndpoint []string, servicePort, heartRate int) error
func (*IndexServiceWorker) Search ¶
func (service *IndexServiceWorker) Search(ctx context.Context, request *SearchRequest) (*SearchResponse, error)
检索,返回文档列表
type Indexer ¶
type Indexer struct {
// contains filtered or unexported fields
}
外观模式,把正排和倒排索引2个子系统封装在一起
func (*Indexer) LoadFromIndexFile ¶
倒排索引存储在内存中,系统重启时从正派索引里加载数据
type LoadBalancer ¶
type RandomSelect ¶
type RandomSelect struct{}
func (*RandomSelect) Take ¶
func (rs *RandomSelect) Take(endPoints []string) string
type RoundRobin ¶
type RoundRobin struct {
// contains filtered or unexported fields
}
func (*RoundRobin) Take ¶
func (rr *RoundRobin) Take(endPoints []string) string
type SearchRequest ¶
type SearchRequest struct { Query *types.TermQuery `protobuf:"bytes,1,opt,name=Query,proto3" json:"Query,omitempty"` OnFlag uint64 `protobuf:"varint,2,opt,name=OnFlag,proto3" json:"OnFlag,omitempty"` OffFlag uint64 `protobuf:"varint,3,opt,name=OffFlag,proto3" json:"OffFlag,omitempty"` OrFlags []uint64 `protobuf:"varint,4,rep,packed,name=OrFlags,proto3" json:"OrFlags,omitempty"` }
func (*SearchRequest) Descriptor ¶
func (*SearchRequest) Descriptor() ([]byte, []int)
func (*SearchRequest) GetOffFlag ¶
func (m *SearchRequest) GetOffFlag() uint64
func (*SearchRequest) GetOnFlag ¶
func (m *SearchRequest) GetOnFlag() uint64
func (*SearchRequest) GetOrFlags ¶
func (m *SearchRequest) GetOrFlags() []uint64
func (*SearchRequest) GetQuery ¶
func (m *SearchRequest) GetQuery() *types.TermQuery
func (*SearchRequest) Marshal ¶
func (m *SearchRequest) Marshal() (dAtA []byte, err error)
func (*SearchRequest) MarshalToSizedBuffer ¶
func (m *SearchRequest) MarshalToSizedBuffer(dAtA []byte) (int, error)
func (*SearchRequest) ProtoMessage ¶
func (*SearchRequest) ProtoMessage()
func (*SearchRequest) Reset ¶
func (m *SearchRequest) Reset()
func (*SearchRequest) Size ¶
func (m *SearchRequest) Size() (n int)
func (*SearchRequest) String ¶
func (m *SearchRequest) String() string
func (*SearchRequest) Unmarshal ¶
func (m *SearchRequest) Unmarshal(dAtA []byte) error
func (*SearchRequest) XXX_DiscardUnknown ¶
func (m *SearchRequest) XXX_DiscardUnknown()
func (*SearchRequest) XXX_Marshal ¶
func (m *SearchRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*SearchRequest) XXX_Merge ¶
func (m *SearchRequest) XXX_Merge(src proto.Message)
func (*SearchRequest) XXX_Size ¶
func (m *SearchRequest) XXX_Size() int
func (*SearchRequest) XXX_Unmarshal ¶
func (m *SearchRequest) XXX_Unmarshal(b []byte) error
type SearchResponse ¶
type SearchResponse struct {
Documents []*types.Document `protobuf:"bytes,1,rep,name=Documents,proto3" json:"Documents,omitempty"`
}
func (*SearchResponse) Descriptor ¶
func (*SearchResponse) Descriptor() ([]byte, []int)
func (*SearchResponse) GetDocuments ¶
func (m *SearchResponse) GetDocuments() []*types.Document
func (*SearchResponse) Marshal ¶
func (m *SearchResponse) Marshal() (dAtA []byte, err error)
func (*SearchResponse) MarshalToSizedBuffer ¶
func (m *SearchResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)
func (*SearchResponse) ProtoMessage ¶
func (*SearchResponse) ProtoMessage()
func (*SearchResponse) Reset ¶
func (m *SearchResponse) Reset()
func (*SearchResponse) Size ¶
func (m *SearchResponse) Size() (n int)
func (*SearchResponse) String ¶
func (m *SearchResponse) String() string
func (*SearchResponse) Unmarshal ¶
func (m *SearchResponse) Unmarshal(dAtA []byte) error
func (*SearchResponse) XXX_DiscardUnknown ¶
func (m *SearchResponse) XXX_DiscardUnknown()
func (*SearchResponse) XXX_Marshal ¶
func (m *SearchResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*SearchResponse) XXX_Merge ¶
func (m *SearchResponse) XXX_Merge(src proto.Message)
func (*SearchResponse) XXX_Size ¶
func (m *SearchResponse) XXX_Size() int
func (*SearchResponse) XXX_Unmarshal ¶
func (m *SearchResponse) XXX_Unmarshal(b []byte) error
type Sentinel ¶
type Sentinel struct {
// contains filtered or unexported fields
}
func NewSentinel ¶
func (*Sentinel) GetGrpcConn ¶
func (sentinal *Sentinel) GetGrpcConn(endpoint string) *grpc.ClientConn
type ServiceHub ¶
type ServiceHub struct {
// contains filtered or unexported fields
}
服务注册中心
func GetServiceHub ¶
func GetServiceHub(etcdEndpoints []string, heartRate int64) *ServiceHub
func (*ServiceHub) GetServiceEndpoint ¶
func (hub *ServiceHub) GetServiceEndpoint(service string) string
根据负载均衡,从众多endpoint中选择一个
func (*ServiceHub) GetServiceEndpoints ¶
func (hub *ServiceHub) GetServiceEndpoints(service string) []string
服务发现,client每次进行RPC调用之前都查询etcd,获取server集合,然后采用负载均衡算法选择一台server。或者也可以把负载均衡的功能放到注册中心,即放到getServiceEndpoints函数里,让它只返回一个server
type ServiceHubProxy ¶
type ServiceHubProxy struct { *ServiceHub // ServiceHubProxy拥有ServiceHub的所有方法(匿名成员变量) // contains filtered or unexported fields }
代理模式,对ServiceHub做一层代理,提供缓存和限流保护
func GetServiceHubProxy ¶
func GetServiceHubProxy(etcdEndpoints []string, heartRate int64, qps int) *ServiceHubProxy
func (*ServiceHubProxy) GetServiceEndpoints ¶
func (proxy *ServiceHubProxy) GetServiceEndpoints(service string) []string
type UnimplementedIndexServiceServer ¶
type UnimplementedIndexServiceServer struct { }
UnimplementedIndexServiceServer can be embedded to have forward compatible implementations.
func (*UnimplementedIndexServiceServer) AddDoc ¶
func (*UnimplementedIndexServiceServer) AddDoc(ctx context.Context, req *types.Document) (*AffectedCount, error)
func (*UnimplementedIndexServiceServer) Count ¶
func (*UnimplementedIndexServiceServer) Count(ctx context.Context, req *CountRequest) (*AffectedCount, error)
func (*UnimplementedIndexServiceServer) DeleteDoc ¶
func (*UnimplementedIndexServiceServer) DeleteDoc(ctx context.Context, req *DocId) (*AffectedCount, error)
func (*UnimplementedIndexServiceServer) Search ¶
func (*UnimplementedIndexServiceServer) Search(ctx context.Context, req *SearchRequest) (*SearchResponse, error)
Click to show internal directories.
Click to hide internal directories.