Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ThisBuild / organization := "app.softnetwork"

name := "softclient4es"

ThisBuild / version := "0.5.0"
ThisBuild / version := "0.6.0"

ThisBuild / scalaVersion := scala213

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import app.softnetwork.elastic.sql.{
ElasticNested,
ElasticParent,
SQLBetween,
SQLComparisonDateMath,
SQLExpression,
SQLIn,
SQLIsNotNull,
SQLIsNull
SQLIsNotNullCriteria,
SQLIsNull,
SQLIsNullCriteria
}
import com.sksamuel.elastic4s.ElasticApi._
import com.sksamuel.elastic4s.searches.queries.Query
Expand Down Expand Up @@ -70,7 +71,8 @@ case class ElasticQuery(filter: ElasticFilter) {
case between: SQLBetween[Double] => between
case geoDistance: ElasticGeoDistance => geoDistance
case matchExpression: ElasticMatch => matchExpression
case dateMath: SQLComparisonDateMath => dateMath
case isNull: SQLIsNullCriteria => isNull
case isNotNull: SQLIsNotNullCriteria => isNotNull
case other =>
throw new IllegalArgumentException(s"Unsupported filter type: ${other.getClass.getName}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,20 @@ package object bridge {
)
}

def applyNumericOp[A](n: SQLNumeric[_])(
def applyNumericOp[A](n: SQLNumericValue[_])(
longOp: Long => A,
doubleOp: Double => A
): A = n.toEither.fold(longOp, doubleOp)

implicit def expressionToQuery(expression: SQLExpression): Query = {
import expression._
if (aggregation)
return matchAllQuery()
if (identifier.functions.nonEmpty) {
return scriptQuery(Script(script = painless).lang("painless").scriptType("source"))
}
value match {
case n: SQLNumeric[_] if !aggregation =>
case n: SQLNumericValue[_] =>
operator match {
case Ge =>
maybeNot match {
Expand Down Expand Up @@ -226,7 +231,7 @@ package object bridge {
}
case _ => matchAllQuery()
}
case l: SQLLiteral if !aggregation =>
case l: SQLStringValue =>
operator match {
case Like =>
maybeNot match {
Expand Down Expand Up @@ -279,7 +284,7 @@ package object bridge {
}
case _ => matchAllQuery()
}
case b: SQLBoolean if !aggregation =>
case b: SQLBoolean =>
operator match {
case Eq =>
maybeNot match {
Expand All @@ -297,27 +302,27 @@ package object bridge {
}
case _ => matchAllQuery()
}
case _ => matchAllQuery()
}
}

implicit def dateMathToQuery(dateMath: SQLComparisonDateMath): Query = {
import dateMath._
if (aggregation)
return matchAllQuery()
dateTimeFunction match {
case _: CurrentTimeFunction =>
scriptQuery(Script(script = script).lang("painless").scriptType("source"))
case _ =>
val op = if (maybeNot.isDefined) operator.not else operator
op match {
case Gt => rangeQuery(identifier.name) gt script
case Ge => rangeQuery(identifier.name) gte script
case Lt => rangeQuery(identifier.name) lt script
case Le => rangeQuery(identifier.name) lte script
case Eq => rangeQuery(identifier.name) gte script lte script
case Ne | Diff => not(rangeQuery(identifier.name) gte script lte script)
case i: SQLIdentifier =>
operator match {
case op: SQLComparisonOperator =>
i.toScript match {
case Some(script) =>
val o = if (maybeNot.isDefined) op.not else op
o match {
case Gt => rangeQuery(identifier.name) gt script
case Ge => rangeQuery(identifier.name) gte script
case Lt => rangeQuery(identifier.name) lt script
case Le => rangeQuery(identifier.name) lte script
case Eq => rangeQuery(identifier.name) gte script lte script
case Ne | Diff => not(rangeQuery(identifier.name) gte script lte script)
}
case _ =>
scriptQuery(Script(script = painless).lang("painless").scriptType("source"))
}
case _ =>
scriptQuery(Script(script = painless).lang("painless").scriptType("source"))
}
case _ => matchAllQuery()
}
}

Expand All @@ -335,6 +340,20 @@ package object bridge {
existsQuery(identifier.name)
}

implicit def isNullCriteriaToQuery(
isNull: SQLIsNullCriteria
): Query = {
import isNull._
not(existsQuery(identifier.name))
}

implicit def isNotNullCriteriaToQuery(
isNotNull: SQLIsNotNullCriteria
): Query = {
import isNotNull._
existsQuery(identifier.name)
}

implicit def inToQuery[R, T <: SQLValue[R]](in: SQLIn[R, T]): Query = {
import in._
val _values: Seq[Any] = values.innerValues
Expand Down
Loading