Further polish of algolia indexing
This commit is contained in:
committed by
fabioberger
parent
1e44bcb7c9
commit
f1f38fb8b0
@@ -1,13 +0,0 @@
|
|||||||
const algoliasearch = require('algoliasearch');
|
|
||||||
const algoliaAppId = 'T7V7WKELRY';
|
|
||||||
const algoliaAdminKey = 'ccc472dee2aa991ca4bc935975e76b5d';
|
|
||||||
|
|
||||||
export const adminClient = algoliasearch(algoliaAppId, algoliaAdminKey);
|
|
||||||
|
|
||||||
export const sharedSettings = {
|
|
||||||
distinct: true,
|
|
||||||
attributeForDistinct: 'id',
|
|
||||||
attributesToSnippet: ['description', 'textContent:20'], // attribute:nbWords (number of words to show in a snippet)
|
|
||||||
searchableAttributes: ['title', 'textContent', 'description'],
|
|
||||||
snippetEllipsisText: '…',
|
|
||||||
};
|
|
||||||
@@ -1,13 +1,8 @@
|
|||||||
import { adminClient, sharedSettings } from './constants';
|
import { adminClient, searchIndex, settings } from '../ts/utils/algolia_search';
|
||||||
import { indexFiles, setIndexSettings } from './helpers';
|
import { indexFilesAsync, setIndexSettings } from './helpers';
|
||||||
|
|
||||||
const index = adminClient.initIndex('0x_guides_test');
|
const indexName = 'guides';
|
||||||
const dirName = 'guides';
|
const index = adminClient.initIndex(searchIndex[indexName]);
|
||||||
|
|
||||||
const settings = {
|
setIndexSettings(index, settings[indexName]);
|
||||||
...sharedSettings,
|
indexFilesAsync(index, indexName);
|
||||||
attributesForFaceting: ['topics', 'difficulty'],
|
|
||||||
};
|
|
||||||
|
|
||||||
setIndexSettings(index, settings);
|
|
||||||
indexFiles(index, dirName);
|
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ async function processMdxAsync(index: any, dirName: string, fileName: string): P
|
|||||||
.process(file);
|
.process(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function indexFiles(index: any, dirName: string): Promise<void> {
|
export async function indexFilesAsync(index: any, dirName: string): Promise<void> {
|
||||||
fs.readdir(dirName, async (err: string, items: string[]) => {
|
fs.readdir(dirName, async (err: string, items: string[]) => {
|
||||||
for (const fileName of items) {
|
for (const fileName of items) {
|
||||||
await processMdxAsync(index, dirName, fileName);
|
await processMdxAsync(index, dirName, fileName);
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
const { adminClient, sharedSettings } = require('./constants');
|
import { adminClient, searchIndex, settings } from '../ts/utils/algolia_search';
|
||||||
const { indexFiles, setIndexSettings } = require('./helpers');
|
import { indexFilesAsync, setIndexSettings } from './helpers';
|
||||||
|
|
||||||
const index = adminClient.initIndex('0x_tools_test');
|
const indexName = 'tools';
|
||||||
const dirName = 'tools';
|
const index = adminClient.initIndex(searchIndex[indexName]);
|
||||||
|
|
||||||
const settings = {
|
setIndexSettings(index, settings[indexName]);
|
||||||
...sharedSettings,
|
indexFilesAsync(index, indexName);
|
||||||
attributesForFaceting: ['type', 'tags', 'difficulty', 'isCommunity'],
|
|
||||||
};
|
|
||||||
|
|
||||||
setIndexSettings(index, settings);
|
|
||||||
indexFiles(index, dirName);
|
|
||||||
|
|||||||
@@ -1,11 +1,33 @@
|
|||||||
const algoliasearch = require('algoliasearch/lite');
|
const algoliasearch = require('algoliasearch/lite');
|
||||||
|
|
||||||
const { configs } = require('ts/utils/configs');
|
const ALGOLIA_APP_ID = 'T7V7WKELRY';
|
||||||
|
const ALGOLIA_CLIENT_API_KEY = '4c367b8cc6d6e175ae537cc61e4d8dfd';
|
||||||
|
// @TODO: Move the following somewhere safe / out of the repo
|
||||||
|
const ALGOLIA_ADMIN_API_KEY = 'ccc472dee2aa991ca4bc935975e76b5d';
|
||||||
|
|
||||||
export const searchClient = algoliasearch(configs.ALGOLIA_APP_ID, configs.ALGOLIA_CLIENT_API_KEY);
|
export const searchClient = algoliasearch(ALGOLIA_APP_ID, ALGOLIA_CLIENT_API_KEY);
|
||||||
// export const adminClient = algoliasearch(configs.ALGOLIA_APP_ID, configs.ALGOLIA_ADMIN_API_KEY);
|
export const adminClient = algoliasearch(ALGOLIA_APP_ID, ALGOLIA_ADMIN_API_KEY);
|
||||||
|
|
||||||
export const searchIndex = {
|
export const searchIndex = {
|
||||||
guides: '0x_guides_test',
|
guides: '0x_guides_test',
|
||||||
tools: '0x_tools_test',
|
tools: '0x_tools_test',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sharedSettings = {
|
||||||
|
distinct: true,
|
||||||
|
attributeForDistinct: 'id',
|
||||||
|
attributesToSnippet: ['description', 'textContent:20'], // attribute:nbWords (number of words to show in a snippet)
|
||||||
|
searchableAttributes: ['title', 'textContent', 'description'],
|
||||||
|
snippetEllipsisText: '…',
|
||||||
|
};
|
||||||
|
|
||||||
|
export const settings = {
|
||||||
|
guides: {
|
||||||
|
...sharedSettings,
|
||||||
|
attributesForFaceting: ['topics', 'difficulty'],
|
||||||
|
},
|
||||||
|
tools: {
|
||||||
|
...sharedSettings,
|
||||||
|
attributesForFaceting: ['type', 'tags', 'difficulty', 'isCommunity'],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ const BASE_URL = window.location.origin;
|
|||||||
const INFURA_API_KEY = 'T5WSC8cautR4KXyYgsRs';
|
const INFURA_API_KEY = 'T5WSC8cautR4KXyYgsRs';
|
||||||
|
|
||||||
export const configs = {
|
export const configs = {
|
||||||
ALGOLIA_APP_ID: 'T7V7WKELRY',
|
|
||||||
ALGOLIA_ADMIN_API_KEY: 'ccc472dee2aa991ca4bc935975e76b5d',
|
|
||||||
ALGOLIA_CLIENT_API_KEY: '4c367b8cc6d6e175ae537cc61e4d8dfd',
|
|
||||||
AMOUNT_DISPLAY_PRECSION: 5,
|
AMOUNT_DISPLAY_PRECSION: 5,
|
||||||
BACKEND_BASE_PROD_URL: 'https://website-api.0x.org',
|
BACKEND_BASE_PROD_URL: 'https://website-api.0x.org',
|
||||||
BACKEND_BASE_STAGING_URL: 'https://staging-website-api.0x.org',
|
BACKEND_BASE_STAGING_URL: 'https://staging-website-api.0x.org',
|
||||||
|
|||||||
Reference in New Issue
Block a user