Skip to content

Commit

Permalink
Merge pull request #89 from meilisearch/add-config-file-support-on-do…
Browse files Browse the repository at this point in the history
…cssearch

Add config file support on docssearch strategy
  • Loading branch information
tpayet authored Jan 31, 2024
2 parents 6140261 + a8ffcf7 commit d12a41f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export class Crawler {

this.scraper =
this.config.strategy == 'docssearch'
? new DocsearchScraper(this.sender)
? new DocsearchScraper(this.sender, this.config)
: this.config.strategy == 'schema'
? new SchemaScraper(this.sender, this.config)
: new DefaultScraper(this.sender, this.config)
Expand Down
18 changes: 15 additions & 3 deletions src/scrapers/docssearch.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { v4 as uuidv4 } from 'uuid'
import { Sender } from '../sender'
import { Config } from '../types'
import { Page } from 'puppeteer'
import {
DocsSearchDocument,
Expand Down Expand Up @@ -34,11 +35,14 @@ const TAG_LEVELS: Record<HTag, number> = {

export default class DocsearchScaper {
sender: Sender
settings: Config['meilisearch_settings']

constructor(sender: Sender) {
constructor(sender: Sender, config?: Config) {
console.info('DocsearchScaper::constructor')
this.sender = sender
void this.sender.updateSettings({

// Predefined settings
const defaultSettings = {
distinctAttribute: 'url',
rankingRules: [
'words',
Expand All @@ -65,7 +69,15 @@ export default class DocsearchScaper {
'hierarchy_lvl0',
'content',
],
})
}

// Merge user-defined settings with predefined settings
this.settings = {
...defaultSettings,
...(config?.meilisearch_settings || {}),
}

void this.sender.updateSettings(this.settings)
}

_amount_of_hierarchies(pageMap: DocsSearchDocument) {
Expand Down

0 comments on commit d12a41f

Please sign in to comment.