{"id":670,"date":"2017-11-10T14:53:53","date_gmt":"2017-11-10T14:53:53","guid":{"rendered":"https:\/\/www.muratyaman.co.uk\/wp\/?p=670"},"modified":"2020-04-01T11:26:23","modified_gmt":"2020-04-01T10:26:23","slug":"poor-mans-full-text-search-for-suitecrm","status":"publish","type":"post","link":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/2017\/11\/poor-mans-full-text-search-for-suitecrm\/","title":{"rendered":"Poor man&#8217;s full text search for SuiteCRM"},"content":{"rendered":"<p>The poor man&#8217;s CRM, a.k.a SuiteCRM, is great (&#8230; was great for its time!); that&#8217;s another story.<\/p>\n<p>One of the features provided is &#8220;unified search&#8221;, as the geeks call it; some may call it global\/universal search across many tables and records in the database. What it does is simply as follows:<\/p>\n<ul>\n<li>Loop over a list of modules (e.g. accounts, contacts, opportunities, calls, meetings, notes, etc.)<\/li>\n<li>Search for records matching a phrase (entered by user) by looking at <b>all the fields<\/b><\/li>\n<li>List the records found under each module<\/li>\n<\/ul>\n<p>From technical point of view, their solution includes the following logic (e.g. using contact module).<\/p>\n<p>1. Create main query.<br \/>\n(source: include\/ListView\/listViewData.php function getListViewData())<\/p>\n<p><code lang=\"sql\"><br \/>\nSELECT t1.*, t2.*<br \/>\nFROM contacts t1<br \/>\nLEFT JOIN contacts_cstm t2 ON t1.id = t2.id_c<br \/>\nWHERE t1.deleted = 0 -- exclude soft-deleted records<br \/>\nAND (<br \/>\n(<br \/>\n   (t1.first_name LIKE 'john%')<br \/>\nOR (t1.last_name LIKE 'john%')<br \/>\n-- OR ... using other fields on both tables<br \/>\n)<br \/>\nORDER BY t1.date_modified DESC -- example<br \/>\nLIMIT 0, 10 -- first 10 records<br \/>\n<\/code><\/p>\n<p>2. Create list count query based on main query by removing ORDER BY and LIMIT clauses.<br \/>\n(source: data\/SugarBean.php function create_list_count_query())<\/p>\n<p><code lang=\"sql\"><br \/>\nSELEC COUNT(*) AS c FROM (<br \/>\n  -- main query here without ORDER BY and LIMIT clauses<br \/>\n)<br \/>\n<\/code><\/p>\n<p>3. Execute list count query and get the total number of records that would be retrieved by main query.<\/p>\n<p>4. Execute main query by using ORDER BY and LIMIT clauses.<br \/>\n(source: include\/database\/MysqlManager.php function limitQuery())<br \/>\nLoop over the records found, and prepare for display, which may require running additional queries to load related data such as user name of the user who created a selected record.<\/p>\n<p>There are two main issues with this common approach:<\/p>\n<p>A. Too many columns are selected unnecessarily from the tables.<\/p>\n<p>B. We execute more or less same query twice. So-called database abstraction layer and the logic that comes with it prevents us from using a powerful feature of MySQL:<\/p>\n<p><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/information-functions.html#function_found-rows\">function found_rows()<\/a><\/p>\n<p>We can modify the main query and inject the key SQL_CALC_FOUND_ROWS; e.g.<\/p>\n<p><code lang=\"sql\"><br \/>\nSELECT SQL_CALC_FOUND_ROWS t1.*, t2.*<br \/>\nFROM contacts t1<br \/>\nLEFT JOIN contacts_cstm t2 ON t1.id = t2.id_c<br \/>\nWHERE t1.deleted = 0 -- exclude soft-deleted records<br \/>\nAND (<br \/>\n   (t1.first_name LIKE 'john%')<br \/>\nOR (t1.last_name LIKE 'john%')<br \/>\n-- OR ... using other fields on both tables<br \/>\n)<br \/>\nORDER BY t1.date_modified DESC -- example<br \/>\nLIMIT 0, 10 -- first 10 records<br \/>\n<\/code><\/p>\n<p>After running this version, we can simply extract the <b>total<\/b> number of records found:<\/p>\n<p><code lang=\"sql\"><br \/>\nSELECT found_rows() AS total_records;<br \/>\n<\/code><\/p>\n<p>Obviously, this is very specific non-standard feature of MySQL. Still, I think the database abstraction layer should handle this requirement, and implement for each database management system supported.<\/p>\n<p>Next, I want to explain my implementation of global full text search with a simple scoring feature. Let&#8217;s start with a very simple example (&#8216;john smith&#8217; is search phrase):<\/p>\n<p><code lang=\"sql\"><br \/>\nSELECT * FROM (<br \/>\n  SELECT<br \/>\n    t1.*,<br \/>\n    LOWER(u.user_name) AS created_by_user_name,<br \/>\n    (<br \/>\n    IF(COALESCE(t1.first_name LIKE '%john%'), 1, 0) +<br \/>\n    IF(COALESCE(t1.last_name LIKE '%john%'), 1, 0) +<br \/>\n    IF(COALESCE(t1.first_name LIKE '%smith%'), 1, 0) +<br \/>\n    IF(COALESCE(t1.last_name LIKE '%smith%'), 1, 0) +<br \/>\n    ) AS score<br \/>\n  FROM contacts t1<br \/>\n  LEFT JOIN users u ON t1.created_by = u.id<br \/>\n  LEFT JOIN contacts_cstm t2 ON t1.id = t2.id_c<br \/>\n  WHERE t1.deleted = 0 -- exclude soft-deleted records<br \/>\n) q<br \/>\nWHERE 0 < score\nORDER BY score DESC, date_modified DESC\n<\/code><\/p>\n<p>The idea is this: for each word in the search phrase, create an expression for each column in both main table and custom table; if every match is 1 point; and we simple add the points to calculate an overall score. Then, we can order the records by score calculated in descending order. Also, we can favour the recently modified records when they have same score.<\/p>\n<p>Here is a real example when we search for 'jo smi ya 18':<\/p>\n<p><code lang=\"sql\"><br \/>\nSELECT * FROM (<br \/>\n  SELECT<br \/>\n    t1.*,<br \/>\n    LOWER(u.user_name) AS created_by_user_name,<br \/>\n    (<br \/>\nIF(COALESCE(t1.account_type, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.annual_revenue, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.assigned_user_id, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_city, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_country, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_postalcode, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_state, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_street, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.campaign_id, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.created_by, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.date_entered, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.date_modified, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.deleted, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.description, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.employees, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.id, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.industry, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.modified_user_id, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.name, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.ownership, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.parent_id, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.phone_alternate, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.phone_fax, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.phone_office, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.rating, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_city, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_country, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_postalcode, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_state, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_street, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.sic_code, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.ticker_symbol, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.website, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.client_overview_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.failures_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.headlines_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_account_bu_owner_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_account_feedback_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_account_overview_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_acc_feedback_last_updated_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_acc_overview_last_updated_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_additional_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_beds_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_business_relationship_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_bu_strategic_target_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_current_opportunities_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_current_opp_last_updated_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_curr_risks_last_updated_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_domain_note_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_existing_customer_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_financial_overview_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_fin_overview_last_updated_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_hidden_import_id_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_last_sync_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_owner_id_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_prev_number_of_won_opps_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_site_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_site_id_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_type_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_uep_e_strategic_account_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_unipart_current_risks_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_vision_statement_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_win_people_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.hubspot_id_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.id_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.jjwg_maps_address_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.jjwg_maps_geocode_status_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.jjwg_maps_lat_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.jjwg_maps_lng_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.opportunities_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.public_private_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.ref_code_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.registration_number_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.sector_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.sub_sector_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.success_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t2.threats_c, '') LIKE '%jo%', 1, 0) +<br \/>\nIF(COALESCE(t1.account_type, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.annual_revenue, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.assigned_user_id, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_city, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_country, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_postalcode, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_state, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_street, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.campaign_id, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.created_by, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.date_entered, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.date_modified, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.deleted, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.description, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.employees, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.id, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.industry, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.modified_user_id, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.name, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.ownership, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.parent_id, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.phone_alternate, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.phone_fax, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.phone_office, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.rating, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_city, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_country, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_postalcode, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_state, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_street, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.sic_code, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.ticker_symbol, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.website, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.client_overview_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.failures_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.headlines_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_account_bu_owner_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_account_feedback_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_account_overview_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_acc_feedback_last_updated_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_acc_overview_last_updated_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_additional_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_beds_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_business_relationship_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_bu_strategic_target_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_current_opportunities_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_current_opp_last_updated_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_curr_risks_last_updated_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_domain_note_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_existing_customer_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_financial_overview_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_fin_overview_last_updated_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_hidden_import_id_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_last_sync_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_owner_id_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_prev_number_of_won_opps_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_site_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_site_id_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_type_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_uep_e_strategic_account_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_unipart_current_risks_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_vision_statement_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_win_people_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.hubspot_id_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.id_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.jjwg_maps_address_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.jjwg_maps_geocode_status_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.jjwg_maps_lat_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.jjwg_maps_lng_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.opportunities_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.public_private_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.ref_code_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.registration_number_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.sector_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.sub_sector_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.success_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t2.threats_c, '') LIKE '%smi%', 1, 0) +<br \/>\nIF(COALESCE(t1.account_type, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.annual_revenue, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.assigned_user_id, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_city, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_country, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_postalcode, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_state, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_street, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.campaign_id, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.created_by, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.date_entered, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.date_modified, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.deleted, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.description, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.employees, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.id, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.industry, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.modified_user_id, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.name, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.ownership, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.parent_id, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.phone_alternate, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.phone_fax, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.phone_office, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.rating, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_city, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_country, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_postalcode, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_state, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_street, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.sic_code, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.ticker_symbol, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.website, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.client_overview_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.failures_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.headlines_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_account_bu_owner_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_account_feedback_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_account_overview_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_acc_feedback_last_updated_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_acc_overview_last_updated_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_additional_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_beds_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_business_relationship_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_bu_strategic_target_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_current_opportunities_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_current_opp_last_updated_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_curr_risks_last_updated_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_domain_note_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_existing_customer_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_financial_overview_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_fin_overview_last_updated_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_hidden_import_id_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_last_sync_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_owner_id_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_prev_number_of_won_opps_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_site_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_site_id_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_type_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_uep_e_strategic_account_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_unipart_current_risks_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_vision_statement_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_win_people_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.hubspot_id_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.id_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.jjwg_maps_address_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.jjwg_maps_geocode_status_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.jjwg_maps_lat_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.jjwg_maps_lng_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.opportunities_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.public_private_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.ref_code_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.registration_number_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.sector_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.sub_sector_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.success_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t2.threats_c, '') LIKE '%ya%', 1, 0) +<br \/>\nIF(COALESCE(t1.account_type, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.annual_revenue, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.assigned_user_id, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_city, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_country, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_postalcode, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_state, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.billing_address_street, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.campaign_id, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.created_by, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.date_entered, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.date_modified, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.deleted, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.description, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.employees, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.id, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.industry, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.modified_user_id, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.name, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.ownership, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.parent_id, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.phone_alternate, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.phone_fax, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.phone_office, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.rating, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_city, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_country, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_postalcode, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_state, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.shipping_address_street, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.sic_code, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.ticker_symbol, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t1.website, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.client_overview_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.failures_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.headlines_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_account_bu_owner_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_account_feedback_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_account_overview_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_acc_feedback_last_updated_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_acc_overview_last_updated_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_additional_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_beds_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_business_relationship_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_bu_strategic_target_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_current_opportunities_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_current_opp_last_updated_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_curr_risks_last_updated_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_domain_note_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_existing_customer_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_financial_overview_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_fin_overview_last_updated_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_hidden_import_id_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_last_sync_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_owner_id_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_prev_number_of_won_opps_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_site_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_site_id_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_type_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_uep_e_strategic_account_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_unipart_current_risks_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_vision_statement_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hs_win_people_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.hubspot_id_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.id_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.jjwg_maps_address_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.jjwg_maps_geocode_status_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.jjwg_maps_lat_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.jjwg_maps_lng_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.opportunities_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.public_private_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.ref_code_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.registration_number_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.sector_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.sub_sector_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.success_c, '') LIKE '%18%', 1, 0) +<br \/>\nIF(COALESCE(t2.threats_c, '') LIKE '%18%', 1, 0))<br \/>\n    ) AS score<br \/>\n  FROM accounts t1<br \/>\n  LEFT JOIN users u ON t1.created_by = u.id<br \/>\n  LEFT JOIN accounts_cstm t2 ON t1.id = t2.id_c<br \/>\n  WHERE t1.deleted = 0<br \/>\n) q<br \/>\nWHERE 0 < score\nORDER BY score DESC, date_modified DESC\nLIMIT 50\nOFFSET 0;\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The poor man&#8217;s CRM, a.k.a SuiteCRM &#8230;<\/p>\n","protected":false},"author":2,"featured_media":674,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[189,57,170,33],"class_list":["post-670","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology","tag-crm","tag-mysql","tag-search","tag-sql"],"_links":{"self":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/670","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=670"}],"version-history":[{"count":8,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/670\/revisions"}],"predecessor-version":[{"id":874,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/posts\/670\/revisions\/874"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/media\/674"}],"wp:attachment":[{"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=670"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=670"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.muratyaman.co.uk\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=670"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}