Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Improved Search Function
 
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features
 
Thread Tools Search this Thread
  #101  
Old 02-28-2005, 02:50 PM
 
sstillwell@aerostich.com sstillwell@aerostich.com is offline
 

eXpert
  
Join Date: Jun 2004
Location: Duluth, MN
Posts: 242
 

Default

Wow, what a difference a few lines of code can make. I hope Xcart takes note. They should update their search.php to include this handy little mod. They could even list it as an "Improvement" in the change log

Searchs are normal again, oh, search around, you can get it to search your sku's as well.
__________________
No longer using Xcart, was good while it lasted.
Reply With Quote
  #102  
Old 03-05-2005, 02:17 PM
 
PremiumPonyParts PremiumPonyParts is offline
 

Senior Member
  
Join Date: Dec 2004
Posts: 114
 

Default

Is there a way to have it automatically search extra fields.

In my site,
Some of my products titles are listed as

1964-1973 Car Part

Well, that includes say, 1969,
But if they search 1969 Car Part, it won't return it.
I have a Extra Field called Fits Years and lists all the years it fits.
Is it possible to automatically search extra fields?
__________________
Version 4.0.8
Reply With Quote
  #103  
Old 03-07-2005, 03:03 PM
 
Khar Khar is offline
 

Advanced Member
  
Join Date: Nov 2004
Posts: 57
 

Default

I'm using 4.0.7

The above code that bluecat posted gives me an error

Parse error: parse error, unexpected T_STRING, expecting ')' in /home/order/public_html/xcart/include/search.php on line 42



I would also like to implement the

split search string into separate words
and the strip last s from search string

I have pulled my last hair out. I'm not a coder so I could use some help on this.

Thanks to all that have been a part of this tread.
__________________
tekmind

X-cart 4.0.7 [unix]
Reply With Quote
  #104  
Old 03-17-2005, 01:47 PM
 
Khar Khar is offline
 

Advanced Member
  
Join Date: Nov 2004
Posts: 57
 

Default

Will this code work for 4.0.7 or am I just doing something wrong?

I' not to sure if I want to upgrade. I don't know what will happen to all the mods that I have implemented. I really don't want to lose all the work I've done.
__________________
tekmind

X-cart 4.0.7 [unix]
Reply With Quote
  #105  
Old 03-17-2005, 04:47 PM
  DogByteMan's Avatar 
DogByteMan DogByteMan is offline
 

X-Adept
  
Join Date: Mar 2003
Posts: 833
 

Default

I'm running this code in 4.0.7...

include/search.php

Code:
<?php /*****************************************************************************\ +-----------------------------------------------------------------------------+ | X-Cart | | Copyright (c) 2001-2004 Ruslan R. Fazliev <rrf@rrf.ru> | | All rights reserved. | +-----------------------------------------------------------------------------+ | PLEASE READ THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" | | FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE | | AT THE FOLLOWING URL: http://www.x-cart.com/license.php | | | | THIS AGREEMENT EXPRESSES THE TERMS AND CONDITIONS ON WHICH YOU MAY USE | | THIS SOFTWARE PROGRAM AND ASSOCIATED DOCUMENTATION THAT RUSLAN R. | | FAZLIEV (hereinafter referred to as "THE AUTHOR") IS FURNISHING OR MAKING | | AVAILABLE TO YOU WITH THIS AGREEMENT (COLLECTIVELY, THE "SOFTWARE"). | | PLEASE REVIEW THE TERMS AND CONDITIONS OF THIS LICENSE AGREEMENT | | CAREFULLY BEFORE INSTALLING OR USING THE SOFTWARE. BY INSTALLING, | | COPYING OR OTHERWISE USING THE SOFTWARE, YOU AND YOUR COMPANY | | (COLLECTIVELY, "YOU") ARE ACCEPTING AND AGREEING TO THE TERMS OF THIS | | LICENSE AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY THIS | | AGREEMENT, DO NOT INSTALL OR USE THE SOFTWARE. VARIOUS COPYRIGHTS AND | | OTHER INTELLECTUAL PROPERTY RIGHTS PROTECT THE SOFTWARE. THIS | | AGREEMENT IS A LICENSE AGREEMENT THAT GIVES YOU LIMITED RIGHTS TO USE | | THE SOFTWARE AND NOT AN AGREEMENT FOR SALE OR FOR TRANSFER OF TITLE.| | THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT. | | | | The Initial Developer of the Original Code is Ruslan R. Fazliev | | Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2004 | | Ruslan R. Fazliev. All Rights Reserved. | +-----------------------------------------------------------------------------+ \*****************************************************************************/ # # $Id: search.php,v 1.38.2.22 2004/11/11 12:02:11 max Exp $ # if ( !defined('XCART_SESSION_START') ) { header("Location: ../"); die("Access denied"); } $advanced_options = array("productcode", "productid", "provider", "price_max", "avail_max", "weight_max", "forsale", "flag_free_ship", "flag_ship_freight", "flag_global_disc", "flag_free_tax", "flag_min_amount", "flag_low_avail_limit", "flag_list_price", "flag_vat", "flag_gstpst", "manufacturers"); $sort_fields = array( "productcode" => func_get_langvar_by_name("lbl_sku"), "title" => func_get_langvar_by_name("lbl_product"), "price" => func_get_langvar_by_name("lbl_price"), "orderby" => func_get_langvar_by_name("lbl_default") ); if($current_area == 'A' || $current_area == 'P') $sort_fields["quantity"] = func_get_langvar_by_name("lbl_quantity"); if ($REQUEST_METHOD == "POST") { # # Update the session $search_data variable from $posted_data # if (!empty($posted_data)) { $need_advanced_options = false; foreach ($posted_data as $k=>$v) { if (!is_array($v) && !is_numeric($v)) $posted_data[$k] = stripslashes($v); if (in_array($k, $advanced_options) and $v !== "") $need_advanced_options = true; } if (!$need_advanced_options) $need_advanced_options = (doubleval($posted_data["price_min"]) != 0 || intval($posted_data["avail_min"]) != 0 || doubleval($posted_data["weight_min"]) != 0); if (!$need_advanced_options and $current_area == "C" and !empty($posted_data["categoryid"])) $need_advanced_options = true; $posted_data["need_advanced_options"] = $need_advanced_options; # # Data convertation for Feature comparison module # if(!empty($active_modules['Feature_Comparison'])) { include $xcart_dir."/modules/Feature_Comparison/search_define.php"; } if (empty($search_data["products"]["sort_field"])) { $posted_data["sort_field"] = "title"; $posted_data["sort_direction"] = 0; } else { $posted_data["sort_field"] = $search_data["products"]["sort_field"]; $posted_data["sort_direction"] = $search_data["products"]["sort_direction"]; } $search_data["products"] = $posted_data; $search_data["is_modify"] = $is_modify; } func_header_location("search.php?mode=search"); } if ($mode == "search") { # # Perform search and display results # $data = array(); $flag_save = false; # # Prepare the search data # if (!empty($sort) and isset($sort_fields[$sort])) { # Store the sorting type in the session $search_data["products"]["sort_field"] = $sort; $flag_save = true; } if (isset($sort_direction)) { # Store the sorting direction in the session $search_data["products"]["sort_direction"] = $sort_direction; $flag_save = true; } if($current_area == 'C' && !empty($config['Appearance']['products_order']) && empty($search_data["products"]["sort_field"])) { $search_data["products"]["sort_field"] = $config['Appearance']['products_order']; $search_data["products"]["sort_direction"] = 0; } if (!empty($page) and $search_data["products"]["page"] != intval($page)) { # Store the current page number in the session $search_data["products"]["page"] = $page; $flag_save = true; } if (is_array($search_data["products"])) { $data = $search_data["products"]; foreach ($data as $k=>$v) if (!is_array($v) && !is_numeric($v)) $data[$k] = addslashes($v); } if(!isset($condition) || (isset($HTTP_GET_VARS['condition']) || isset($HTTP_POST_VARS['condition']) || isset($HTTP_COOKIE_VARS['condition']))) $condition = array(); if(!isset($join) || (isset($HTTP_GET_VARS['join']) || isset($HTTP_POST_VARS['join']) || isset($HTTP_COOKIE_VARS['join']))) $join = array(); if(!isset($add_fields) || (isset($HTTP_GET_VARS['add_fields']) || isset($HTTP_POST_VARS['add_fields']) || isset($HTTP_COOKIE_VARS['add_fields']))) $add_fields = array(); if(!isset($having) || (isset($HTTP_GET_VARS['having']) || isset($HTTP_POST_VARS['having']) || isset($HTTP_COOKIE_VARS['having']))) $having = array(); if(!isset($search_condition) || (isset($HTTP_GET_VARS['search_condition']) || isset($HTTP_POST_VARS['search_condition']) || isset($HTTP_COOKIE_VARS['search_condition']))) $search_condition = ""; $search_condition .= "$sql_tbl[pricing].productid=$sql_tbl[products].productid AND $sql_tbl[pricing].quantity=1 AND $sql_tbl[pricing].variantid = 0 AND $sql_tbl[pricing].membership IN ('".@$user_account['membership']."','')"; $data["substring"] = trim($data["substring"]); if (!empty($data["substring"])) { if (empty($data["by_title"]) && empty($data["by_shortdescr"]) && empty($data["by_fulldescr"]) && empty($data["extra_fields"])) { $search_data["products"]["by_title"] = $data["by_title"] = "Y"; $flag_save = true; } $ss = split(" ",$data["substring"]); $ss_condition = ""; foreach($ss as $s) { # Search for substring in some fields... $condition = array(); if (!empty($data["by_title"])) $condition[] = "$sql_tbl[products].product LIKE '%".$s."%'"; if (!empty($data["by_shortdescr"])) $condition[] = "$sql_tbl[products].descr LIKE '%".$s."%'"; if (!empty($data["by_fulldescr"])) $condition[] = "$sql_tbl[products].fulldescr LIKE '%".$s."%'"; if (!empty($data["extra_fields"]) && $active_modules['Extra_Fields']) { foreach($data["extra_fields"] as $k => $v) $condition[] = "($sql_tbl[extra_field_values].value LIKE '%".$s."%' AND $sql_tbl[extra_fields].fieldid = '$k')"; $join['extra_field_values'] = "$sql_tbl[products].productid = $sql_tbl[extra_field_values].productid"; $join['extra_fields'] = "$sql_tbl[extra_field_values].fieldid = $sql_tbl[extra_fields].fieldid AND $sql_tbl[extra_fields].active = 'Y'"; } if (!empty($condition)) $ss_condition .= " AND (".implode(" OR ", $condition).")"; } $search_condition .= $ss_condition; # Search statistics db_query("INSERT INTO $sql_tbl[stats_search] (search, date) VALUES ('$data[substring]', '".time()."')"); } # /if (!empty($data["substring"])) # # Search by product features # if(!empty($active_modules['Feature_Comparison'])) { include $xcart_dir."/modules/Feature_Comparison/search_define.php"; } # # Internation names & descriptions # if($current_area == 'C' || $current_area == 'P') { $add_fields[] = "$sql_tbl[products_lng].product as product_lng"; $add_fields[] = "$sql_tbl[products_lng].descr as descr_lng"; $add_fields[] = "$sql_tbl[products_lng].full_descr as fulldescr_lng"; $join['products_lng'] = "$sql_tbl[products_lng].productid = $sql_tbl[products].productid AND $sql_tbl[products_lng].code = '$shop_language'"; } if(!empty($data["manufacturers"]) && $active_modules['Manufacturers']) { $search_condition .= " AND $sql_tbl[products].manufacturerid IN ('".implode("','", $data["manufacturers"])."')"; } if (!empty($data["categoryid"])) { # Search by category... $data["categoryid"] = intval($data["categoryid"]); if (!empty($data["search_in_subcategories"])) { # Search also in all subcategories $category_sign = ""; if (empty($data["category_main"]) && empty($data["category_extra"])) { $category_sign = "NOT"; } $categoryid_path = addslashes(array_pop(func_query_first("SELECT categoryid_path FROM $sql_tbl[categories] WHERE categoryid='".$data["categoryid"]."'"))); $categoryids_tmp = func_query("SELECT categoryid FROM $sql_tbl[categories] WHERE categoryid='".$data["categoryid"]."' OR categoryid_path LIKE '$categoryid_path/%'"); if (is_array($categoryids_tmp)) { foreach ($categoryids_tmp as $k=>$v) $categoryids[] = $v["categoryid"]; } $categoryids = implode(",", $categoryids); $categoryid_condition = " AND $sql_tbl[products_categories].categoryid $category_sign IN ($categoryids)"; } else $categoryid_condition = " AND $category_sign $sql_tbl[products_categories].categoryid='$data[categoryid]'"; $condition = array(); if (!empty($data["category_main"])) $condition[] = "$sql_tbl[products_categories].main='Y'"; if (!empty($data["category_extra"])) $condition[] = "$sql_tbl[products_categories].main!='Y'"; if (!empty($condition)) $categoryid_condition .= " AND (".implode(" OR ", $condition).")"; $search_condition .= " AND $sql_tbl[products_categories].productid=$sql_tbl[products].productid $categoryid_condition"; $from_tbl[$sql_tbl["products_categories"]] = 1; } # /if (!empty($data["categoryid"])) if (!empty($data["productcode"])) { if(!empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[products].productcode LIKE '%".$data["productcode"]."%' OR $sql_tbl[variants].productcode LIKE '%".$data["productcode"]."%')"; } else { $search_condition .= " AND $sql_tbl[products].productcode LIKE '%".$data["productcode"]."%'"; } } if (!empty($data["productid"])) $search_condition .= " AND $sql_tbl[products].productid='".$data["productid"]."'"; if (!empty($data["provider"])) $search_condition .= " AND $sql_tbl[products].provider LIKE '%".$data["provider"]."%'"; if (!empty($data["price_min"])) { if(!empty($active_modules['Product_Options'])) { $having[] = "(price>='".$data["price_min"]."' OR v_price>='".$data["price_min"]."')"; # $search_condition .= " AND ($sql_tbl[pricing].price>='".$data["price_min"]."' OR v_pricing.price>='".$data["price_min"]."')"; } else { $search_condition .= " AND $sql_tbl[pricing].price>='".$data["price_min"]."'"; } } if (strlen(@$data["price_max"]) > 0) { if(!empty($active_modules['Product_Options'])) { $having[] = "(price<='".$data["price_max"]."' OR v_price<='".$data["price_max"]."')"; # $search_condition .= " AND ($sql_tbl[pricing].price<='".$data["price_max"]."' OR v_pricing.price<='".$data["price_max"]."')"; } else { $search_condition .= " AND $sql_tbl[pricing].price<='".$data["price_max"]."'"; } } if (!empty($data["avail_min"])) { if(!empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[products].avail>='".$data["avail_min"]."' OR $sql_tbl[variants].avail>='".$data["avail_min"]."')"; } else { $search_condition .= " AND $sql_tbl[products].avail>='".$data["avail_min"]."'"; } } if (strlen(@$data["avail_max"]) > 0) { if(!empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[products].avail<='".$data["avail_max"]."' OR $sql_tbl[variants].avail<='".$data["avail_max"]."')"; } else { $search_condition .= " AND $sql_tbl[products].avail<='".$data["avail_max"]."'"; } } if (!empty($data["weight_min"])) { if(!empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[products].weight>='".$data["weight_min"]."' OR $sql_tbl[variants].weight>='".$data["weight_min"]."')"; } else { $search_condition .= " AND $sql_tbl[products].weight>='".$data["weight_min"]."'"; } } if (strlen(@$data["weight_max"]) > 0) { if(!empty($active_modules['Product_Options'])) { $search_condition .= " AND ($sql_tbl[products].weight<='".$data["weight_max"]."' OR $sql_tbl[variants].weight<='".$data["weight_max"]."')"; } else { $search_condition .= " AND $sql_tbl[products].weight<='".$data["weight_max"]."'"; } } if (!empty($data["forsale"])) $search_condition .= " AND $sql_tbl[products].forsale='".$data["forsale"]."'"; if (!empty($data["flag_free_ship"])) $search_condition .= " AND $sql_tbl[products].free_shipping='".$data["flag_free_ship"]."'"; if (!empty($data["flag_ship_freight"])) $search_condition .= " AND $sql_tbl[products].shipping_freight='".$data["flag_ship_freight"]."'"; if (!empty($data["flag_ship_freight"])) { if ($data["flag_ship_freight"] == "Y") $search_condition .= " AND $sql_tbl[products].shipping_freight>'0'"; else $search_condition .= " AND $sql_tbl[products].shipping_freight='0'"; } if (!empty($data["flag_global_disc"])) $search_condition .= " AND $sql_tbl[products].discount_avail='".$data["flag_global_disc"]."'"; if (!empty($data["flag_free_tax"])) $search_condition .= " AND $sql_tbl[products].free_tax='".$data["flag_free_tax"]."'"; if (!empty($data["flag_min_amount"])) { if ($data["flag_min_amount"] == "Y") $search_condition .= " AND $sql_tbl[products].min_amount!='1'"; else $search_condition .= " AND $sql_tbl[products].min_amount='1'"; } if (!empty($data["flag_low_avail_limit"])) { if ($data["flag_low_avail_limit"] == "Y") $search_condition .= " AND $sql_tbl[products].low_avail_limit!='10'"; else $search_condition .= " AND $sql_tbl[products].low_avail_limit='10'"; } if (!empty($data["flag_list_price"])) { if ($data["flag_list_price"] == "Y") $search_condition .= " AND $sql_tbl[products].list_price!='0'"; else $search_condition .= " AND $sql_tbl[products].list_price='0'"; } if (!empty($data["flag_vat"])) { if ($data["flag_vat"] == "Y") $search_condition .= " AND $sql_tbl[products].vat!='0'"; else $search_condition .= " AND $sql_tbl[products].vat='0'"; } if (!empty($data["flag_gstpst"])) { if ($data["flag_gstpst"] == "Y") $search_condition .= " AND ($sql_tbl[products].apply_gst='Y' OR $sql_tbl[products].apply_pst='Y')"; else $search_condition .= " AND $sql_tbl[products].apply_gst='N' AND $sql_tbl[products].apply_pst='N'"; } if(!empty($active_modules['Product_Options'])) { $join['classes'] = "$sql_tbl[classes].productid = $sql_tbl[products].productid"; $join["variants"] = "$sql_tbl[variants].productid = $sql_tbl[products].productid"; $join["pricing v_pricing"] = "v_pricing.variantid = $sql_tbl[variants].variantid AND v_pricing.quantity = 1 AND v_pricing.membership IN ('','".@$user_account['membership']."')"; $add_fields[] = "IF($sql_tbl[variants].variantid IS NOT NULL,'Y','') as is_variant"; $add_fields[] = "IF($sql_tbl[classes].classid IS NOT NULL,'Y','') as is_product_options"; $add_fields[] = "v_pricing.price as v_price"; } if (!empty($data["sort_field"])) { # Sort the search results... $direction = ($data["sort_direction"] ? "DESC" : "ASC"); switch ($data["sort_field"]) { case "productcode": $sort_string = "$sql_tbl[products].productcode $direction"; break; case "title": $sort_string = "$sql_tbl[products].product $direction"; break; case "orderby": $sort_string = "$sql_tbl[products_categories].orderby $direction"; if(empty($from_tbl[$sql_tbl["products_categories"]])) { $search_condition .= " AND $sql_tbl[products_categories].productid=$sql_tbl[products].productid "; } $from_tbl[$sql_tbl["products_categories"]] = 1; break; case "quantity": $sort_string = "$sql_tbl[products].avail $direction"; break; case "price": $sort_string = "price $direction"; break; default: $sort_string = "$sql_tbl[products].product"; } } else { $sort_string = "$sql_tbl[products].product"; } if(!empty($data['sort_condition'])) { $sort_string = $data['sort_condition']; } if ($config["General"]["unlimited_products"]=="N" && ($current_area == "C" || $current_area == "B") && $config["General"]["disable_outofstock_products"] == "Y") { $search_condition .= " AND ($sql_tbl[products].avail>0 OR $sql_tbl[products].product_type NOT IN ('','N')) "; } if (!empty($from_tbl) and is_array($from_tbl)) $from_tbl = ", ".implode(", ", array_keys($from_tbl)); # # Generate LEFT JOIN string # $join_string = ''; if(!empty($join) && @is_array($join)) { foreach($join as $k => $v) { list($name, $as) = explode(" ", $k); if(!empty($as)) $as = " as ".$as; $join_string .= " LEFT JOIN ".$sql_tbl[$name].$as." ON $v "; } } # # Generate HAVING string # $having_string = ''; if(!empty($having)) { $having_string = " HAVING ".implode(" AND ", $having); } # # Generate additional fields string # $add_fields_string = ''; if(!empty($add_fields) && @is_array($add_fields)) { $add_fields_string = ", ".implode(", ", $add_fields); } # # Calculate the number of rows in the search results # $total_items = @count(func_query("SELECT COUNT($sql_tbl[products].productid), MIN($sql_tbl[pricing].price) as price $add_fields_string FROM $sql_tbl[products], $sql_tbl[pricing] $from_tbl $join_string WHERE $search_condition GROUP BY $sql_tbl[products].productid $having_string")); if ($total_items > 0) { $page = $search_data["products"]["page"]; # # Prepare the page navigation # if(!isset($objects_per_page)) { if ($current_area == "C" || $current_area == "B") $objects_per_page = $config["Appearance"]["products_per_page"]; else $objects_per_page = $config["Appearance"]["products_per_page_admin"]; } $total_nav_pages = ceil($total_items/$objects_per_page)+1; include $xcart_dir."/include/navigation.php"; # # Perform the SQL query and getting the search results # if (!empty($search_data["is_modify"])) { # # Get the products and go to modify them # $products = func_query("SELECT $sql_tbl[products].productid FROM $sql_tbl[products], $sql_tbl[pricing] $from_tbl $join_string WHERE $search_condition GROUP BY $sql_tbl[products].productid $having_string"); if (is_array($products)) { x_session_register("store_productids"); $store_productids = array(); foreach($products as $v) $store_productids[$v['productid']] = true; func_header_location("product_modify.php?mode=return"); } } else $products = func_query("SELECT $sql_tbl[products].*, MIN($sql_tbl[pricing].price) as price $add_fields_string FROM $sql_tbl[products], $sql_tbl[pricing] $from_tbl $join_string WHERE $search_condition GROUP BY $sql_tbl[products].productid $having_string ORDER BY $sort_string LIMIT $first_page, $objects_per_page"); if (!empty($products)) { foreach ($products as $k=>$v) { $products[$k]['taxed_price'] = $v['price']; } } if (!empty($products) and $current_area == "C") { x_session_register("cart"); foreach ($products as $k=>$v) { if(!empty($active_modules['Feature_Comparison'])) { $products[$k]['is_clist'] = func_check_comparison($v['productid']); } $in_cart = 0; if(!empty($cart['products'])) { foreach($cart['products'] as $cv) { if($cv['productid'] == $v['productid']) $in_cart += $cv['amount']; } $products[$k]['avail'] -= $in_cart; if($products[$k]['avail'] < 0) { $products[$k]['avail'] = 0; } } if(!empty($active_modules['Product_Options'])) { $tmp_price = func_get_price_default_variant($v['productid'], @$user_account['membership']); if ($tmp_price) { $products[$k]["price"] = $tmp_price; $products[$k]["taxed_price"] = $tmp_price; } } $products[$k]["tmbn_url"] = func_get_thumbnail_url($v["productid"]); if(!empty($v['product_lng'])) $products[$k]['product'] = $v['product_lng']; if(!empty($v['descr_lng'])) $products[$k]['descr'] = $v['descr_lng']; if(!empty($v['fulldescr_lng'])) $products[$k]['fulldescr'] = $v['fulldescr_lng']; unset($products[$k]['product_lng'], $products[$k]['descr_lng'], $products[$k]['fulldescr_lng']); $products[$k]["taxes"] = func_get_product_taxes($products[$k], $login); if($products[$k]['descr'] == strip_tags($products[$k]['descr'])) $products[$k]['descr'] = str_replace("\n"," ",$products[$k]['descr']); if($products[$k]['fulldescr'] == strip_tags($products[$k]['fulldescr'])) $products[$k]['fulldescr'] = str_replace("\n"," ",$products[$k]['fulldescr']); } } # Assign the Smarty variables $smarty->assign("navigation_script","search.php?mode=search"); $smarty->assign("products", $products); $smarty->assign("first_item", $first_page+1); $smarty->assign("last_item", min($first_page+$objects_per_page, $total_items)); } $smarty->assign("total_items",$total_items); $smarty->assign("mode", $mode); if ($flag_save) x_session_save("search_data"); } if (empty($search_data["products"]) && $current_area == 'C') { $search_data["products"]['productcode'] = $config['Search_products']['search_products_sku_d']; $search_data["products"]['price_min'] = preg_replace("/-.*$/", "", $config['Search_products']['search_products_price_d']); $search_data["products"]['price_max'] = preg_replace("/^.*-/", "", $config['Search_products']['search_products_price_d']); $search_data["products"]['weight_min'] = preg_replace("/-.*$/", "", $config['Search_products']['search_products_weight_d']); $search_data["products"]['weight_max'] = preg_replace("/^.*-/", "", $config['Search_products']['search_products_weight_d']); $search_data["products"]['categoryid'] = $config['Search_products']['search_products_category_d']; } if (!empty($active_modules['Feature_Comparison']) && $current_area != 'C' && $current_area != 'P') { $fclasses = func_query("SELECT $sql_tbl[feature_classes].*, IF($sql_tbl[feature_classes_lng].class IS NOT NULL, $sql_tbl[feature_classes_lng].class, $sql_tbl[feature_classes].class) as class FROM $sql_tbl[feature_classes] LEFT JOIN $sql_tbl[feature_classes_lng] ON $sql_tbl[feature_classes].fclassid = $sql_tbl[feature_classes_lng].fclassid AND $sql_tbl[feature_classes_lng].code = '$shop_language' WHERE $sql_tbl[feature_classes].avail = 'Y' ORDER BY $sql_tbl[feature_classes].orderby"); if(!empty($fclasses)) { $smarty->assign("fclasses", $fclasses); } } $smarty->assign("search_prefilled", $search_data["products"]); if($active_modules['Manufacturers']) { $manufacturers = func_query("SELECT * FROM $sql_tbl[manufacturers]"); if($manufacturers) { array_unshift($manufacturers, array("manufacturerid" => '0', "manufacturer" => func_get_langvar_by_name("lbl_no_manufacturer"))); $tmp = explode("\n", $config['Search_products']['search_products_manufacturers_d']); foreach($manufacturers as $k => $v) { if(@in_array($v['manufacturerid'], $search_data["products"]['manufacturers']) || (in_array($v['manufacturerid'], $tmp) && $current_area == 'C')) $manufacturers[$k]['selected'] = 'Y'; } if($manufacturers) $smarty->assign("manufacturers", $manufacturers); } } if($active_modules['Extra_Fields']) { $extra_fields = func_query("SELECT * FROM $sql_tbl[extra_fields]"); if($extra_fields) { $tmp = explode("\n", $config['Search_products']['search_products_extra_fields']); foreach($extra_fields as $k => $v) { if(!in_array($v['fieldid'], $tmp) && $current_area == 'C') { unset($extra_fields[$k]); continue; } if($search_data["products"]['extra_fields'][$v['fieldid']]) $extra_fields[$k]['selected'] = 'Y'; } if($extra_fields) $smarty->assign("extra_fields", $extra_fields); } } if($current_area != 'C') include $xcart_dir."/include/categories.php"; if(!defined('IS_ROBOT')) $smarty->assign("sort_fields", $sort_fields); $smarty->assign("main","search"); ?>
__________________
Dedicated Server provided by EWD Hosting
X-Cart version 4.1.12
PHP 5.3.2
MySQL server 5.0.87-community
Operation system Linux
Perl 5.008008
dogbytecomputer.com
Reply With Quote
  #106  
Old 03-21-2005, 03:40 PM
 
Khar Khar is offline
 

Advanced Member
  
Join Date: Nov 2004
Posts: 57
 

Default

I really appreciate your time. Unfortunately I'm still getting an error.

I got a quote from X-cart to resolve this problem. Not to bad.

thanks again for the help.
__________________
tekmind

X-cart 4.0.7 [unix]
Reply With Quote
  #107  
Old 03-23-2005, 04:58 PM
 
JediSam04 JediSam04 is offline
 

Advanced Member
  
Join Date: Sep 2004
Location: Columbia, SC
Posts: 43
 

Default

Can someone please tell me what code I need to add in order to Match whole word only when searching?

I sell comic books. When I search for a Shi comic, all of the titles that contain the letters s h i are displayed. This is 12 pages of items. No customer is going to sit there and sift through these pages.

I searched the web and found some regular expressions that might work, but I really don't know what I'm doing and I don't want to screw anything up.

Your help is greatly appreciated.

Samantha
__________________
JediSam04
Version 4.1.11
X-AOM 4.1.10
PHP 5.2.6
MySQL 5.0.51a-community
Hosting by EWDHosting
DSEFU, Feed Manager, Custom mods
Reply With Quote
  #108  
Old 04-04-2005, 05:59 AM
 
vikkip vikkip is offline
 

Newbie
  
Join Date: Apr 2005
Posts: 3
 

Default improve search for 4.0.12?

For the simple search function, the more words a visitor enters, the worse things get. I'm getting 0 results when there should be several matches.

I need to quickly improve the search feature for two carts - both are Gold cart 4.0.12. Can this code be used w/ that version? The 4.0.12 file looks a lot different from the one below.


Quote:
Originally Posted by funkydunk
something like:

Code:
<? /*****************************************************************************\ +-----------------------------------------------------------------------------+ | X-Cart | | Copyright (c) 2001-2003 Ruslan R. Fazliev <rrf@rrf.ru> | | All rights reserved. | +-----------------------------------------------------------------------------+ | PLEASE READ THE FULL TEXT OF SOFTWARE LICENSE AGREEMENT IN THE "COPYRIGHT" | | FILE PROVIDED WITH THIS DISTRIBUTION. THE AGREEMENT TEXT IS ALSO AVAILABLE | | AT THE FOLLOWING URL: http://www.x-cart.com/license.php | | | | THIS AGREEMENT EXPRESSES THE TERMS AND CONDITIONS ON WHICH YOU MAY USE | | THIS SOFTWARE PROGRAM AND ASSOCIATED DOCUMENTATION THAT RUSLAN R. | | FAZLIEV (hereinafter referred to as "THE AUTHOR") IS FURNISHING OR MAKING | | AVAILABLE TO YOU WITH THIS AGREEMENT (COLLECTIVELY, THE "SOFTWARE"). | | PLEASE REVIEW THE TERMS AND CONDITIONS OF THIS LICENSE AGREEMENT | | CAREFULLY BEFORE INSTALLING OR USING THE SOFTWARE. BY INSTALLING, | | COPYING OR OTHERWISE USING THE SOFTWARE, YOU AND YOUR COMPANY | | (COLLECTIVELY, "YOU") ARE ACCEPTING AND AGREEING TO THE TERMS OF THIS | | LICENSE AGREEMENT. IF YOU ARE NOT WILLING TO BE BOUND BY THIS | | AGREEMENT, DO NOT INSTALL OR USE THE SOFTWARE. VARIOUS COPYRIGHTS AND | | OTHER INTELLECTUAL PROPERTY RIGHTS PROTECT THE SOFTWARE. THIS | | AGREEMENT IS A LICENSE AGREEMENT THAT GIVES YOU LIMITED RIGHTS TO USE | | THE SOFTWARE AND NOT AN AGREEMENT FOR SALE OR FOR TRANSFER OF TITLE.| | THE AUTHOR RETAINS ALL RIGHTS NOT EXPRESSLY GRANTED BY THIS AGREEMENT. | | | | The Initial Developer of the Original Code is Ruslan R. Fazliev | | Portions created by Ruslan R. Fazliev are Copyright (C) 2001-2003 | | Ruslan R. Fazliev. All Rights Reserved. | +-----------------------------------------------------------------------------+ \*****************************************************************************/ # # $Id: search.php,v 1.44.2.1 2003/06/02 11:57:44 svowl Exp $ # require "../smarty.php"; require "../config.php"; @include "./https.php"; require "./auth.php"; require "../include/categories.php"; $tmp=strstr($QUERY_STRING, "$XCART_SESSION_NAME="); if (!empty($tmp)) $QUERY_STRING=ereg_replace("$XCART_SESSION_NAME=([0-9a-zA-Z]*)", "", $QUERY_STRING); if(!empty($QUERY_STRING)) { # # Perform SQL search query # // new bit to split search string into separate words $con = ""; $substr = ""; if(!empty($substring)) { $ss = split(" ",$substring); foreach($ss as $s)$con[] = $sql_tbl[products].".product like '%".$s."%'"; $substr .= "&substring=".urlencode($substring); } if(empty($and))$and = "or"; $substr .= "&and=".$and; $substring_query = (!empty($con)) ? " (".join(" ".$and." ",$con).") " : " 1 "; // end of new bit $price_condition = $price_search_1?" AND $sql_tbl[pricing].price>='$price_search_1'":""; $price_condition .= $price_search_2?" AND $sql_tbl[pricing].price<='$price_search_2'":""; $price_substring = $price_search_1?"&price_search_1=".urlencode($price_search_1):""; $price_substring .= $price_search_2?"&price_search_2=".urlencode($price_search_2):""; if ($price_condition) $sort_by_price = "price"; if ($in_category) { $search_category = addslashes(array_pop(func_query_first("select category from $sql_tbl[categories] where categoryid='$in_category'"))); $search_categories = func_query("select categoryid from $sql_tbl[categories] where $sql_tbl[categories].category like '$search_category%'"); if(is_array($search_categories)) { $category_condition=" in ( "; foreach($search_categories as $k=>$v) $category_condition .= "'$v[categoryid]', "; $category_condition = ereg_replace(", $", ")", $category_condition); $category_condition=" ($sql_tbl[products].categoryid $category_condition or $sql_tbl[products].categoryid1 $category_condition or $sql_tbl[products].categoryid2 $category_condition or $sql_tbl[products].categoryid3 $category_condition) "; } } else $category_condition = "1"; $membership_condition = " AND ($sql_tbl[categories].membership='". $user_account['membership']."' OR $sql_tbl[categories].membership='') "; if ($store_language != $config["default_customer_language"] && $substring) { // $substring_query = "AND (($sql_tbl[products].product like '%$substring%' or $sql_tbl[products].descr like '%$substring%') OR ($sql_tbl[products_lng].code='$store_language' AND ($sql_tbl[products_lng].product LIKE '%$substring%' OR $sql_tbl[products_lng].descr LIKE '%$substring%' OR $sql_tbl[products_lng].full_descr LIKE '%$substring%')))"; $search_query_count = "select count(*) from $sql_tbl[pricing], $sql_tbl[categories], $sql_tbl[products] LEFT JOIN $sql_tbl[products_lng] ON $sql_tbl[products].productid=$sql_tbl[products_lng].productid where $sql_tbl[pricing].productid=$sql_tbl[products].productid and $sql_tbl[pricing].quantity=1 and $sql_tbl[products].categoryid=$sql_tbl[categories].categoryid $membership_condition and ($sql_tbl[pricing].membership='". $user_account['membership']."' or $sql_tbl[pricing].membership='') AND $category_condition and $sql_tbl[products].forsale='Y' and $sql_tbl[categories].avail='Y' $price_condition $substring_query group by $sql_tbl[products].productid"; } else { // $substring_query = "AND ($sql_tbl[products].product like '%$substring%' OR $sql_tbl[products].descr like '%$substring%')"; $search_query_count = "select count(*) from $sql_tbl[products], $sql_tbl[pricing], $sql_tbl[categories] where $sql_tbl[pricing].productid=$sql_tbl[products].productid and $sql_tbl[pricing].quantity=1 and $sql_tbl[products].categoryid=$sql_tbl[categories].categoryid $membership_condition and ($sql_tbl[pricing].membership='". $user_account['membership']."' or $sql_tbl[pricing].membership='') and ($sql_tbl[products].product like '%$substring%' or $sql_tbl[products].descr like '%$substring%') AND $category_condition and $sql_tbl[products].forsale='Y' and $sql_tbl[categories].avail='Y' $price_condition $substring_query group by $sql_tbl[products].productid"; } $search_query = "$category_condition and $sql_tbl[categories].avail='Y' and $sql_tbl[products].forsale='Y' $price_condition $substring_query "; $total_products_in_search = count(func_query($search_query_count)); # # Navigation code # $objects_per_page = $config["Appearance"]["products_per_page"]; $total_nav_pages = ceil($total_products_in_search/$objects_per_page)+1; require "../include/navigation.php"; $smarty->assign("products",func_search_products($search_query, $user_account['membership'],$first_page,$total_products_in_search, 0, $sort_by_price)); $smarty->assign("navigation_script","search.php?substring=".urlencode($substring)."&in_category=$in_category".$price_substring); $HTTP_GET_VARS["substring"] = stripslashes($HTTP_GET_VARS["substring"]); $smarty->assign("main","search"); } else { $smarty->assign("main","advanced_search"); } $smarty->display("customer/home.tpl"); ?>

Please note that has not been tested
Reply With Quote
  #109  
Old 04-04-2005, 06:01 AM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

Just make a copy of your current file and test it out. Can't hurt
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #110  
Old 04-07-2005, 06:06 AM
 
html_sucks html_sucks is offline
 

Advanced Member
  
Join Date: May 2004
Location: London, UK
Posts: 63
 

Default

Bluecat's complete file (http://forum.x-cart.com/viewtopic.php?p=72059#72059) seems to still work in 4.0.13, i've not tested fully, but looks good at first glance.

__________________
X-Cart v4.2.0, v4.0.13, v4.0.9, v4.0.17
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Changing and adding new features


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 10:58 PM.

   

 
X-Cart forums © 2001-2018