aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-06-15 14:58:39 +0200
committerChocobozzz <me@florianbigard.com>2020-06-15 15:04:51 +0200
commitff9c3d9b189a323c1da5fcee6178574481529225 (patch)
treea295beb0c221afb63002986124001a9f4ff318f2 /client/src/app/videos/recommendations/recent-videos-recommendation.service.ts
parent12e6b31486a45a56117dfbbebad8bae3d69f0556 (diff)
downloadPeerTube-ff9c3d9b189a323c1da5fcee6178574481529225.tar.gz
PeerTube-ff9c3d9b189a323c1da5fcee6178574481529225.tar.zst
PeerTube-ff9c3d9b189a323c1da5fcee6178574481529225.zip
Use local search for recommended videos
Diffstat (limited to 'client/src/app/videos/recommendations/recent-videos-recommendation.service.ts')
-rw-r--r--client/src/app/videos/recommendations/recent-videos-recommendation.service.ts28
1 files changed, 23 insertions, 5 deletions
diff --git a/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts b/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts
index a1e65c27c..f06c35f9a 100644
--- a/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts
+++ b/client/src/app/videos/recommendations/recent-videos-recommendation.service.ts
@@ -1,4 +1,4 @@
1import { Injectable } from '@angular/core' 1import { Injectable, OnInit } from '@angular/core'
2import { RecommendationService } from '@app/videos/recommendations/recommendations.service' 2import { RecommendationService } from '@app/videos/recommendations/recommendations.service'
3import { Video } from '@app/shared/video/video.model' 3import { Video } from '@app/shared/video/video.model'
4import { RecommendationInfo } from '@app/shared/video/recommendation-info.model' 4import { RecommendationInfo } from '@app/shared/video/recommendation-info.model'
@@ -7,6 +7,9 @@ import { map, switchMap } from 'rxjs/operators'
7import { Observable, of } from 'rxjs' 7import { Observable, of } from 'rxjs'
8import { SearchService } from '@app/search/search.service' 8import { SearchService } from '@app/search/search.service'
9import { AdvancedSearch } from '@app/search/advanced-search.model' 9import { AdvancedSearch } from '@app/search/advanced-search.model'
10import { ServerService } from '@app/core'
11import { ServerConfig } from '@shared/models'
12import { truncate } from 'lodash'
10 13
11/** 14/**
12 * Provides "recommendations" by providing the most recently uploaded videos. 15 * Provides "recommendations" by providing the most recently uploaded videos.
@@ -15,10 +18,18 @@ import { AdvancedSearch } from '@app/search/advanced-search.model'
15export class RecentVideosRecommendationService implements RecommendationService { 18export class RecentVideosRecommendationService implements RecommendationService {
16 readonly pageSize = 5 19 readonly pageSize = 5
17 20
21 private config: ServerConfig
22
18 constructor ( 23 constructor (
19 private videos: VideoService, 24 private videos: VideoService,
20 private searchService: SearchService 25 private searchService: SearchService,
21 ) { } 26 private serverService: ServerService
27 ) {
28 this.config = this.serverService.getTmpConfig()
29
30 this.serverService.getConfig()
31 .subscribe(config => this.config = config)
32 }
22 33
23 getRecommendations (recommendation: RecommendationInfo): Observable<Video[]> { 34 getRecommendations (recommendation: RecommendationInfo): Observable<Video[]> {
24 return this.fetchPage(1, recommendation) 35 return this.fetchPage(1, recommendation)
@@ -35,12 +46,19 @@ export class RecentVideosRecommendationService implements RecommendationService
35 const defaultSubscription = this.videos.getVideos({ videoPagination: pagination, sort: '-createdAt' }) 46 const defaultSubscription = this.videos.getVideos({ videoPagination: pagination, sort: '-createdAt' })
36 .pipe(map(v => v.data)) 47 .pipe(map(v => v.data))
37 48
38 if (!recommendation.tags || recommendation.tags.length === 0) return defaultSubscription 49 const tags = recommendation.tags
50 const searchIndexConfig = this.config.search.searchIndex
51 if (
52 !tags || tags.length === 0 ||
53 (searchIndexConfig.enabled === true && searchIndexConfig.disableLocalSearch === true)
54 ) {
55 return defaultSubscription
56 }
39 57
40 const params = { 58 const params = {
41 search: '', 59 search: '',
42 componentPagination: pagination, 60 componentPagination: pagination,
43 advancedSearch: new AdvancedSearch({ tagsOneOf: recommendation.tags.join(','), sort: '-createdAt' }) 61 advancedSearch: new AdvancedSearch({ tagsOneOf: recommendation.tags.join(','), sort: '-createdAt', searchTarget: 'local' })
44 } 62 }
45 63
46 return this.searchService.searchVideos(params) 64 return this.searchService.searchVideos(params)