Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/__tests__/__snapshots__/config.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,23 @@ Object {
"bootstrapConcurrency": 100,
"bootstrapIndexName": "npm-search-bootstrap",
"indexName": "fake-index",
"indexRules": Array [
Object {
"condition": Object {
"anchoring": "is",
"pattern": "{facet:concatenatedName}",
},
"consequence": Object {
"params": Object {
"automaticOptionalFacetFilters": Array [
"concatenatedName",
],
},
},
"description": "promote exact matches",
"objectID": "promote-exact",
},
],
"indexSettings": Object {
"attributesForFaceting": Array [
"filterOnly(concatenatedName)",
Expand Down Expand Up @@ -58,13 +75,17 @@ Object {
"owners.name",
],
"separatorsToIndex": "_",
"synonyms": Array [
Array [
},
"indexSynonyms": Array [
Object {
"objectID": "underscore",
"synonyms": Array [
"_",
"underscore",
],
],
},
"type": "synonym",
},
],
"maxObjSize": 450000,
"npmDownloadsEndpoint": "https://api.npmjs.org/downloads",
"npmRegistryEndpoint": "https://replicate.npmjs.com/registry",
Expand Down
23 changes: 22 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,30 @@ const defaultConfig = {
],
optionalWords: ['js', 'javascript'],
separatorsToIndex: '_',
synonyms: [['_', 'underscore']],
replaceSynonymsInHighlight: false,
},
indexSynonyms: [
{
type: 'synonym',
synonyms: ['_', 'underscore'],
objectID: 'underscore',
},
],
indexRules: [
{
objectID: 'promote-exact',
description: 'promote exact matches',
condition: {
pattern: '{facet:concatenatedName}',
anchoring: 'is',
},
consequence: {
params: {
automaticOptionalFacetFilters: ['concatenatedName'],
},
},
},
],
};

export default Object.entries(defaultConfig).reduce(
Expand Down
17 changes: 14 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ const { index: mainIndex, client } = createAlgoliaIndex(c.indexName);
const { index: bootstrapIndex } = createAlgoliaIndex(c.bootstrapIndexName);
const stateManager = createStateManager(mainIndex);

mainIndex
.setSettings(c.indexSettings)
.then(({ taskID }) => mainIndex.waitTask(taskID))
setSettings(mainIndex)
.then(() => setSettings(bootstrapIndex))
.then(() => stateManager.check())
.then(bootstrap)
.then(() => stateManager.get())
Expand All @@ -35,6 +34,18 @@ mainIndex
.then(watch)
.catch(error);

async function setSettings(index) {
await index.setSettings(c.indexSettings);
await index.batchSynonyms(c.indexSynonyms, {
replaceExistingSynonyms: true,
});
const { taskID } = await index.batchRules(c.indexRules, {
replaceExistingRules: true,
});

return index.waitTask(taskID);
}

function infoChange(seq, nbChanges, emoji) {
return npm.info().then(npmInfo => {
const ratePerSecond = nbChanges / ((Date.now() - loopStart) / 1000);
Expand Down