@@ -5,30 +5,36 @@ import {
5
5
DocumentCollatorFactory ,
6
6
IndexableDocument ,
7
7
} from '@backstage/plugin-search-common' ;
8
- import fetch from 'node-fetch' ;
8
+ import { PluginDatabaseManager } from '@backstage/backend-common' ;
9
+ import { DatabaseQetaStore } from '../../database' ;
9
10
10
11
export type QetaCollatorFactoryOptions = {
11
12
logger : Logger ;
13
+ database : PluginDatabaseManager ;
12
14
} ;
13
15
14
16
export type QetaDocument = IndexableDocument & {
15
17
tags ?: string [ ] ;
16
18
components ?: string [ ] ;
17
19
author : string ;
18
20
views : number ;
21
+ score : number ;
19
22
answersCount : number ;
23
+ created : Date ;
24
+ updatedBy ?: string ;
25
+ updated ?: Date ;
20
26
} ;
21
27
22
28
export class QetaCollatorFactory implements DocumentCollatorFactory {
23
- private readonly appBaseUrl : string ;
24
- private readonly backendBaseUrl : string ;
25
29
private readonly logger : Logger ;
30
+ private readonly database : PluginDatabaseManager ;
31
+ private readonly appBaseUrl : string ;
26
32
public readonly type : string = 'qeta' ;
27
33
28
34
private constructor ( config : Config , options : QetaCollatorFactoryOptions ) {
29
35
this . logger = options . logger ;
36
+ this . database = options . database ;
30
37
this . appBaseUrl = config . getString ( 'app.baseUrl' ) ;
31
- this . backendBaseUrl = config . getString ( 'backend.baseUrl' ) ;
32
38
}
33
39
34
40
static fromConfig ( config : Config , options : QetaCollatorFactoryOptions ) {
@@ -41,13 +47,17 @@ export class QetaCollatorFactory implements DocumentCollatorFactory {
41
47
42
48
async * execute ( ) : AsyncGenerator < QetaDocument > {
43
49
this . logger . info ( 'Executing QetaCollator' ) ;
44
- const response = await fetch (
45
- `${ this . backendBaseUrl } /api/qeta/questions?includeAnswers=true&includeComponents=true` ,
46
- ) ;
47
- const data = await response . json ( ) ;
48
- this . logger . info ( `Found ${ data . questions . length } questions to index` ) ;
50
+ const db = await DatabaseQetaStore . create ( {
51
+ database : this . database ,
52
+ skipMigrations : true ,
53
+ } ) ;
54
+
55
+ const questions = await db . getQuestions ( {
56
+ includeAnswers : true ,
57
+ includeComponents : true ,
58
+ } ) ;
49
59
50
- for ( const question of data . questions ) {
60
+ for ( const question of questions . questions ) {
51
61
yield {
52
62
...question ,
53
63
text : question . content ,
0 commit comments