Git Product home page Git Product logo

pagefind-instantsearch's Introduction

InstantSearch adapter for pagefind monorepo

It is the monorepo repository:

Idea

The idea is to create an InstantSearch adapter for pagefind and build the same demo site as I did for facets. This way we can compare "apples to apples".

To do so I wanted to use the same Schema as in facets:

I started implementation with hardcoded conversion. I managed to create a working demo. However, I realized that pagefind can't be used as a general faceted search engine.

Type conversion

pagefind supports only string values, so all values need to be converted to strings before indexing and back to the initial type on the client side.

Indexing:

brand: [item.brand],
categories: item.categories,
price: [`${item.price}`],
rating: [`${item.rating}`],
free_shipping: [`${item.free_shipping}`],

Client-side:

{
  objectID: item.id,
  ...data.meta,
  categories: data.filters.categories,
  price: parseFloat(data.filters.price[0]),
  rating: parseFloat(data.filters.rating[0]),
}

Sorting

See:

Stats for numerical facets

Because there is no support for numbers to get stats we need to convert strings to numbers on the client side and calculate stats:

if (schema[field]?.type === "number") {
  const values: number[] = [];
  entries.forEach((a) => values.push(parseFloat(a[0])));
  facetsStats[field] = {
    min: Math.min(...values),
    max: Math.max(...values),
  };
}

Filter for numeric fields

I didn't implement a filter for numeric fields, like price >= 40 AND price <= 100. The price slider doesn't work in the deme

Status

After I realized that it was not practical to use a general faceted search engine I gave up and didn't finish code for schema transformation.

This code is not recomended for prodcution use.

Development

pnpm i
pnpm run dev

TODO

  • CLI to covert JSON to pagefind index
    • maybe cosmiconfig to pass configuration
      • it can use the same schema as facets
      • input
      • output
  • adapter for instantsearch
    • filtering for numeric facets

pagefind-instantsearch's People

Contributors

dependabot[bot] avatar stereobooster avatar

Watchers

 avatar  avatar

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.