2024-01-03 22:03:30 +00:00
'use strict' ;
const config = require ( 'config' ) ;
const manticore = require ( 'manticoresearch' ) ;
const args = require ( 'yargs' ) . argv ;
const knex = require ( '../knex' ) ;
const mantiClient = new manticore . ApiClient ( ) ;
mantiClient . basePath = ` http:// ${ config . database . manticore . host } : ${ config . database . manticore . httpPort } ` ;
const searchApi = new manticore . SearchApi ( mantiClient ) ;
const utilsApi = new manticore . UtilsApi ( mantiClient ) ;
const indexApi = new manticore . IndexApi ( mantiClient ) ;
const update = args . update ;
async function fetchActors ( ) {
// manually select date of birth, otherwise it is retrieved in local timezone but interpreted as UTC...
const actors = await knex . raw ( `
2024-01-25 00:15:42 +00:00
SELECT
2024-03-14 23:57:28 +00:00
actors . * ,
2024-01-25 00:15:42 +00:00
actors _meta . * ,
date _of _birth AT TIME ZONE 'Europe/Amsterdam' AT TIME ZONE 'UTC' as dob
2024-03-14 23:57:28 +00:00
FROM actors
LEFT JOIN actors _meta ON actors _meta . actor _id = actors . id
2024-01-03 22:03:30 +00:00
` );
return actors . rows ;
}
async function init ( ) {
if ( update ) {
2024-03-14 23:57:28 +00:00
await utilsApi . sql ( 'drop table if exists actors' ) ;
2024-01-03 22:03:30 +00:00
await utilsApi . sql ( ` create table actors(
id int ,
name text ,
slug string ,
gender string ,
date _of _birth timestamp ,
country string ,
has _avatar bool ,
2024-03-24 03:23:55 +00:00
mass int ,
2024-01-03 22:03:30 +00:00
height int ,
cup string ,
natural _boobs int ,
penis _length int ,
2024-01-25 00:15:42 +00:00
penis _girth int ,
stashed int ,
scenes int
2024-01-03 22:03:30 +00:00
) ` );
const actors = await fetchActors ( ) ;
const docs = actors . map ( ( actor ) => ( {
insert : {
index : 'actors' ,
id : actor . id ,
doc : {
name : actor . name ,
slug : actor . slug ,
gender : actor . gender || undefined ,
date _of _birth : actor . dob ? Math . round ( actor . dob . getTime ( ) / 1000 ) : undefined ,
has _avatar : ! ! actor . avatar _media _id ,
country : actor . birth _country _alpha2 || undefined ,
height : actor . height || undefined ,
2024-03-24 03:23:55 +00:00
mass : actor . weight || undefined , // weight is a reserved keyword in manticore
2024-01-03 22:03:30 +00:00
cup : actor . cup || undefined ,
natural _boobs : actor . natural _boobs === null ? 0 : Number ( actor . natural _boobs ) + 1 , // manticore bool does not seem to support null, and we need three states for natural_boobs: yes, no and unknown
penis _length : actor . penis _length || undefined ,
penis _girth : actor . penis _girth || undefined ,
2024-01-25 00:15:42 +00:00
stashed : actor . stashed || 0 ,
scenes : actor . scenes || 0 ,
2024-01-03 22:03:30 +00:00
} ,
} ,
} ) ) ;
const data = await indexApi . bulk ( docs . map ( ( doc ) => JSON . stringify ( doc ) ) . join ( '\n' ) ) . catch ( ( error ) => {
console . log ( error ) ;
} ) ;
console . log ( 'data' , data ) ;
knex . destroy ( ) ;
return ;
}
const result = await searchApi . search ( {
index : 'actors' ,
query : {
equals : {
has _avatar : 1 ,
} ,
} ,
limit : 3 ,
sort : [ { slug : 'asc' } ] ,
} ) ;
console . log ( result ) ;
console . log ( result . hits ? . hits ) ;
knex . destroy ( ) ;
}
init ( ) ;