当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript algoliasearch类代码示例

本文整理汇总了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 })
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:58,代码来源:configureAlgolia.ts

示例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()
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:72,代码来源:indexChartsToAlgolia.ts

示例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, () => {});
开发者ID:Rick-Kirkham,项目名称:DefinitelyTyped,代码行数:31,代码来源:algoliasearch-tests.ts

示例4: getClient

function getClient() {
    if (!algolia)
        algolia = algoliasearch(ALGOLIA_ID, ALGOLIA_SEARCH_KEY)
    return algolia
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:5,代码来源:siteSearch.ts

示例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) => {});
开发者ID:AdaskoTheBeAsT,项目名称:DefinitelyTyped,代码行数:30,代码来源:algoliasearch-tests.ts

示例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},
开发者ID:csrakowski,项目名称:DefinitelyTyped,代码行数:31,代码来源:algoliasearch-helper-tests.ts

示例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) => {});
开发者ID:ChanceM,项目名称:DefinitelyTyped,代码行数:30,代码来源:algoliasearch-tests.ts

示例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);
开发者ID:wxyyxc1992,项目名称:ConfigurableAPIServer,代码行数:24,代码来源:build-index.ts

示例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()
}
开发者ID:OurWorldInData,项目名称:owid-grapher,代码行数:73,代码来源:indexToAlgolia.ts

示例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;
开发者ID:kevmo314,项目名称:canigraduate.uchicago.edu,代码行数:31,代码来源:indexes-worker.ts


注:本文中的algoliasearch类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。