Fix playlist search
authorChocobozzz <me@florianbigard.com>
Fri, 27 Dec 2019 08:04:04 +0000 (09:04 +0100)
committerChocobozzz <me@florianbigard.com>
Fri, 27 Dec 2019 08:04:04 +0000 (09:04 +0100)
server/models/video/video-playlist.ts
server/tests/api/videos/video-playlists.ts
shared/extra-utils/videos/video-playlists.ts

index ef87a7ee9586f757d7dc6ca9a67d9c1d8c7a3550..71a5802499ea1007461d2420f9faad6e95cefd9e 100644 (file)
@@ -13,11 +13,10 @@ import {
   Model,
   Scopes,
   Table,
-  UpdatedAt,
-  Sequelize
+  UpdatedAt
 } from 'sequelize-typescript'
 import { VideoPlaylistPrivacy } from '../../../shared/models/videos/playlist/video-playlist-privacy.model'
-import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid, createSimilarityAttribute } from '../utils'
+import { buildServerIdsFollowedBy, buildWhereIdOrUUID, getSort, isOutdated, throwIfNotValid } from '../utils'
 import {
   isVideoPlaylistDescriptionValid,
   isVideoPlaylistNameValid,
@@ -46,7 +45,8 @@ import { ActivityIconObject } from '../../../shared/models/activitypub/objects'
 import { FindOptions, literal, Op, ScopeOptions, Transaction, WhereOptions } from 'sequelize'
 import * as Bluebird from 'bluebird'
 import {
-  MVideoPlaylistAccountThumbnail, MVideoPlaylistAP,
+  MVideoPlaylistAccountThumbnail,
+  MVideoPlaylistAP,
   MVideoPlaylistFormattable,
   MVideoPlaylistFull,
   MVideoPlaylistFullSummary,
@@ -166,18 +166,9 @@ type AvailableForListOptions = {
     }
 
     if (options.search) {
-      const escapedSearch = VideoPlaylistModel.sequelize.escape(options.search)
-      const escapedLikeSearch = VideoPlaylistModel.sequelize.escape('%' + options.search + '%')
       whereAnd.push({
-        id: {
-          [ Op.in ]: Sequelize.literal(
-            '(' +
-            'SELECT "videoPlaylist"."id" FROM "videoPlaylist" ' +
-            'WHERE ' +
-            'lower(immutable_unaccent("videoPlaylist"."name")) % lower(immutable_unaccent(' + escapedSearch + ')) OR ' +
-            'lower(immutable_unaccent("videoPlaylist"."name")) LIKE lower(immutable_unaccent(' + escapedLikeSearch + '))' +
-            ')'
-          )
+        name: {
+          [ Op.iLike ]: '%' + options.search + '%'
         }
       })
     }
index 424b217fb163149ef01cf4d828f57294b2215015..9fd48ac7c0b52a5bd971c19a69ab4ffc057965e2 100644 (file)
@@ -407,6 +407,25 @@ describe('Test video playlists', function () {
         expect(data).to.have.lengthOf(1)
         expect(data[ 0 ].displayName).to.equal('playlist 3')
       }
+
+      {
+        const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 0, 10, 'createdAt', '3')
+
+        expect(res.body.total).to.equal(1)
+
+        const data: VideoPlaylist[] = res.body.data
+        expect(data).to.have.lengthOf(1)
+        expect(data[ 0 ].displayName).to.equal('playlist 3')
+      }
+
+      {
+        const res = await getAccountPlaylistsList(servers[ 1 ].url, 'root', 0, 10, 'createdAt', '4')
+
+        expect(res.body.total).to.equal(0)
+
+        const data: VideoPlaylist[] = res.body.data
+        expect(data).to.have.lengthOf(0)
+      }
     })
 
     it('Should not list unlisted or private playlists', async function () {
index cbb073fbc5c927e87d9f540f793f52d7fc1f77c9..6762c59736596275560616aaaf833c92decbeea9 100644 (file)
@@ -45,13 +45,14 @@ function getVideoChannelPlaylistsList (url: string, videoChannelName: string, st
   })
 }
 
-function getAccountPlaylistsList (url: string, accountName: string, start: number, count: number, sort?: string) {
+function getAccountPlaylistsList (url: string, accountName: string, start: number, count: number, sort?: string, search?: string) {
   const path = '/api/v1/accounts/' + accountName + '/video-playlists'
 
   const query = {
     start,
     count,
-    sort
+    sort,
+    search
   }
 
   return makeGetRequest({