当前位置:网站首页>RTMP streaming protocol live video on demand platform / face recognition system easydss customized tag retrieval function to retrieve data errors

RTMP streaming protocol live video on demand platform / face recognition system easydss customized tag retrieval function to retrieve data errors

2020-12-06 09:42:46 osc_ 0sqf9hqy

In years of video solution development ,TSINGSEE Qingxi video R & D team has encountered a lot of projects with customized requirements for products , We will also try our best to modify the products according to the needs of users .

stay EasyDSS In the customization project of , Customers put forward the demand to add tag search function , We add this feature and test it , It is found that the query data does not match the data retrieved on demand . For example, there are the following data in the database , Inquire about shared by true, And the label is “ All over the world ” Or the label is “ love ” , Only two pieces of data should be found , But three pieces of data were actually found .

64.png

Write test data , And test code . Query the database command issued by the background for :

SELECT * FROM "vod_files"  WHERE (dir_id = 'Cuwb2D2MR') AND (shared = '1') AND (labels like '% love ;%') OR (labels like '% All over the world ;%') ORDER BY update_at desc LIMIT 10 OFFSET 0

Check this command , Found that the order of the command query is incorrect , The correct order should be as follows :

SELECT * FROM "vod_files"  WHERE (dir_id = 'Cuwb2D2MR') AND (shared = '1') AND ((labels like '% love ;%') OR (labels like '% All over the world ;%')) ORDER BY update_at desc LIMIT 10 OFFSET 0

The point is that (labels like ‘% love ;%’) OR (labels like ‘% All over the world ;%’) This sentence , Brackets should be added , Otherwise, the result of the query is that all tags are “ All over the world ” The data of the .

Look at the code , About like The command for is the following code :

labelArr := estring.ArrayStrToArray(labels)
for _, label := range *labelArr {
   ors = append(ors, "labels like '%" + label + ";%'")
}

The above code will all like Statement placed in or in , So there's a problem , That is, the code generated at the bottom is :

db.Where("labels like '% love ;%'").Or("labels like '% All over the world ;%'")

Modify the code as follows :

labelArr := estring.ArrayStrToArray(labels)
labelLike := ""
for index, label := range *labelArr {
   if index > 0 {
      labelLike = labelLike + " OR "
   }
   labelLike = labelLike + "labels like '%" + label + ";%'"
}
if labelLike != consts.EmptyString {
   wheres = append(wheres, labelLike)
}

The code generated by this code is

db.Where("labels like '% love ;%' OR labels like '% All over the world ;%'")

This generated code will (labels like ‘% love ;%’) OR (labels like ‘% All over the world ;%’) Add a bracket to the outside , So right .

The final test query result is 2 Data , Solve this problem . Here is a partial screenshot of the returned data ,total For the total number of queries .

65.png

版权声明
本文为[osc_ 0sqf9hqy]所创,转载请带上原文链接,感谢
https://chowdera.com/2020/12/202012060941411462.html