lucilla
Version 0.2.0
Lucilla是Kotlin的内存全文搜索库。
它允许您为数据库构建全文搜索索引,该索引无需将其持续到数据库。您可以针对索引运行搜索查询,以快速查找匹配文档。
import com.haroldadmin.lucilla.core.*
data class Book (
@Id
val id : Int ,
val title : String ,
val summary : String ,
)
val index = useFts(getBooks())
index.search( " Martian " ).map { searchResult ->
val bookId = searchResult.documentId
val book = getBook(bookId)
// Show search result to the user
}露西拉(Lucilla)正在积极发展。这是一个早期的原型,不适合生产使用。
尽管Lucilla为您介绍了大多数基本功能,但缺少对某些高级功能的支持(但计划):
要使用Lucilla的FTS功能,您必须首先将数据建模为类。
我们建议为此目的使用数据类,但是只要满足以下要求,任何内容都应有效:
@Id标记的字段,可以解析为IntString S import com.haroldadmin.lucilla.core.Id
data class Book (
@Id
val id : Int ,
val title : String ,
val summary : String ,
)如果您不希望Lucilla为文档的某些字段索引,请用@Ignore注释它们。
import com.haroldadmin.lucilla.core.Id
import com.haroldadmin.lucilla.core.Ignore
data class Book (
@Id
val id : Int ,
val title : String ,
val summary : String ,
@Ignore
val publisher : String ,
)创建FTS索引并将您的数据添加到其中:
val index = useFts< Book >()
getBooks().forEach { index.add(it) }
// You can also pass your seed data directly
val books = getBooks()
val index = useFts< Book >(books)将文档添加到索引或使用种子数据创建索引是一个可能昂贵的过程,具体取决于每个文档的大小。最好在背景线程或Coroutine上执行此过程。
将查询发送到索引,以获取相关性订购的搜索结果。
val searchResults = index.search(query)
val books = searchResults.map { r -> r.documentId }.map { id -> getBook(id) }
showResults(books)Lucilla通过文本处理管道运行每个搜索查询,从中提取可搜索的令牌。令牌可能无法准确反映搜索查询。要查找与给定搜索结果匹配的搜索查询的哪个令牌,请在搜索结果上使用“ MatchTerm”属性。
将Jitpack存储库添加到您的存储库列表中:
// Project level build.gradle file
allprojects {
repositories {
maven { url ' https://jitpack.io ' }
}
}然后在gradle文件中添加依赖项:
// Module build.gradle file
dependencies {
implementation " com.github.haroldadmin.lucilla:core:(latest-version) "
}露西拉(Lucilla)正在积极发展,并且不承诺API稳定性。希望图书馆在达到稳定状态之前进行重大变化。
我们鼓励社区贡献功能并报告错误。
塞巴斯蒂安·维特尔(Sebastian Vettel)的2020法拉利(Ferrari)的名字启发了“露西拉(Lucilla)”这个名字。这听起来也类似于Lucene (来自Apache Lucene),这是行业标准全文搜索框架。
露西拉(Lucilla)的实现从JavaScript图书馆杂物借用。
MIT License
Copyright (c) 2022 Kshitij Chauhan
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.