Thread: Instant Search

Page 1 of 2 12 LastLast
Results 1 to 10 of 254

Hybrid View

  1. #1
    Join Date
    Nov 2011
    Posts
    34
    Plugin Contributions
    1

    Default Re: Instant Search

    Quote Originally Posted by MikeyG View Post
    I am not getting any message box come up, unless I reference the jquery file in the jscript_instansearch.php file and then I get the version for the jquery file I reference and no image swapper working.

    I think the problem lies in the order of each .js file being called in your web page.

    for example instantSearch.js depends on jquery.js, so if we want both of these files to work we need to call jquery.js first and then instantSearch.js, i.e:

    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="instantSearch.js"></script>

    however if we do it the other way round it will not work i.e call instantSearch.js first and then jquery.js:

    <script type="text/javascript" src="instantSearch.js"></script>
    <script type="text/javascript" src="jquery.js"></script>

    My theory is that the image swapper is compatible with the old jquery file and will not work with the new one that comes with instantsearch, i.e when we install instant search with your image swapper this is how it looks:

    <script type="text/javascript" src="jquery.js"></script> <--new
    <script type="text/javascript" src="instantSearch.js"></script>
    <script type="text/javascript" src="jquery.js"></script> <--old
    <script type="text/javascript" src="imageSwaper.js"></script>

    from the above you can see that instant search will work since it calls the new jquery file and image swapper will not work since it is also stuck with the new jquery file (it will ignore the old jquery file).

    I think this might be your problem, but i'm not sure, it would be better if i could of had access to your sites header code.

    what you can try is to remove both the references to jquery.js and instantSearch.js that came with instant search. Then go into the image swapper part of the code and add the instantSearch.js reference there, i.e:

    <script type="text/javascript" src="jquery.js"></script> <--old
    <script type="text/javascript" src="imageSwaper.js"></script>
    <script type="text/javascript" src="instantSearch.js"></script>

    again i would like to say this may be one possibility, not 100% sure!

  2. #2
    Join Date
    Dec 2011
    Posts
    41
    Plugin Contributions
    0

    Default Re: Instant Search

    Hi! when I look into public_html/cache, I found this

    PHP Warning: json_encode() [<a href='function.json-encode'>function.json-encode</a>]: Invalid UTF-8 sequence in argument in /home/cncmach/public_html/searches.php on line 161

    Here is the code for searches.php

    Code:
    <?php
    /**
     * @package Instant Search Results
     * @copyright Copyright Ayoob G 2009-2011
     * @copyright Portions Copyright 2003-2006 The Zen Cart Team
     * @copyright Portions Copyright 2003 osCommerce
     * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
     */
    
    
    //This PHP file is used to get the search results from our database. 
    
    // I don't know if this is nessceary
    header( 'Content-type: text/html; charset=utf-8' );
    
    
    //need to add this
    require('includes/application_top.php');
    global $db;
    
    
    //this gets the word we are searching for. Usually from instantSearch.js.
    $wordSearch = (isset($_GET['query']) ? $_GET['query'] : '');
    
    
    // we place or results into these arrays
    //$results will hold data that has the search term in the begining of the word. This will yield a better search result but the number of results will be a few.
    //$resultsAddAfter will hold data that has the search term anywhere in the word. This will yield a normal search result but the number of results will be a high.
    //$results has first priority over $resultsAddAfter
    $results=array();
    $resultsAddAfter=array();
    $prodResult;
    
    
    //the search word can not be empty
    if (strlen($wordSearch) > 0) {
    	
    	//if the user enters less than 2 characters we would like match search results that beging with these characters
    	//if the characters are greater than 2 then we would like to broaden our search results
    	if (strlen($wordSearch) <= 2) {
    		$wordSearchPlus =  $wordSearch . "%";
    	}else{
    		$wordSearchPlus =  "%" . $wordSearch . "%";
    	}
    	
    	
    	//first we would like to search for products that match our search word
    	//we then order the search results with respect to the keyword found at the begining of each of the results
    
    
    $sqlProduct = "SELECT " . TABLE_PRODUCTS_DESCRIPTION . ".products_name, " . TABLE_PRODUCTS_DESCRIPTION . ".products_id, " . TABLE_PRODUCTS . ".products_status
    FROM " . TABLE_PRODUCTS_DESCRIPTION . ", " . TABLE_PRODUCTS . "
    WHERE " . TABLE_PRODUCTS . ".products_id = " . TABLE_PRODUCTS_DESCRIPTION . ".products_id
    AND " . TABLE_PRODUCTS . ".products_status <> 0
    AND ((products_name LIKE :wordSearchPlus:) OR (LEFT(" . TABLE_PRODUCTS_DESCRIPTION . ".products_name,LENGTH(:wordSearch:)) SOUNDS LIKE :wordSearch:))
    ORDER BY 
    field(LEFT(" . TABLE_PRODUCTS_DESCRIPTION . ".products_name,LENGTH(:wordSearch:)), :wordSearch:) DESC,
    " . TABLE_PRODUCTS_DESCRIPTION . ".products_viewed DESC
    LIMIT 2";				
    
    		
    	//this protects use from sql injection - i think????							
    	$sqlProduct = $db->bindVars($sqlProduct, ':wordSearch:', $wordSearch, 'string');
    	$sqlProduct = $db->bindVars($sqlProduct, ':wordSearchPlus:', $wordSearchPlus, 'string');
    
    
    	$dbProducts = $db->Execute($sqlProduct);
    	
    	
    	//this takes each item that was found in the results and places it into 2 separate arrays
    	if ($dbProducts->RecordCount() > 0) {
    	  while (!$dbProducts->EOF) {
    		$prodResult = strip_tags($dbProducts->fields['products_name']);
    		if (strtolower(substr($prodResult,0,strlen($wordSearch))) == strtolower($wordSearch)){
    			$results[] = array(
    				//we have 4 seperate variables that will be passed on to instantSearch.js
    				//'q' is the result thats been found
    				//'c' is the number of item within a category search (we leave this empty for product search, look at the example bellow for category search)
    				//'l' is used for creating a link to the product or category
    				//'pc' lets us know if the word found is a product or a category
    				'q'=>$prodResult,
    				'c'=>"",
    				'l'=>$dbProducts->fields['products_id'],
    				'pc'=>"p"
    			);
    		}else{
    			$resultsAddAfter[] = array(
    				'q'=>$prodResult,
    				'c'=>"",
    				'l'=>$dbProducts->fields['products_id'],
    				'pc'=>"p"
    			);	
    		}
    		
    		$dbProducts->MoveNext();
    	  }
    	}
    	
    	
    	
    	//similar to product search but now we search witin categories
    	$sqlCategories = "SELECT categories_name, categories_id
    			FROM " . TABLE_CATEGORIES_DESCRIPTION . "
    			WHERE (categories_name  LIKE :wordSearchPlus:) 
    				OR (LEFT(categories_name,LENGTH(:wordSearch:)) SOUNDS LIKE :wordSearch:) 
    			ORDER BY  
    				field(LEFT(categories_name,LENGTH(:wordSearch:)), :wordSearch:) DESC
    			LIMIT 4";
    		
    	$sqlCategories = $db->bindVars($sqlCategories, ':wordSearch:', $wordSearch, 'string');
    	$sqlCategories = $db->bindVars($sqlCategories, ':wordSearchPlus:', $wordSearchPlus, 'string');
    
    	$dbCategories = $db->Execute($sqlCategories);
    	
    	
    	
    	if ($dbCategories->RecordCount() > 0) {
    	  while (!$dbCategories->EOF) {
    		//this searches for the number of products within a category
    		$products_count = zen_count_products_in_category($dbCategories->fields['categories_id']); 
    
    		$prodResult = strip_tags($dbCategories->fields['categories_name']);
    		if (strtolower(substr($prodResult,0,strlen($wordSearch))) == strtolower($wordSearch)){
    			$results[] = array(
    				'q'=>$prodResult,
    				'c'=>$products_count,
    				'l'=>$dbCategories->fields['categories_id'],
    				'pc'=>"c"
    			);
    		}else{
    			$resultsAddAfter[] = array(
    				'q'=>$prodResult,
    				'c'=>$products_count,
    				'l'=>$dbCategories->fields['categories_id'],
    				'pc'=>"c"
    			);	
    		}
    		
    		
    		$dbCategories->MoveNext();
    	  }
    	}
    	
    }
    
    
    //we now re-sort the results so that $results has first priority over $resultsAddAfter
    foreach ($resultsAddAfter as &$value) {
    	$results[] = array(
    		'q'=>$value["q"],
    		'c'=>$value["c"],
    		'l'=>$value["l"],
    		'pc'=>$value["pc"]
    	);
    }
    
    unset($value);
    
    
    //the results are now passed onto instantSearch.js
    echo json_encode($results);
    
    
    ?>
    The one in red is the code that this error is concerned with. What must be wrong here?

    Thanks a lot

  3. #3
    Join Date
    Nov 2011
    Posts
    34
    Plugin Contributions
    1

    Default Re: Instant Search

    Quote Originally Posted by lala rock View Post
    Hi! when I look into public_html/cache, I found this

    PHP Warning: json_encode() [<a href='function.json-encode'>function.json-encode</a>]: Invalid UTF-8 sequence in argument in /home/cncmach/public_html/searches.php on line 161

    Here is the code for searches.php

    ...

    The one in red is the code that this error is concerned with. What must be wrong here?

    Thanks a lot

    Hi, the json_encode() function is a php function which sends data from php format into javascript format.

    If some of the products contain foreign characters like è then json_encode won't work properly, and the product containing the character will stop instant search from functioning properly, hence the error.

    However if you open searches.php and replace:

    echo json_encode($results);

    with:

    Code:
    echo json_encode(utf8json($results));
    
    function utf8json($inArray) {
    
        static $depth = 0;
    
        /* our return object */
        $newArray = array();
    
        /* safety recursion limit */
        $depth ++;
        if($depth >= '30') {
            return false;
        }
    
        /* step through inArray */
        foreach($inArray as $key=>$val) {
            if(is_array($val)) {
                /* recurse on array elements */
                $newArray[$key] = utf8json($val);
            } else {
                /* encode string values */
                $newArray[$key] = utf8_encode($val);
            }
        }
    
        /* return utf8 encoded array */
        return $newArray;
    }

    then it will be able to convert these foreign characters properly.

  4. #4
    Join Date
    Dec 2011
    Posts
    41
    Plugin Contributions
    0

    Default Re: Instant Search

    Thank you, when I add this to searches.php, the error doesnt show anymore.

  5. #5

    Default Re: Instant Search

    Hi

    works great except it displays also all disabled categories....

    what can i do?

    Thanks

    L.

  6. #6

    Default Re: Instant Search

    What is missing is the categories_status in the sql query, i tried to add it but i am still getting the mod to display disabled categories...

    Can someone let me know what is wrong in my query?

    //similar to product search but now we search witin categories
    $sqlCategories = "SELECT categories_name, categories_id, categories_status
    FROM " . TABLE_CATEGORIES_DESCRIPTION . " , ".TABLE_CATEGORIES."
    WHERE " . TABLE_CATEGORIES . ".categories_status <> 0
    AND (categories_name LIKE :wordSearchPlus:)
    OR (LEFT(categories_name,LENGTH(:wordSearch:)) SOUNDS LIKE :wordSearch:)
    ORDER BY
    field(LEFT(categories_name,LENGTH(:wordSearch:)), :wordSearch:) DESC
    LIMIT 4";

    Thanks

    L.


  7. #7
    Join Date
    Jan 2012
    Posts
    62
    Plugin Contributions
    0

    Default Re: Instant Search

    I'm having CSS issues with my Instant Search also. I moved the search bar up above the navigation, just below the top of the page.
    Every time I enter text into the search field the popup results container pushes the test that I'm entering down below said container.


    Thanks

  8. #8
    Join Date
    Nov 2011
    Posts
    34
    Plugin Contributions
    1

    Default Re: Instant Search

    Quote Originally Posted by wirefram View Post
    What is missing is the categories_status in the sql query, i tried to add it but i am still getting the mod to display disabled categories...

    Can someone let me know what is wrong in my query?

    //similar to product search but now we search witin categories
    $sqlCategories = "SELECT categories_name, categories_id, categories_status
    FROM " . TABLE_CATEGORIES_DESCRIPTION . " , ".TABLE_CATEGORIES."
    WHERE " . TABLE_CATEGORIES . ".categories_status <> 0
    AND (categories_name LIKE :wordSearchPlus:)
    OR (LEFT(categories_name,LENGTH(:wordSearch:)) SOUNDS LIKE :wordSearch:)
    ORDER BY
    field(LEFT(categories_name,LENGTH(:wordSearch:)), :wordSearch:) DESC
    LIMIT 4";

    Thanks

    L.



    hi sorry for late reply,

    replace it with this code:

    Code:
    	$sqlCategories = "SELECT cd.categories_name, cd.categories_id, c.categories_status
    			FROM " . TABLE_CATEGORIES_DESCRIPTION . " cd INNER JOIN " . TABLE_CATEGORIES . " c ON cd.categories_id = c.categories_id
    			WHERE (c.categories_status = 1) AND ((cd.categories_name  LIKE :wordSearchPlus:) 
    				OR (LEFT(cd.categories_name,LENGTH(:wordSearch:)) SOUNDS LIKE :wordSearch:))
    			ORDER BY  
    				field(LEFT(cd.categories_name,LENGTH(:wordSearch:)), :wordSearch:) DESC
    			LIMIT 4";

  9. #9
    Join Date
    Feb 2012
    Location
    Croatia
    Posts
    1
    Plugin Contributions
    0

    Default Re: Instant Search

    Quote Originally Posted by AyoobG View Post
    Hi, the json_encode() function is a php function which sends data from php format into javascript format.

    If some of the products contain foreign characters like è then json_encode won't work properly, and the product containing the character will stop instant search from functioning properly, hence the error.

    However if you open searches.php and replace:

    echo json_encode($results);

    with:

    Code:
    echo json_encode(utf8json($results));
    
    function utf8json($inArray) {
    
        static $depth = 0;
    
        /* our return object */
        $newArray = array();
    
        /* safety recursion limit */
        $depth ++;
        if($depth >= '30') {
            return false;
        }
    
        /* step through inArray */
        foreach($inArray as $key=>$val) {
            if(is_array($val)) {
                /* recurse on array elements */
                $newArray[$key] = utf8json($val);
            } else {
                /* encode string values */
                $newArray[$key] = utf8_encode($val);
            }
        }
    
        /* return utf8 encoded array */
        return $newArray;
    }

    then it will be able to convert these foreign characters properly.
    I have similar problem. I am using utf-8_general_ci in zencart database, Instant search works fine for me, but when i enter special character like (čćžšđ) if wont display anything.
    Here is a two picture below. Please help!
    Attached Thumbnails Attached Thumbnails Click image for larger version. 

Name:	search.jpg 
Views:	83 
Size:	27.2 KB 
ID:	10315   Click image for larger version. 

Name:	search1.jpg 
Views:	113 
Size:	24.2 KB 
ID:	10316  

  10. #10
    Join Date
    Feb 2010
    Posts
    35
    Plugin Contributions
    0

    Default Re: Instant Search

    Hi

    It's very good contrib!

    It's working perfect to me on 1.39h, but there is 1 point to update!

    I discovered that if you have multiple products with the same keywords but in a different order, only the results with the words in the same order as the research emerge. I need all the products with the same keywords in any order can emerge!

    thanks for you help!

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Instant Quote
    By Congerman in forum General Questions
    Replies: 2
    Last Post: 15 Aug 2012, 12:29 PM
  2. Instant Coupon
    By Mickmo68 in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 4
    Last Post: 22 Dec 2008, 08:19 PM
  3. Instant Delivery?
    By eaglewu in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 30 Jul 2007, 09:30 AM
  4. changes instant
    By chufty bill in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 5 Sep 2006, 07:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg