Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed lowercase from LIKE expression as it's done on DB side. Also … #225

Merged
merged 1 commit into from
Nov 25, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ class OStoreTransactionImpl(
ignoreCase: Boolean
): EntityIterable {
requireActiveTransaction()
return OPropertyContainsIterable(this, entityType, propertyName, value)
return OPropertyContainsIterable(this, entityType, propertyName, value, ignoreCase)
}

override fun findStartingWith(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ class OPropertyContainsIterable(
private val entityType: String,
private val propertyName: String,
private val value: String,
private val ignoreCase: Boolean
) : OEntityIterableBase(txn) {

override fun query(): OSelect {
val condition = OContainsCondition(propertyName, value)
val condition = OContainsCondition(propertyName, value, ignoreCase)
return OClassSelect(entityType, condition)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ class OEqualCondition(
class OContainsCondition(
val field: String,
val value: String,
val ignoreCase: Boolean,
) : OCondition {

override fun sql(builder: SqlBuilder) {
val param = builder.addParam(field, value.lowercase())
builder.append(field).append(".toLowerCase()").append(" containsText :$param")
val param = if (ignoreCase){
builder.addParam(field, value.lowercase())
} else{
builder.addParam(field, value)
}
builder.append(field).let { builder -> if (ignoreCase) builder.append(".toLowerCase()") else builder }.append(" containsText :$param")
}
}

Expand All @@ -49,7 +54,7 @@ class OStartsWithCondition(

override fun sql(builder: SqlBuilder) {
val param = builder.addParam(field, "${value.lowercase()}%")
builder.append(field).append(".toLowerCase()").append(" like :$param")
builder.append(field).append(" like :$param")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public PropertyContains(String name, String contains, boolean ignoreCase) {
@Override
public Iterable<Entity> instantiate(String entityType, QueryEngine queryEngine, ModelMetaData metaData, InstantiateContext context) {
var txn = queryEngine.getOStore().requireActiveTransaction();
return new OPropertyContainsIterable(txn, entityType, name, contains);
return new OPropertyContainsIterable(txn, entityType, name, contains, ignoreCase);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,15 @@ class OQueryEngineTest(
// When
withStoreTx { tx ->
val issues = engine.query(iterableGetter(engine, tx), "Issue", PropertyContains("case", "YOU", true))
val issuesIgnoreCase = engine.query(iterableGetter(engine, tx), "Issue", PropertyContains("case", "yOu", true))
val issuesIgnoreNotIgnoreCase = engine.query(iterableGetter(engine, tx), "Issue", PropertyContains("case", "yOu", false))
val empty = engine.query(iterableGetter(engine, tx), "Issue", PropertyContains("case", "not", true))

// Then
assertNamesExactly(issues, "issue2")
assertNamesExactly(issuesIgnoreCase, "issue2")
//this may be subject to change if we want to support exact case search
assertThat(issuesIgnoreNotIgnoreCase).isEmpty()
assertThat(empty).isEmpty()
}
}
Expand All @@ -141,10 +146,12 @@ class OQueryEngineTest(
// When
withStoreTx { tx ->
val issues = engine.query(iterableGetter(engine, tx), "Issue", PropertyStartsWith("case", "Find"))
val issuesOtherCase = engine.query(iterableGetter(engine, tx), "Issue", PropertyStartsWith("case", "find"))
val empty = engine.query(iterableGetter(engine, tx), "Issue", PropertyStartsWith("case", "you"))

// Then
assertNamesExactly(issues, "issue2")
assertNamesExactly(issuesOtherCase, "issue2")
assertThat(empty).isEmpty()
}
}
Expand Down
Loading