本文整理匯總了TypeScript中algoliasearch類的典型用法代碼示例。如果您正苦於以下問題:TypeScript algoliasearch類的具體用法?TypeScript algoliasearch怎麽用?TypeScript algoliasearch使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了algoliasearch類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: configureAlgolia
export async function configureAlgolia() {
const client = algoliasearch(ALGOLIA_ID, ALGOLIA_SECRET_KEY)
const chartsIndex = client.initIndex('charts')
await chartsIndex.setSettings({
searchableAttributes: ["unordered(title)", "unordered(variantName)", "unordered(subtitle)", "unordered(_tags)", "unordered(availableEntities)"],
ranking: ["exact", "typo", "attribute", "words", "proximity", "custom"],
customRanking: ["asc(numDimensions)", "asc(titleLength)"],
attributesToSnippet: ["subtitle:24"],
attributeForDistinct: 'id',
alternativesAsExact: ["ignorePlurals", "singleWordSynonym", "multiWordsSynonym"],
exactOnSingleWordQuery: 'none',
disableExactOnAttributes: ['_tags'],
optionalWords: ['vs'],
removeStopWords: ['en']
})
const pagesIndex = client.initIndex('pages')
await pagesIndex.setSettings({
searchableAttributes: ["unordered(title)", "unordered(content)", "unordered(_tags)", "unordered(authors)"],
ranking: ["exact", "typo", "attribute", "words", "proximity", "custom"],
customRanking: ["desc(importance)"],
attributesToSnippet: ["content:24"],
attributeForDistinct: 'slug',
alternativesAsExact: ["ignorePlurals", "singleWordSynonym", "multiWordsSynonym"],
attributesForFaceting: ['searchable(_tags)', 'searchable(authors)'],
exactOnSingleWordQuery: 'none',
disableExactOnAttributes: ['_tags'],
removeStopWords: ['en']
})
const synonyms = [
['kids', 'children'],
['pork', 'pigmeat'],
['atomic', 'nuclear'],
['pop', 'population'],
['cheese', 'dairy']
]
// Send all our country variant names to algolia as synonyms
for (const country of countries) {
if (country.variantNames) {
synonyms.push([country.name].concat(country.variantNames))
}
}
const algoliaSynonyms = synonyms.map(s => {
return {
objectID: s.join("-"),
type: 'synonym',
synonyms: s
} as algoliasearch.Synonym
})
await pagesIndex.batchSynonyms(algoliaSynonyms, { replaceExistingSynonyms: true })
await chartsIndex.batchSynonyms(algoliaSynonyms, { replaceExistingSynonyms: true })
}
示例2: indexChartsToAlgolia
async function indexChartsToAlgolia() {
await configureAlgolia()
const allCharts = await db.query(`
SELECT id, publishedAt, updatedAt, JSON_LENGTH(config->"$.dimensions") AS numDimensions, config->>"$.type" AS type, config->>"$.slug" AS slug, config->>"$.title" AS title, config->>"$.subtitle" AS subtitle, config->>"$.variantName" AS variantName, config->>"$.data.availableEntities" as availableEntitiesStr
FROM charts
WHERE publishedAt IS NOT NULL
AND is_indexable IS TRUE
`)
const chartTags = await db.query(`
SELECT ct.chartId, ct.tagId, t.name as tagName FROM chart_tags ct
JOIN charts c ON c.id=ct.chartId
JOIN tags t ON t.id=ct.tagId
`)
for (const c of allCharts) {
c.tags = []
}
const chartsById = _.keyBy(allCharts, c => c.id)
const chartsToIndex = []
for (const ct of chartTags) {
const c = chartsById[ct.chartId]
if (c) {
c.tags.push({ id: ct.tagId, name: ct.tagName })
chartsToIndex.push(c)
}
}
const client = algoliasearch(ALGOLIA_ID, ALGOLIA_SECRET_KEY)
const finalIndex = await client.initIndex('charts')
const tmpIndex = await client.initIndex('charts_tmp')
await client.copyIndex(finalIndex.indexName, tmpIndex.indexName, [
'settings',
'synonyms',
'rules'
])
const records = []
for (const c of chartsToIndex) {
if (!c.tags) continue
records.push({
objectID: c.id,
chartId: c.id,
slug: c.slug,
title: c.title,
variantName: c.variantName,
subtitle: c.subtitle,
_tags: c.tags.map((t: any) => t.name),
availableEntities: JSON.parse(c.availableEntitiesStr),
publishedAt: c.publishedAt,
updatedAt: c.updatedAt,
numDimensions: parseInt(c.numDimensions),
titleLength: c.title.length
})
}
console.log(records.length)
await tmpIndex.saveObjects(records)
await client.moveIndex(tmpIndex.indexName, finalIndex.indexName);
// for (let i = 0; i < records.length; i += 1000) {
// console.log(i)
// await index.saveObjects(records.slice(i, i+1000))
// }
await db.end()
}
示例3: algoliasearch
exactOnSingleWordQuery: '',
alternativesAsExact: true,
distinct: 0,
getRankingInfo: false,
numericAttributesToIndex: [''],
numericFilters: [''],
tagFilters: '',
facetFilters: '',
analytics: false,
analyticsTags: [''],
synonyms: true,
replaceSynonymsInHighlight: false,
minProximity: 0,
};
let client: Client = algoliasearch('', '');
let index: Index = client.initIndex('');
let search = index.search({ query: '' });
index.search({ query: '' }, (err, res) => {});
// partialUpdateObject
index.partialUpdateObject({}, () => {});
index.partialUpdateObject({}, false, () => {});
index.partialUpdateObject({}).then(() => {});
index.partialUpdateObject({}, false).then(() => {});
// partialUpdateObjects
index.partialUpdateObjects([{}], () => {});
index.partialUpdateObjects([{}], false, () => {});
示例4: getClient
function getClient() {
if (!algolia)
algolia = algoliasearch(ALGOLIA_ID, ALGOLIA_SEARCH_KEY)
return algolia
}
示例5: algoliasearch
aroundRadius: 0,
aroundPrecision: 0,
minimumAroundRadius: 0,
insideBoundingBox: [[0]],
queryType: '',
insidePolygon: [[0]],
removeWordsIfNoResults: '',
advancedSyntax: false,
optionalWords: [''],
removeStopWords: [''],
disableExactOnAttributes: [''],
exactOnSingleWordQuery: '',
alternativesAsExact: true,
distinct: 0,
getRankingInfo: false,
numericAttributesToIndex: [''],
numericFilters: [''],
tagFilters: '',
facetFilters: '',
analytics: false,
analyticsTags: [''],
synonyms: true,
replaceSynonymsInHighlight: false,
minProximity: 0,
};
let index: AlgoliaIndex = algoliasearch('', '').initIndex('');
let search = index.search({ query: '' });
index.search({ query: '' }, (err, res) => {});
示例6: algoliasearch
import * as algoliasearch from 'algoliasearch';
import * as algoliasearchHelper from 'algoliasearch-helper';
// tslint:disable-next-line:no-duplicate-imports
import { SearchResults, SearchParameters } from 'algoliasearch-helper';
// https://community.algolia.com/algoliasearch-helper-js/reference.html#module:algoliasearchHelper
const client = algoliasearch('latency', '6be0576ff61c053d5f9a3225e2a90f76');
const helper = algoliasearchHelper(client, 'bestbuy', {
facets: ['shipping'],
disjunctiveFacets: ['category']
});
helper.on('result', (result) => {
console.log(result);
});
helper.toggleRefine('Movies & TV Shows')
.toggleRefine('Free shipping')
.search();
const updateTheResult = (results: SearchResults, state: SearchParameters) => {
console.log(results, state);
};
helper.on('result', updateTheResult);
helper.once('result', updateTheResult);
helper.removeListener('result', updateTheResult);
helper.removeAllListeners('result');
() => {
// Changing the number of records returned per page to 1
// This example uses the callback API
const state = helper.searchOnce({hitsPerPage: 1},
示例7: algoliasearch
aroundRadius: "",
aroundPrecision: 0,
minimumAroundRadius: 0,
insideBoundingBox: "",
queryType: "",
insidePolygon: "",
removeWordsIfNoResults: "",
advancedSyntax: false,
optionalWords: [""],
removeStopWords: [""],
disableExactOnAttributes: [""],
exactOnSingleWordQuery: "",
alternativesAsExact: true,
distinct: 0,
getRankingInfo: false,
numericAttributesToIndex: [""],
numericFilters: [""],
tagFilters: "",
facetFilters: "",
analytics: false,
analyticsTags: [""],
synonyms: true,
replaceSynonymsInHighlight: false,
minProximity: 0,
};
let index: AlgoliaIndex = algoliasearch("", "").initIndex("");
let search = index.search({query: ""});
index.search({query: ""}, (err, res) => {});
示例8: require
import * as algoliasearch from 'algoliasearch';
const program = require('commander');
import { ALGOLIA_ADMIN_API_KEY } from './../config/private';
import { buildDocIndex } from '../service/index/buildDocIndex';
import { buildLinkIndex } from '../service/index/buildLinkIndex';
const client = algoliasearch('35UOMI84K6', ALGOLIA_ADMIN_API_KEY);
program
.command('doc')
.description('index docs from several repos')
.action(async function() {
await buildDocIndex(client);
});
program
.command('link')
.description('index links from Awesome Links')
.action(async function() {
await buildLinkIndex(client);
});
program.parse(process.argv);
示例9: indexToAlgolia
async function indexToAlgolia() {
const client = algoliasearch(ALGOLIA_ID, ALGOLIA_SECRET_KEY)
const finalIndex = await client.initIndex('pages')
const tmpIndex = await client.initIndex('pages_tmp')
// Copy to a temporary index which we will then update
// This is so we can do idempotent reindexing
await client.copyIndex(finalIndex.indexName, tmpIndex.indexName, [
'settings',
'synonyms',
'rules'
])
const rows = await wpdb.query(`SELECT * FROM wp_posts WHERE (post_type='post' OR post_type='page') AND post_status='publish'`)
const records = []
for (const country of countries) {
records.push({
objectID: country.slug,
type: 'country',
slug: country.slug,
title: country.name,
content: `All available indicators for ${country.name}.`
})
}
for (const row of rows) {
const rawPost = await wpdb.getFullPost(row)
const post = await formatPost(rawPost, { footnotes: false })
const postText = htmlToPlaintext(post.html)
const chunks = chunkParagraphs(postText, 1000)
const tags = await getPostTags(post.id)
const postType = getPostType(post, tags)
let importance = 0
if (postType === 'entry')
importance = 3
else if (postType === 'explainer')
importance = 2
else if (postType === 'fact')
importance = 1
let i = 0
for (const c of chunks) {
records.push({
objectID: `${row.ID}-c${i}`,
postId: post.id,
type: postType,
slug: post.slug,
title: post.title,
excerpt: post.excerpt,
authors: post.authors,
date: post.date,
modifiedDate: post.modifiedDate,
content: c,
_tags: tags.map(t => t.name),
importance: importance
})
i += 1
}
}
for (let i = 0; i < records.length; i += 1000) {
await tmpIndex.saveObjects(records.slice(i, i+1000))
}
await client.moveIndex(tmpIndex.indexName, finalIndex.indexName);
await wpdb.end()
await db.end()
}
示例10: fromEvent
const ctx: Worker = self as any;
const messages$ = fromEvent(ctx, "message").pipe(
map((x: any) => x.data as WorkerMessage)
);
const institutionData$ = messages$.pipe(
filter(message => message.command == WorkerCommand.SET_INSTITUTION),
map(message => {
return message.data as InstitutionData;
}),
publishReplay(1),
refCount()
);
const algolia = algoliasearch("BF6BT6JP9W", "52677be23c182ca96eb2ccfd7c9c459f");
const indexes$ = institutionData$.pipe(
switchMap(institution => {
const algoliaIndex = algolia.initIndex(institution.algoliaIndex);
return defer(() => Axios.get(institution.indexesUrl)).pipe(
map(response => new Indexes(response.data))
);
}),
publishReplay(1),
refCount()
);
export interface FilterState {
query: string;
periods: number[];
days: any;