Skip to content

Commit

Permalink
Merge pull request #120 from vitrivr/feature/fulltext
Browse files Browse the repository at this point in the history
Adjust Fulltext Search
  • Loading branch information
lucaro authored Nov 18, 2024
2 parents de301d7 + 462d19f commit 33d5dbb
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,14 @@ open class Schema(val name: String = "vitrivr", val connection: Connection) : Cl
* @return [DescriptorWriter]
*/
fun getWriter(): DescriptorWriter<D> = this.connection.getDescriptorWriter(this as Field<*, D>)


/**
* Convenience method to generate and return a prototypical [D] for this [Field].
*
* @return [D]
*/
fun getPrototype(): D = this.analyser.prototype(this as Field<*, D>)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ class FFmpegVideoDecoder : DecoderFactory {
override fun consumeStreams(streams: MutableList<Stream>) {
this.videoStream = streams.firstOrNull { it.type == Stream.Type.VIDEO }
this.audioStream = streams.firstOrNull { it.type == Stream.Type.AUDIO }

/* Reset counters and flags. */
this@InFlowFrameConsumer.videoReady = !(this@InFlowFrameConsumer.videoStream != null && this@Instance.video)
this@InFlowFrameConsumer.audioReady = !(this@InFlowFrameConsumer.audioStream != null && this@Instance.audio)
}

/**
Expand Down Expand Up @@ -217,8 +221,7 @@ class FFmpegVideoDecoder : DecoderFactory {
}

/* If enough frames have been collected, emit them. */
if ((this@Instance.audio && this@InFlowFrameConsumer.videoReady && this@InFlowFrameConsumer.audioReady) ||
(!this@Instance.audio && this@InFlowFrameConsumer.videoReady)) {
if (this@InFlowFrameConsumer.videoReady && this@InFlowFrameConsumer.audioReady) {
emit()

/* Reset counters and flags. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ class ScalarDescriptorReader(field: Schema.Field<*, ScalarDescriptor<*, *>>, con
* @return [Sequence] of [ScalarDescriptor]s.
*/
private fun queryFulltext(query: SimpleFulltextQuery): Sequence<ScalarDescriptor<*, *>> {
val queryValue = query.value.value.split(" ").joinToString(" OR ", "(", ")") { "$it*" }
val cottontailQuery = org.vitrivr.cottontail.client.language.dql.Query(this.entityName)
.select("*")
.fulltext(VALUE_ATTRIBUTE_NAME, query.value.value, "score")
.fulltext(VALUE_ATTRIBUTE_NAME, queryValue, "score")

if (query.limit < Long.MAX_VALUE) {
cottontailQuery.limit(query.limit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ class StructDescriptorReader(field: Schema.Field<*, StructDescriptor<*>>, connec
for ((name, _) in this.fieldMap) {
cottontailQuery.select(name)
}
cottontailQuery.fulltext(query.attributeName!!, query.value.value, SCORE_COLUMN_NAME)

val queryValue = query.value.value.split(" ").joinToString(" OR ", "(", ")") { "$it*" }
cottontailQuery.fulltext(query.attributeName!!, queryValue, SCORE_COLUMN_NAME)
if (query.limit < Long.MAX_VALUE) {
cottontailQuery.limit(query.limit)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ class ScalarDescriptorReader(field: Schema.Field<*, ScalarDescriptor<*, *>>, con
* @return [Sequence] of [ScalarDescriptor]s.
*/
private fun queryFulltext(query: SimpleFulltextQuery): Sequence<ScalarDescriptor<*, *>> {
val statement = "SELECT * FROM \"$tableName\" WHERE $VALUE_ATTRIBUTE_NAME @@ plainto_tsquery(?)"
val queryString = query.value.value.split(" ").map { "$it:*" }.joinToString(" | ") { it }
val statement = "SELECT * FROM \"${tableName.lowercase()}\" WHERE ${query.attributeName} @@ to_tsquery(?)"
return sequence {
this@ScalarDescriptorReader.connection.jdbc.prepareStatement(statement).use { stmt ->
stmt.setString(1, query.value.value)
stmt.setString(1, queryString)
stmt.executeQuery().use { result ->
while (result.next()) {
yield(rowToDescriptor(result))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ class StructDescriptorReader(field: Schema.Field<*, StructDescriptor<*>>, connec
*/
private fun queryFulltext(query: SimpleFulltextQuery): Sequence<StructDescriptor<*>> {
require(query.attributeName != null) { "Query attribute must not be null for a fulltext query on a struct descriptor." }
val statement = "SELECT * FROM \"${tableName.lowercase()}\" WHERE ${query.attributeName} @@ plainto_tsquery(?)"
val queryString = query.value.value.split(" ").map { "$it:*" }.joinToString(" | ") { it }
val statement = "SELECT * FROM \"${tableName.lowercase()}\" WHERE ${query.attributeName} @@ to_tsquery(?)"
return sequence {
this@StructDescriptorReader.connection.jdbc.prepareStatement(statement).use { stmt ->
stmt.setString(1, query.value.value)
stmt.setString(1, queryString)
stmt.executeQuery().use { result ->
while (result.next()) {
yield(rowToDescriptor(result))
Expand Down

0 comments on commit 33d5dbb

Please sign in to comment.