(1)
CREATE TEMP TABLE temp_dialer_search_table AS SELECT * FROM dialer_search WHERE is_visiable=1
(2)
CREATE TEMP TABLE temp_dialer_search_view AS SELECT _id,vds_contact_id,vds_raw_contact_id,vds_name_id,vds_call_date,vds_call_log_id,vds_call_type,vds_geocoded_location,vds_sim_id,vds_vtcall,vds_phone_number,vds_phone_type,vds_lookup,vds_photo_id,vds_starred,vds_indicate_phone_sim,vds_is_sdn_contact,vds_name,vds_sort_key FROM view_dialer_search
(3)
SELECT _id,vds_contact_id,vds_call_date,vds_call_log_id,vds_call_type,vds_geocoded_location,vds_sim_id,vds_vtcall,vds_indicate_phone_sim,vds_starred,vds_photo_id,vds_phone_type,vds_name,vds_phone_number,vds_lookup,vds_is_sdn_contact FROM (SELECT _id,vds_contact_id,vds_call_date,vds_call_log_id,vds_call_type,vds_geocoded_location,vds_sim_id,vds_vtcall,vds_indicate_phone_sim,vds_starred,vds_photo_id,vds_phone_type,vds_name,vds_phone_number,vds_lookup,vds_is_sdn_contact, vds_raw_contact_id FROM temp_dialer_search_view WHERE vds_call_log_id > 0 ORDER BY vds_call_date ) GROUP BY vds_raw_contact_id ORDER BY vds_call_date DESC
CREATE TEMP TABLE IF NOT EXISTS temp_dialer_search_table AS SELECT _id AS temp_id,name_type AS name_type,raw_contact_id AS temp_raw_contact_id,normalized_name AS normalized_name,search_data_offsets AS search_data_offsets,DIALER_SEARCH_MATCH(normalized_name,search_data_offsets,name_type,'5') AS matched_data_offsets
FROM temp_dialer_search_table WHERE DIALER_SEARCH_MATCH_FILTER(normalized_name,search_data_offsets,name_type,'5')
CREATE TEMP TABLE IF NOT EXISTS temp_dialer_search_view AS
SELECT _id,vds_contact_id,vds_raw_contact_id,vds_name,vds_call_date,vds_call_log_id,vds_call_type,vds_geocoded_location,vds_sim_id,vds_vtcall,vds_phone_number,vds_phone_type,vds_lookup,vds_photo_id,vds_starred,vds_indicate_phone_sim,vds_sort_key,vds_name_id,vds_is_sdn_contact, table_number.matched_data_offsets AS matched_data_offsets,
table_name.matched_data_offsets AS matched_name_offsets
FROM
(SELECT *
FROM temp_dialer_search_view
WHERE vds_raw_contact_id
IN (SELECT temp_raw_contact_id FROM temp_dialer_search_table1)) AS temp_base_view
LEFT JOIN temp_dialer_search_table1 AS table_number ON table_number.temp_id = temp_base_view._id AND table_number.name_type = 8
LEFT JOIN temp_dialer_search_table1 AS table_name ON table_name.temp_id = temp_base_view.vds_name_id AND table_name.name_type = 11
ORDER BY vds_raw_contact_id,table_number.name_type,vds_call_date
SELECT _id,vds_contact_id,vds_call_date,vds_call_log_id,vds_call_type,vds_geocoded_location,vds_sim_id,vds_vtcall,vds_indicate_phone_sim,vds_starred,vds_photo_id,vds_phone_type,vds_name,vds_phone_number,vds_lookup,vds_is_sdn_contact,matched_data_offsets,matched_name_offsets FROM temp_dialer_search_view1
ORDER BY vds_call_date ASC,vds_sort_key COLLATE NOCASE