Skip to content

Commit 559d084

Browse files
committed
refactor : change to const string value QUZ-125
1 parent 7e91904 commit 559d084

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

matching-service/matching-infra/src/main/kotlin/com/grepp/quizy/matching/infra/match/repository/MatchingPoolRepositoryAdapter.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ private const val MATCHING_INDEX_PREFIX = "MATCHING_VECTOR_POOL:"
1919
private const val MATCHING_INDEX = "MATCHING_INDEX"
2020
private const val MATCHING_K = 5
2121

22+
private const val ID_FIELD = "id"
23+
private const val VECTOR_FIELD = "vector"
24+
2225
@Repository
2326
class MatchingPoolRepositoryAdapter(
2427
private val jedis: JedisPooled
@@ -39,8 +42,8 @@ class MatchingPoolRepositoryAdapter(
3942
Pair("DISTANCE_METRIC", "COSINE"),
4043
)
4144
val schema = Schema()
42-
.addNumericField("id")
43-
.addHNSWVectorField("vector", vectorAttr)
45+
.addNumericField(ID_FIELD)
46+
.addHNSWVectorField(VECTOR_FIELD, vectorAttr)
4447

4548
try {
4649
jedis.ftCreate(MATCHING_INDEX, IndexOptions.defaultOptions().setDefinition(definition), schema)
@@ -51,21 +54,21 @@ class MatchingPoolRepositoryAdapter(
5154

5255
override fun saveVector(userStatus: UserStatus) {
5356
val key = "$MATCHING_INDEX_PREFIX${userStatus.userId.value}"
54-
jedis.hset(key, "id", userStatus.userId.value.toString())
55-
jedis.hset(key.toByteArray(), "vector".toByteArray(), userStatus.vector.value.toByteArray())
57+
jedis.hset(key, ID_FIELD, userStatus.userId.value.toString())
58+
jedis.hset(key.toByteArray(), VECTOR_FIELD.toByteArray(), userStatus.vector.value.toByteArray())
5659
}
5760

5861
override fun findNearestUser(pivot: UserStatus): List<UserStatus> {
59-
val query = Query("*=>[KNN ${'$'}K @vector ${'$'}query_vector]")
60-
.returnFields("id")
62+
val query = Query("*=>[KNN ${'$'}K @$VECTOR_FIELD ${'$'}query_vector]")
63+
.returnFields(ID_FIELD)
6164
.addParam("K", MATCHING_K)
6265
.addParam("query_vector", pivot.vector.value.toByteArray())
6366
.dialect(2)
6467
val docs = jedis.ftSearch(MATCHING_INDEX, query).documents
6568

6669
return docs.map { doc ->
67-
val id = doc.get("id") as String
68-
val vector = jedis.hget(doc.id.toByteArray(), "vector".toByteArray())
70+
val id = doc.get(ID_FIELD) as String
71+
val vector = jedis.hget(doc.id.toByteArray(), VECTOR_FIELD.toByteArray())
6972
UserStatus(
7073
userId = UserId(id.toLong()),
7174
vector = UserVector(vector.toFloatArray())

0 commit comments

Comments
 (0)