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 > Dev Questions
 
Thread Tools Search this Thread
  #51  
Old 03-04-2004, 11:04 PM
 
jordan0 jordan0 is offline
 

Advanced Member
  
Join Date: Oct 2003
Location: San Francisco, CA
Posts: 77
 

Default

Thanks funkydunk! this version of the modified search.php works great with my 3.5.4 install.
I am trying, though, to integrate a param field search function that is seperate from the substring search. I have gotten it to work great, with the exception of the navigation code. This is one of the chunks I inserted to perform a search within param01:
Code:
#Param01 Search $conp = ""; $andp = "AND"; if(!empty($search_param_01)){ $smarty->assign("stay_in_param01","$search_param_01"); $ssp = split(" ",$search_param_01); foreach($ssp as $sp) $conp[] = "(".$sql_tbl[products].".param01 like '%".$sp."%'"." OR ". $sql_tbl[products].".param01 like '%".$sp."%'".")"; } if(empty($andp))$andp = "OR"; $param01_query = (!empty($conp)) ? " AND (".join(" ".$andp." ",$conp).") " :"";

That part seems to work fine. I then made additions to my search query:
Code:
$search_query = "$category_condition and $sql_tbl[categories].avail='Y' and $sql_tbl[products].forsale='Y' $price_condition $param01_query $param02_query $param03_query $substring_query ";

And then, I think I've got something wrong here with my navigation code because it creates strange links between result pages. For example, if i perform a param01 search it returns the first page of results just fine. Then when I go to page two of the results, it forgets the param01 query and puts a "+" into the substring query. Here is the navigation code in question:
Code:
$smarty->assign("navigation_script","search.php?substring=".urlencode($substring)."&in_category=$in_category"." &search_param01=".urlencode($search_param01)."&search_param02=".urlencode($search_param02)." &search_param03=".urlencode($search_param03).$price_substring);

thanks!
__________________
Jordan Sitkin
http://www.kitkraft.biz
X-Cart 4.0.18 [unix]
Reply With Quote
  #52  
Old 03-05-2004, 12:03 AM
 
jeeya jeeya is offline
 

X-Adept
  
Join Date: May 2003
Location: USA
Posts: 807
 

Default

I am sorry if it's posted before but how to add subcatagory search option in advanced options below root catagories?

Thanks.
__________________
X-Cart Version 4.1.8
Hosted on Linux
Reply With Quote
  #53  
Old 03-08-2004, 12:34 PM
  domspe's Avatar 
domspe domspe is offline
 

Advanced Member
  
Join Date: Mar 2004
Location: Sarasota, FL
Posts: 79
 

Default subcategories search

I need the same thing
Quote:
I am sorry if it's posted before but how to add subcatagory search option in advanced options below root catagories?

I need to the subcats to search. we are going to have sucats like: artist, color, style, etc... and we want them to be able to search for "blue" withing "color"

any advice for this?

Thank You!!!!!!!!!!
__________________
~jaime*
shop.mpartworks.com
~~~~~~~~~~~~~~
xcart pro 3.5.5
heavily modified
freeBSD 4.8
php 4.3.3
Reply With Quote
  #54  
Old 03-23-2004, 06:06 PM
 
Emerson Emerson is offline
 

X-Man
  
Join Date: Mar 2004
Location: Atlanta, GA
Posts: 2,209
 

Default

Can this be changed so it searches in extra field?
Reply With Quote
  #55  
Old 03-23-2004, 06:44 PM
 
Emerson Emerson is offline
 

X-Man
  
Join Date: Mar 2004
Location: Atlanta, GA
Posts: 2,209
 

Default

Quote:
Originally Posted by Emerson
Can this be changed so it searches in extra field?

Nevermind, it DOES search in extrafields, it's just that I was searching in param01 and it is set to param00.. oops!

Another questions, tho.
Yes I did look before asking this time.
How can you set the search results to be sorted by date_added?

Thanks
Reply With Quote
  #56  
Old 04-07-2004, 09:25 PM
 
avanzar avanzar is offline
 

Newbie
  
Join Date: Feb 2004
Posts: 2
 

Default

I also tried the code and got a "could not find template error"
Reply With Quote
  #57  
Old 04-21-2004, 07:35 AM
 
BHMedia BHMedia is offline
 

Advanced Member
  
Join Date: Sep 2003
Posts: 71
 

Default

Hey! I just tried this mod for 3.5.6 works great! Nice one!!!!!!! Been looking for this for a long time since xcarts search function sucks azz. Hah thanks
Reply With Quote
  #58  
Old 04-21-2004, 09:48 AM
 
funkydunk funkydunk is offline
 

X-Man
  
Join Date: Oct 2002
Location: Cambridge, UK
Posts: 2,210
 

Default

Quote:
Originally Posted by avanzar
I also tried the code and got a "could not find template error"

Strange - what version of xcart are you using - the code above is designed for 3.5.x but if you look furtherback in the thread it will be compatible with 3.4

and yes, BHmedia - standard xcart search really does not do what it needs to. This is an improvement but can still be improved by xcart by taking the above and building an advanced search that has the search fields for all of the fields in the products table and allows them to be switched on or off in admin. This way it can be whatever the store owner wants.....
__________________
ex x-cart guru
Reply With Quote
  #59  
Old 04-28-2004, 06:51 AM
 
jeremye jeremye is offline
 

Senior Member
  
Join Date: Apr 2004
Location: Philadelphia, PA
Posts: 158
 

Default

Just as a note, I implemented the code for 3.4.14 and it works perfectly! Thanks all!

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.5 2004/02/05 12:29:22 mclap 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 # // BEG HACK // new bit to split search string into separate words $con = ""; $substr = ""; $and="AND"; if(!empty($substring)){ $ss = split(" ",$substring); foreach($ss as $s) // nfc - we add support for other fields to search $con[] = "(".$sql_tbl[products].".product like '%".$s."%'"." OR ". $sql_tbl[products].".descr like '%".$s."%'"." OR ". $sql_tbl[products].".fulldescr like '%".$s."%'"." OR ". $sql_tbl[products].".productid like '%".$s."%'".")"; //$substr .= "&substring=".urlencode($substring); } if(empty($and))$and = "OR"; $substring_query = (!empty($con)) ? " AND (".join(" ".$and." ",$con).") " :" 1 "; // END HACK $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) { // BEG HACK // always using default language so this case will never happen /* $substring_query = "AND (($sql_tbl[products].product like '%$substring%' or $sql_tbl[products].descr like '%$substring%' or $sql_tbl[products].fulldescr 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 { // BEG HACK // removed $substring_query =..... /* $substring_query = "AND ($sql_tbl[products].product like '%$substring%' OR $sql_tbl[products].descr like '%$substring%' OR $sql_tbl[products].fulldescr 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 $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"); } include "../customer/banner.php"; ?>

Although, in the advanced search mode, if I try a price search I get this error:
Code:
INVALID SQL: 1064 : You have an error in your SQL syntax near '1 group by xcart_products.productid' at line 1 SQL QUERY FAILURE: select count(*) from xcart_products, xcart_pricing, xcart_categories where xcart_pricing.productid=xcart_products.productid and xcart_pricing.quantity=1 and xcart_products.categoryid=xcart_categories.categoryid AND (xcart_categories.membership='' OR xcart_categories.membership='') and (xcart_pricing.membership='' or xcart_pricing.membership='') AND 1 and xcart_products.forsale='Y' and xcart_categories.avail='Y' AND xcart_pricing.price>='35' AND xcart_pricing.price<='95' 1 group by xcart_products.productid

If I try a category search I get this error:
Code:
INVALID SQL: 1064 : You have an error in your SQL syntax near '1 group by xcart_products.productid' at line 1 SQL QUERY FAILURE: select count(*) from xcart_products, xcart_pricing, xcart_categories where xcart_pricing.productid=xcart_products.productid and xcart_pricing.quantity=1 and xcart_products.categoryid=xcart_categories.categoryid AND (xcart_categories.membership='' OR xcart_categories.membership='') and (xcart_pricing.membership='' or xcart_pricing.membership='') AND (xcart_products.categoryid in ( '475', '325', '326', '327', '328', '329', '330', '331', '332', '333', '334', '335', '336', '337', '338') or xcart_products.categoryid1 in ( '475', '325', '326', '327', '328', '329', '330', '331', '332', '333', '334', '335', '336', '337', '338') or xcart_products.categoryid2 in ( '475', '325', '326', '327', '328', '329', '330', '331', '332', '333', '334', '335', '336', '337', '338') or xcart_products.categoryid3 in ( '475', '325', '326', '327', '328', '329', '330', '331', '332', '333', '334', '335', '336', '337', '338')) and xcart_products.forsale='Y' and xcart_categories.avail='Y' 1 group by xcart_products.productid

Any ideas? I saw that someone had a problem like this before but a solution was never posted? Thoughts?
__________________
Jeremy
X-Cart Gold v3.4.14 [Linux/Apache]
Heavily Modded
Reply With Quote
  #60  
Old 04-28-2004, 08:51 AM
 
jeremye jeremye is offline
 

Senior Member
  
Join Date: Apr 2004
Location: Philadelphia, PA
Posts: 158
 

Default

I fixed the problem above with the advanced search error, but I don't know why it was programmed this way.

On line 69 (or thereabouts) it HAD this:
Code:
$substring_query = (!empty($con)) ? " AND (".join(" ".$and." ",$con).") " :" 1 ";

My question is, what is the " 1 " for at the very end of the line? When I remove the one as seen below, it fixes all the problems and the search still works perfectly?

This code works:
Code:
$substring_query = (!empty($con)) ? " AND (".join(" ".$and." ",$con).") " :" "; //deleted 1

I just want to try to understand why that 1 was there so I know I didn't break something else.

Thanks.
__________________
Jeremy
X-Cart Gold v3.4.14 [Linux/Apache]
Heavily Modded
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



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 02:58 PM.

   

 
X-Cart forums © 2001-2020