0.2.7 • Published 3 years ago

next-algolia-server v0.2.7

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

next-algolia-server

Install

yarn add algoliasearch next-algolia-server

Usage

Basic configuration

import AlgoliaServer from "next-algolia-server";

// Create your instance with your algoliaId and algoliaKey
// Get yours https://www.algolia.com/
const algolia = AlgoliaServer.getInstance({ algoliaId, algoliaKey });

// Set your index
algolia.setIndex("blog");

// Set your searchableAttributes
// Read more about this https://www.algolia.com/doc/api-reference/api-parameters/searchableAttributes/
algolia.setSearchableAttributes([
  "title,description",
  "content",
  "categories.name",
]);

Then you would be able to use this algolia instance to handle your records.

// I did it inside my `getStaticProps`
export async function getStaticProps() {
  // ... functions to get my posts...
  const posts = [];
  // Read more about this https://www.algolia.com/doc/api-reference/api-methods/save-objects/
  // Every record most have a unique `objectID` param
  // Or let algolia generate it with algoliaServer.saveRecords(posts, { autoGenerateObjectIDIfNotExist: true })
  // Be careful if you let algolia generate it you could duplicate your records
  algoliaServer.saveRecords(posts);

  return posts;
}

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.2

3 years ago

0.1.0

3 years ago