• Stars
    star
    127
  • Rank 282,790 (Top 6 %)
  • Language
    Kotlin
  • License
    MIT License
  • Created almost 3 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Fast, efficient, in-memory Full Text Search for Kotlin

Lucilla

Build Jitpack

Lucilla is an in-memory Full Text Search library for Kotlin.

It allows to you to build a Full Text Search index for data that does not need to be persisted to a database. You can run search queries against the index to find matching documents quickly.

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 is in active development. It's an early stage prototype, and not suitable for production use yet.

Features

  • PATRICIA Trie based space efficient FTS index
  • Advanced text processing pipeline with support for Tokenization, Stemming, Punctuation removal and more.
  • Extensible text processing with custom pipeline steps
  • Search results ranking using TF-IDF scores
  • Customisable document parsing with ability to ignore unwanted fields

While lucilla has you covered on most of the basic features, support for some advanced features is missing (but planned):

  • Fuzzy searching
  • Custom field boosts
  • Async processing

Usage

Modelling Data

To use lucilla's FTS capabilities, you must first model your data as a class.

We recommend using data classes for this purpose, but anything should work as long as it satisfies the following requirements:

  • Must have a @Id marked field that can be parsed as an Int
  • Must have one or more other properties that can be parsed as Strings
import com.haroldadmin.lucilla.core.Id

data class Book(
  @Id
  val id: Int,
  val title: String,
  val summary: String,
)

If you don't want lucilla to index some fields of your document, annotate them with @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,
)

Create the Index

Create an FTS index and add your data to it:

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)

Adding documents to the index, or creating the index with seed data is a potentially expensive process depending on how large each document is. It's best to perform this process on a background thread or Coroutine.

Search the Index

Send your queries to the index to get search results ordered by relevance.

val searchResults = index.search(query)
val books = searchResults.map { r -> r.documentId }.map { id -> getBook(id) }
showResults(books)

Lucilla runs every search query through a text processing pipeline to extract searchable tokens from it. The tokens may not reflect the search query exactly. To find which token of your search query matched with a given search result, use the "matchTerm" property on a search result.

Installation

Add the Jitpack repository to your list of repositories:

// Project level build.gradle file
allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

And then add the dependency in your gradle file:

// Module build.gradle file
dependencies {
    implementation "com.github.haroldadmin.lucilla:core:(latest-version)"
}

Jitpack

Contributing

lucilla is in active development and does not promise API stability. Expect the library to undergo significant changes before it reaches stable status.

We encourage the community to contribute features and report bugs.

Meta

The name 'lucilla' is inspired from the name of Sebastian Vettel's 2020 Ferrari. It also sounds similar to lucene (from Apache Lucene), which is the industry standard full text search framework.

lucilla's implementation borrows from a JavaScript library MiniSearch.

License

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.

More Repositories

1

NetworkResponseAdapter

Retrofit call adapter to model success/failed responses as sealed types
Kotlin
562
star
2

WhatTheStack

See a pretty error screen when your Android app crashes
Kotlin
245
star
3

Vector

Kotlin Coroutines based MVI architecture library for Android
Kotlin
193
star
4

MoonShot

A SpaceX companion app for Android
Kotlin
161
star
5

MovieDB

A gorgeous TMDb client for Android
Kotlin
124
star
6

functions-differ

Tool to find Firebase Functions that changed for selective redeployments
TypeScript
39
star
7

Resumade

An Android app with a minimal material design that generates a resume for you
Kotlin
32
star
8

opengraphKt

A dead simple OpenGraph tags parser for Kotlin
Kotlin
21
star
9

json-formatter

Dead simple JSON formatter for the browser (Next.js, Tailwindcss, TypeScript)
TypeScript
8
star
10

getignore

Fetch gitignore files for your projects right from the command line
Go
7
star
11

dagger-mvrx-multimodule

Demonstrates usage of Dagger and MvRx in multi module apps
Kotlin
3
star
12

pathfix

Fixes the PATH environment variable of the current process
Go
3
star
13

EpoxyCarouselBugSample

Sample project for carousel scrolling bug in Epoxy
Kotlin
2
star
14

homebrew-pps

Homebrew Tap for the pps package
Ruby
2
star
15

translate_ref_generator

A Dart build plugin to make it easier to work with translation string files
Dart
2
star
16

UsageStatsManager-Sample

An app to demonstrate the usage of the UsageStatsManager API
Java
2
star
17

homebrew-getignore

Homebrew repository for getignore
Ruby
1
star
18

spacexkmp

A Kotlin Multiplatform wrapper for the SpaceX API
Kotlin
1
star
19

translate_ref

Annotations library for Translation Reference Generator
Dart
1
star
20

CMS

Semester project for Database Management System course (CO202)
JavaScript
1
star
21

UnitTestingSample

A sample app to help me learn unit testing through Junit 5 and Spek framework
Kotlin
1
star
22

MVRx-Lite

A lightweight state management library inspired from Airbnb's amazing MvRx library
Kotlin
1
star
23

pps

A parallel port scanner, not intended for real use
Go
1
star
24

Rosewood

An Android app to create a timeline of user interactions with their device
Kotlin
1
star