Skip to content
This repository has been archived by the owner on Jun 28, 2022. It is now read-only.
/ QuickSearch Public archive
forked from karliszigurs/QuickSearch

Simple and lightweight in-memory search library

Notifications You must be signed in to change notification settings

ingef/QuickSearch

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status SonarQube Coverage SonarQube Tech Debt Coverty Scan Codacy grade

QuickSearch

Simple and lightweight in-memory search library for Java 8 web and desktop applications. Single 30KB jar. 100% test coverage. Fast.

Demo

Live demo available at http://zigurs.com/qs (instance of https://github.com/karliszigurs/QuickSearchServer).

Description

QuickSearch provides pretty instant search over arbitrary items and their keywords. This is achieved by adding items and pre-calculating their keywords and partial matching fragments that are then matched against users input during search.

It is well suited for small to medium data sets (e.g. up to a 10-20GB of JVM heap) that can fit into memory, e.g.

  • Contacts lookup (keywords of name, department, position, location, ...)
  • Online store stock search (keywords of category, raw description, brand names, reviews, ...)
  • Complex category navigation (keywords of category tree, category items, category aliases, ...)
  • Faceted search of sparsely distributed categories
  • ...

Performance and footprint

Circa 500k - 1 million lookups per second on a commodity server. Search request processing times in single digit microsecond range. Less than 20MB of heap required for 100'000 unique items. Thread safe.

Benchmarks available at https://github.com/karliszigurs/QuickSearchBenchmarks

Include it in your project

<dependency>
    <groupId>com.zigurs.karlis.utils.search</groupId>
    <artifactId>QuickSearch</artifactId>
    <version>1.8</version>
</dependency>

Use example

/* create instance with all defaults */
QuickSearch<String> qs = new QuickSearch<>();

/* add a few example movies and associated keywords */
qs.addItem("The Da Vinci Code", "The Da Vinci Code Wedding Will Tu...");
qs.addItem("Ice Age: The Meltdown", "Ice Age: The Meltdown  Family...");
qs.addItem("Casino Royale", "Casino Royale Prague, James Bond MI6 ...");
qs.addItem("Night at the Museum", "Family Larry Daley Ben Stiller ...");
qs.addItem("Cars", "Cars Family last race Piston Cup tie Strip The...");

/* find a top result for query */
Optional<String> foundItem = qs.findItem("bond");
System.out.println(foundItem.get());

/* find up to 10 top items */
List<String> foundItems = qs.findItems("family ca", 10);
foundItems.forEach(i -> System.out.println(String.format("- %s", i)));

Caveats

All internal data structures are pre-calculated on add/remove and reside in memory. Following considerations apply:

  • Searchable items should be relatively lightweight as they will be long lived. If you want to search over heavyweight items (e.g. pictures or ORM) it is best to create an lightweight immutable object that contains only the minimum required to refer to fill payload.
  • QuickSearch does not contain any protection against running out of memory. This shouldn't be a problem, as in normal use even 10s of thousands of searchable items and keywords don't require more than a few tens of megabytes of heap. If you cannot ensure that you are removing no longer relevant entries it is recommended to periodically clear and repopulate the index (e.g. daily).

Credits

                              //
(C) 2016 Karlis Zigurs (http://zigurs.com)
                            //

About

Simple and lightweight in-memory search library

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%