Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@clickup/magination

Package Overview
Dependencies
Maintainers
13
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@clickup/magination

An opinionated framework to build cursor-based pagination over multiple streams of hits

  • 2.10.296
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
13
Created
Source

magination: an opinionated framework to build cursor-based pagination over multiple streams of hits

See also Full API documentation.

CI run

The problem: for some search request (e.g. search-by-keywords), we have multiple search queries (sources) with different performance that deliver results (hits) with different relevancy. We want to merge that search hits using "cursor based pagination pattern" (allowing the user to scroll search results with the mouse).

For example purposes, considering the following 3 kinds of sources:

  1. "Full keyword match" query: finds the docs that have their lexems match the search keywords exactly. Highest relevancy and performance.
  2. "Prefix keyword match" query: considers the search keywords as lexem prefixes and finds all of the docs which have the lexems matching that prefixes. Moderate relevancy and performance.
  3. "Substring trigram match" query: finds docs which have search keywords as substrings. Lowest in relevancy and is super-slow.

When producing the cursored stream of pages, we must satisfy the following requirements:

  1. The results must never repeat: if some hit is seen on top, it's never shown at the bottom. E.g. if a "full keyword match" query returns document A, and the same document A is also returned by "substring trigram match" query, it should not be shown the 2nd time.
  2. The results must be exhaustive: i.e. eventually, all of the data will be returned, irregardless of its cardinality, even when the data is constantly appended to the database at some slow rate.
  3. The results from the source with highest relevancy should come earlier than the results from all other sources (at least for the very 1st set of pages). E.g. "full keyword match" source has higher relevancy than "substring trigram match", so the data from it should be returned earlier.
  4. The order of results should not depend on the performance: i.e. the same query run multiple times should produce the same results (considering the underlying database hasn't been changed).

Below is a cryptic diagram which illustrates, how it works:

source1:     [b, m, n]   |
source2: [a, b, c]       |     [d, e, f]
source3:   [q, r]        |  [s, t]
---------------------------------------------------> time

1. Magination.load():
   -> [b,m,n][a,c][q,r] + cursor
2. Magination.load(cursor):
   -> [d,e,f][s,t] + cursor=null

Here, [...] means search results docs from some source, and "|" means that a search query returns a cursor which allows to re-run it from where it left off.

To guarantee that the docs are never repeated in the resulting stream of pages, the engine remembers all of the hits previously emitted; they are stored in the cache. Where possible, it saves the docs hash codes, but for the actual sources, we store the entire hits, because we may want to return to the previous pages too (plus, we do "preload-ahead" for sources).

Keywords

FAQs

Package last updated on 13 Jan 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc