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.