Giter VIP home page Giter VIP logo

lucilla's Introduction

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.

lucilla's People

Contributors

haroldadmin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

lucilla's Issues

Add ability to limit search query to specific document properties

Allow users to search the index for specific properties of a document only.

For example, the ability to search only the titles of indexed books, even if other properties are indexed too:

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

val index = useFts(getBooks())

// Only return results that contain "recursion" in the book title
val results = index.search("recursion", Book::title)

Divide the FTS index per document field

Lucilla treats every document as a blob of text, which does not work well for field-specific or field boosts. Storing field related information in the document would make it easier to implement such functionality.

Add support for auto-complete suggestions

Add ability to fetch auto completion suggestions for a search query.

A simple autocomplete suggestions provider can be built using prefix search. For a search query, return matching words in the index that contain the query as a prefix.

Switch to Positional Postings List in the Index

Lucilla's FTS index stores a map of documents and frequencies for each term, which can also be used to calculate the document frequency.

Modify the index to also store the starting position/offset for each term in the documents.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.