Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/zhuliquan/lucene-to-sql
parse lucene query and convert lucene query to SQL query
https://github.com/zhuliquan/lucene-to-sql
Last synced: about 2 months ago
JSON representation
parse lucene query and convert lucene query to SQL query
- Host: GitHub
- URL: https://github.com/zhuliquan/lucene-to-sql
- Owner: zhuliquan
- License: mit
- Created: 2023-05-22T15:12:24.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-05-25T17:19:02.000Z (8 months ago)
- Last Synced: 2024-06-19T15:00:18.860Z (7 months ago)
- Language: Go
- Size: 75.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# lucene-to-sql
## Introduction
This package can parse lucene query and convert to **WHERE predicates** in SQL, this package is pure go package.
## Features
- 1、This package can convert lucene query to **WHERE predicates** SQL.
- 2、According to ES Mapping to convert Lucene query to SQL.## Usage
get package:
```shell
go get github.com/zhuliquan/lucene-to-sql@latest
```example of `lucene-to-sql`:
```golang
import (
"fmt""github.com/zhuliquan/lucene-to-sql"
esMapping "github.com/zhuliquan/es-mapping"
)func getSchema(mapping *esMapping.Mapping) *esMapping.PropertyMapping {
res, _ := esMapping.NewPropertyMapping(mapping)
return res
}func main() {
cvt := lucene_to_sql.NewSqlConvertor(
lucene_to_sql.WithSQLStyle(lucene_to_sql.SQLite),
lucene_to_sql.WithSchema(getSchema(&esMapping.Mapping{
Properties: map[string]*esMapping.Property{
"field1": {
Type: esMapping.DATE_FIELD_TYPE,
Format: "yyyy-MM-dd'T'HH:mm:ss",
},
"field2": {
Type: esMapping.KEYWORD_FIELD_TYPE,
},
"field3": {
Type: esMapping.TEXT_FIELD_TYPE,
},
},
})),
)
query := `field1:["2008-01-01T09:09:08" TO * ] AND field2:foo OR field3:bar`
got, err := cvt.LuceneToSql(query)
if err != nil {
panic(err)
} else {
// field1 >= '2008-01-01 09:09:08' AND field2 = 'foo' OR field3 like '%bar%'
fmt.Println(got)
}
}
```