Skip to content

Commit

Permalink
Merge pull request #225 from JetBrains/graph-store-ignore-case-search
Browse files Browse the repository at this point in the history
Removed lowercase from LIKE expression as it's done on DB side. Also …
  • Loading branch information
leostryuk authored Nov 25, 2024
2 parents 36765cb + 1c55dd7 commit 35380a6
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
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

0 comments on commit 35380a6

Please sign in to comment.