Add "language" to postgres
This commit is contained in:
parent
997449ab4b
commit
6b5c9cfaf1
2 changed files with 14 additions and 5 deletions
|
@ -51,6 +51,7 @@ class Video
|
|||
wilson_score: Float64,
|
||||
published: Time,
|
||||
description: String,
|
||||
language: String?,
|
||||
})
|
||||
end
|
||||
|
||||
|
@ -171,7 +172,7 @@ def fetch_video(id, client)
|
|||
end
|
||||
end
|
||||
|
||||
video = Video.new(id, info, Time.now, title, views, likes, dislikes, wilson_score, published, description)
|
||||
video = Video.new(id, info, Time.now, title, views, likes, dislikes, wilson_score, published, description, nil)
|
||||
|
||||
return video
|
||||
end
|
||||
|
@ -261,12 +262,19 @@ def rank_videos(db, n, pool, filter)
|
|||
video = get_video(id, client, db)
|
||||
pool << client
|
||||
|
||||
if video.language
|
||||
language = video.language
|
||||
else
|
||||
description = XML.parse(video.description)
|
||||
content = [video.title, description.content].join(" ")
|
||||
|
||||
results = DetectLanguage.detect(content)
|
||||
language = results[0].language
|
||||
|
||||
if results[0].language == "en"
|
||||
db.exec("UPDATE videos SET language = $1 WHERE id = $2", language, id)
|
||||
end
|
||||
|
||||
if language == "en"
|
||||
language_list << id
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,6 +12,7 @@ CREATE TABLE public.videos
|
|||
wilson_score double precision,
|
||||
published timestamp with time zone,
|
||||
description text COLLATE pg_catalog."default",
|
||||
language text COLLATE pg_catalog."default",
|
||||
CONSTRAINT videos_pkey PRIMARY KEY (id)
|
||||
)
|
||||
WITH (
|
||||
|
|
Loading…
Reference in a new issue