レコード抽出ツール
非公式ベータ版翻訳
このページは PageTurner AI で翻訳されました(ベータ版)。プロジェクト公式の承認はありません。 エラーを見つけましたか? 問題を報告 →
はじめに
情報
このドキュメントでは helpers.docsearch メソッドに関する情報のみを扱います。Algolia Crawler の詳細については Algolia Crawler ドキュメント を参照してください。
ページは recordExtractor によって抽出されます。これらの抽出ツールは recordExtractor パラメータを介して actions に割り当てられます。このパラメータは、インデックス化したいデータを JSON オブジェクトの配列として整理して返す関数を指します。
ヘルパーはコンテンツ抽出と Algolia レコード生成を支援する関数群です
役立つリンク
使用方法
DocSearch ヘルパーを使用する最も一般的な方法は、その結果を recordExtractor 関数に返すことです。
recordExtractor: ({ helpers }) => {
return helpers.docsearch({
recordProps: {
lvl0: {
selectors: "header h1",
},
lvl1: "article h2",
lvl2: "article h3",
lvl3: "article h4",
lvl4: "article h5",
lvl5: "article h6",
content: "main p, main li",
},
});
},
Cheerio を使用した DOM 操作
Cheerio instance ($) を使用すると DOM を操作できます:
recordExtractor: ({ $, helpers }) => {
// Removing DOM elements we don't want to crawl
$(".my-warning-message").remove();
return helpers.docsearch({
recordProps: {
lvl0: {
selectors: "header h1",
},
lvl1: "article h2",
lvl2: "article h3",
lvl3: "article h4",
lvl4: "article h5",
lvl5: "article h6",
content: "main p, main li",
},
});
},
フォールバックセレクタの指定
一部のページに存在しない可能性のあるコンテンツを取得する場合、フォールバックセレクタが役立ちます:
recordExtractor: ({ $, helpers }) => {
return helpers.docsearch({
recordProps: {
// `.exists h1` will be selected if `.exists-probably h1` does not exists.
lvl0: {
selectors: [".exists-probably h1", ".exists h1"],
},
lvl1: "article h2",
lvl2: "article h3",
lvl3: "article h4",
lvl4: "article h5",
lvl5: "article h6",
// `.exists p, .exists li` will be selected.
content: [
".does-not-exists p, .does-not-exists li",
".exists p, .exists li",
],
},
});
},
生テキストの提供 (defaultValue)
このオプションは lvl0 と カスタム変数 セレクタでのみサポートされています
検索結果をウェブサイトとは異なる構造にしたい場合や、存在しない可能性のあるセレクタに defaultValue を提供したい場合があります:
recordExtractor: ({ $, helpers }) => {
return helpers.docsearch({
recordProps: {
lvl0: {
// It also supports the fallback DOM selectors syntax!
selectors: ".exists-probably h1",
defaultValue: "myRawTextIfDoesNotExists",
},
lvl1: "article h2",
lvl2: "article h3",
lvl3: "article h4",
lvl4: "article h5",
lvl5: "article h6",
content: "main p, main li",
// The variables below can be used to filter your search
language: {
// It also supports the fallback DOM selectors syntax!
selectors: ".exists-probably .language",
// Since custom variables are used for filtering, we allow sending
// multiple raw values
defaultValue: ["en", "en-US"],
},
},
});
},