Git Product home page Git Product logo

keywordsearch's Introduction

KeywordSearch

Memory efficient fast keyword search library written in Kotlin based on ternary search trie data structure.

This library is ideal for memory constrained environments like Android. It is also fast and can be used for high performance applications.

An example app is provided in the app module. It is a simple app that searches for cities in the world based on a json file. Google maps is used to show the location of the city. You should provide your own Google maps API key in the local.properties file like below

```MAPS_API_KEY=YOUR_API_KEY```

Features

  • Prefix search
  • Custom searchable object support
  • Memory efficient
  • Fast
  • Case insensitive / case sensitive search

Installation

This library currently isn't hosted in any repository. You can download the source code and build it yourself.

Usage

    implementation project(path: ':keywordsearch')

provided you have library module in your project.

Create a searchable object

Create a class that implements the Searchable interface. The text field should return the text that you want to search on. For example

    data class City(val name: String, val country: String, val latitude: Double, val longitude: Double) : Searchable {
        override fun getSearchableText(): String {
            return name
        }
    }   

Create a keyword search object

You can create a keyword search object to perform your searches on. You can create a keyword search object by passing a list of searchable objects to the constructor.

    val keywordSearch = KeywordSearch(caseSensitive = true) // case insensitive search

Note that the default configuration for caseSensitive is false. If you want to perform case sensitive search, you should pass true to the constructor.

Add a searchable object

You can add a searchable object to the keyword search object by calling the add method on the keyword search object.

    keywordSearch.add(city)

Your searchable object will be added to the keyword search object and will be available for search.

Perform a search

You can perform a keyword search by by calling the itemsWithKeyword method on the keyword search object. The itemsWithKeyword method returns a list of searchable objects that match the search query.

    val results = keywordSearch.itemsWithKeyword("lond")

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.