Showing posts with label json. Show all posts
Showing posts with label json. Show all posts

MYSQL REGEXP / NOT REGEXP multiple JSON fields


Futzing around with personal projects. Trying to stay relevant. This particular project makes use of JSON support on mysql.

I know right? I did it anyways.

The following clause was used as filter:

Select
.… 
AND
(
LOWER( json_unquote(cd.data->'$.title') ) REGEXP ? OR
LOWER( json_unquote(cd.data->'$.title.$t') ) REGEXP ? OR
...
)
AND
(
LOWER( json_unquote(cd.data->'$.title') ) NOT REGEXP ? OR
LOWER( json_unquote(cd.data->'$.title.$t') ) NOT REGEXP ? OR 
...
)

But that was not not performing as expected. After some trial and error. The following solution seems to work best. concat_ws the fields into a string.

Select
....
AND
CONCAT_WS(' ',
    LOWER( cd.data->'$.text' ),
    LOWER( cd.data->'$.text.$t' )
) REGEXP ?
AND
CONCAT_WS(' ',
    LOWER( cd.data->'$.text' ),
    LOWER( cd.data->'$.text.$t' )
) NOT REGEXP ?

Can’t speak for efficiency but is working as expected so far.
Hope you find useful.

Mysql Reminder - A Delete Duplicates that works fast.

Note to self. Deleting dupes

This takes forever:

SET SQL_SAFE_UPDATES=0;
DELETE a 
FROM 
 tbl1.tbl_data as a, 
    tbl1.tbl_data as b
where 
 json_unquote(a.data->'$.text') = json_unquote(b.data->'$.text')  
AND 
 a.updated < b.updated;    
SET SQL_SAFE_UPDATES=1;



This Gem Works well.

SET SQL_SAFE_UPDATES=0;
 DELETE tbl_data from tbl_data
  inner join (
     select max(updated) as lastupdated, data->'$.text' as text
       from tbl_data
      group by text
     having count(*) > 1) duplic on duplic.text = data->'$.text'
  where updated < duplic.lastupdated;
SET SQL_SAFE_UPDATES=1;

goBloggerCrawler Blogger Web Crawler in Go

Go-based web crawler used to efficiently extract structured data (titles, video URLs, and tags) from Google Blogger sites using concurrent p...