Documentation ¶
Overview ¶
Package backend contains translation code from the immediate representation into a concrete query usable by a search engine.
Implementing a backend requires implementing both the BooleanQuery interface and the Compiler interface.
Package backend contains translation code from the immediate representation into a concrete query usable by a search engine.
This file contains a decent reference implementation for compiling and transforming the IR into and ElasticSearch query.
Index ¶
- type BooleanQuery
- type CommonQueryRepresentationBackend
- type CommonQueryRepresentationQuery
- type Compiler
- type ElasticsearchBooleanQuery
- type ElasticsearchCompiler
- type ElasticsearchQuery
- type IrBackend
- type IrQuery
- type MedlineBackend
- type MedlineQuery
- type PubmedBackend
- type PubmedQuery
- type TerrierBackend
- type TerrierQuery
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BooleanQuery ¶
type BooleanQuery interface { Representation() (interface{}, error) String() (string, error) StringPretty() (string, error) }
BooleanQuery is an interface for handling the queries in a query language. The most important method is String(), which will output an appropriate query suitable for a search engine.
type CommonQueryRepresentationBackend ¶
type CommonQueryRepresentationBackend struct{}
CommonQueryRepresentationBackend is the backend for compiling transmute ir into CQR.
func NewCQRBackend ¶
func NewCQRBackend() CommonQueryRepresentationBackend
NewCQRBackend returns a new CQR backend.
func (CommonQueryRepresentationBackend) Compile ¶
func (b CommonQueryRepresentationBackend) Compile(q ir.BooleanQuery) (BooleanQuery, error)
Compile transforms the transmute ir into CQR. The CQR is slightly different to the transmute ir, in that the depth of the children is different. Take note of how the children of a transmute ir differs from the children of CQR.
type CommonQueryRepresentationQuery ¶
type CommonQueryRepresentationQuery struct {
// contains filtered or unexported fields
}
CommonQueryRepresentationQuery is the transmute wrapper for CQR.
func NewCQRQuery ¶
func NewCQRQuery(query cqr.CommonQueryRepresentation) CommonQueryRepresentationQuery
func (CommonQueryRepresentationQuery) Representation ¶
func (q CommonQueryRepresentationQuery) Representation() (interface{}, error)
Representation returns the CQR.
func (CommonQueryRepresentationQuery) String ¶
func (q CommonQueryRepresentationQuery) String() (string, error)
String returns a JSON-encoded representation of the cqr.
func (CommonQueryRepresentationQuery) StringPretty ¶
func (q CommonQueryRepresentationQuery) StringPretty() (string, error)
StringPretty returns a pretty-printed JSON-encoded representation of the cqr.
type Compiler ¶
type Compiler interface { // Compile will transform an immediate representation into the corresponding boolean query for the backend. This // is the reason both the backend and query interfaces must be implemented for this package. Compile(ir ir.BooleanQuery) (BooleanQuery, error) }
Compiler is an interface which requires the implementation of a compiler.
type ElasticsearchBooleanQuery ¶
type ElasticsearchBooleanQuery struct {
// contains filtered or unexported fields
}
ElasticsearchBooleanQuery is the transmute representation of an Elasticsearch query.
func (ElasticsearchBooleanQuery) Representation ¶
func (q ElasticsearchBooleanQuery) Representation() (interface{}, error)
Representation is a wrapper for the traverseGroup function. This function should be used to transform the Elasticsearch ir into a valid Elasticsearch query.
func (ElasticsearchBooleanQuery) String ¶
func (q ElasticsearchBooleanQuery) String() (string, error)
String creates a machine-readable JSON Elasticsearch query.
func (ElasticsearchBooleanQuery) StringPretty ¶
func (q ElasticsearchBooleanQuery) StringPretty() (string, error)
StringPretty creates a human-readable JSON Elasticsearch query.
type ElasticsearchCompiler ¶
type ElasticsearchCompiler struct {
// contains filtered or unexported fields
}
ElasticsearchCompiler is a compiler for Elasticsearch queries.
func NewElasticsearchCompiler ¶
func NewElasticsearchCompiler() ElasticsearchCompiler
NewElasticsearchCompiler returns a new backend for compiling Elasticsearch queries.
func (ElasticsearchCompiler) Compile ¶
func (b ElasticsearchCompiler) Compile(ir ir.BooleanQuery) (BooleanQuery, error)
Compile transforms an immediate representation of a query into an Elasticsearch query.
type ElasticsearchQuery ¶
type ElasticsearchQuery struct {
// contains filtered or unexported fields
}
ElasticsearchQuery is the transmute representation of an Elasticsearch keyword.
type IrBackend ¶
type IrBackend struct{}
IrBackend is the implementation for an immediate representation backend.
func NewIrBackend ¶
func NewIrBackend() IrBackend
NewIrBackend returns an immediate representation compiler backend.
func (IrBackend) Compile ¶
func (b IrBackend) Compile(query ir.BooleanQuery) (BooleanQuery, error)
Compile returns a new IrQuery with the ir embedded inside.
type IrQuery ¶
type IrQuery struct {
// contains filtered or unexported fields
}
IrQuery is just a wrapper for a boolean query in immediate representation.
func (IrQuery) Representation ¶
Representation is the immediate representation using a native data structure.
func (IrQuery) String ¶
String returns a JSON-encoded representation of the immediate representation.
func (IrQuery) StringPretty ¶
StringPretty returns a pretty-printed JSON-encoded representation of the immediate representation.
type MedlineBackend ¶
type MedlineBackend struct { }
func NewMedlineBackend ¶
func NewMedlineBackend() MedlineBackend
func (MedlineBackend) Compile ¶
func (b MedlineBackend) Compile(ir ir.BooleanQuery) (BooleanQuery, error)
type MedlineQuery ¶
type MedlineQuery struct {
// contains filtered or unexported fields
}
func (MedlineQuery) Representation ¶
func (m MedlineQuery) Representation() (interface{}, error)
func (MedlineQuery) String ¶
func (m MedlineQuery) String() (string, error)
func (MedlineQuery) StringPretty ¶
func (m MedlineQuery) StringPretty() (string, error)
type PubmedBackend ¶
type PubmedBackend struct {
ReplaceAdj bool
}
func NewPubmedBackend ¶
func NewPubmedBackend() PubmedBackend
func (PubmedBackend) Compile ¶
func (b PubmedBackend) Compile(ir ir.BooleanQuery) (BooleanQuery, error)
type PubmedQuery ¶
type PubmedQuery struct {
// contains filtered or unexported fields
}
func (PubmedQuery) Representation ¶
func (m PubmedQuery) Representation() (interface{}, error)
func (PubmedQuery) String ¶
func (m PubmedQuery) String() (string, error)
func (PubmedQuery) StringPretty ¶
func (m PubmedQuery) StringPretty() (string, error)
type TerrierBackend ¶
type TerrierBackend struct{}
TerrierBackend is the terrier query compiler.
func NewTerrierBackend ¶
func NewTerrierBackend() TerrierBackend
func (TerrierBackend) Compile ¶
func (t TerrierBackend) Compile(q ir.BooleanQuery) (BooleanQuery, error)
Compile a terrier query.
type TerrierQuery ¶
type TerrierQuery struct {
// contains filtered or unexported fields
}
TerrierQuery is the transmute representation of terrier queries.
func NewTerierQuery ¶
func NewTerierQuery(repr string) TerrierQuery
func (TerrierQuery) Representation ¶
func (q TerrierQuery) Representation() (interface{}, error)
Representation of a terrier query.
func (TerrierQuery) String ¶
func (q TerrierQuery) String() (string, error)
String returns a JSON-encoded representation of the cqr.
func (TerrierQuery) StringPretty ¶
func (q TerrierQuery) StringPretty() (string, error)
StringPretty returns a pretty-printed JSON-encoded representation of the cqr.