Limit Search Results

Discussion in 'PHP' started by jayg5000, Dec 15, 2006.

  1. #1
    I have a php script that runs a query for an on-site search feature but it is returning too many results. It is pulling the information from a database. I know there is some way to limit the searches so that only one result per page is listed in the search results. I am using the "SELECT Distinct" code but don't know if it is functioning correctly.

    This is the actual query code:
    $query1 = "SELECT Distinct Title, items.PageName, items.Thumbnail, items.MemberOf, OptionCode, DropCode
    			FROM (items LEFT JOIN Options ON items.PageName = Options.PageName) LEFT JOIN DropDown ON items.code = DropDown.Code
    WHERE ((items.Code like '%$search%' or OptionCode like '%$search%' or DropCode like '%$search%') and (items.MemberOf <> '' or items.PageName <> '')) and Discon_YN=0 and Sol_YN<>0";
    Code (markup):
    Let me know if you need more than just this code. If anyone can help it would be greatly appreciated!
     
    jayg5000, Dec 15, 2006 IP
  2. krakjoe

    krakjoe Well-Known Member

    Messages:
    1,795
    Likes Received:
    141
    Best Answers:
    0
    Trophy Points:
    135
    #2
    krakjoe, Dec 15, 2006 IP
  3. jayg5000

    jayg5000 Active Member

    Messages:
    223
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Come to think of it, it might be in the actual comparing of the database fields to the search term. What I would really like to do is limit the search results so they are more specific to what the user is searching for without bringing up every instance of the search term in various results of the same page.

    Hopefully this will help clarify:
    $query1 = "SELECT Distinct Title, items.PageName, items.Thumbnail, items.MemberOf, OptionCode, DropCode
    			FROM (items LEFT JOIN Options ON items.PageName = Options.PageName) LEFT JOIN DropDown ON items.code = DropDown.Code
    WHERE ((items.Code like '%$search%' or OptionCode like '%$search%' or DropCode like '%$search%') and (items.MemberOf <> '' or items.PageName <> '')) and Discon_YN=0 and Sol_YN<>0";
    
    	}
    	else 			//if($SearchType == "keyword_search" || $SearchType == "brand_search")
    	{
    		//ExtraWhere is to compensate for a single 3 character search.
    		$ExtraWhere = "";
    		if(strlen($search) == 3)
    		{
    			$ExtraWhere = " or (CartDesc like '%".$search."%')";
    		}
    
    		$query1 = "SELECT MATCH (Title,items.PageName)
    			AGAINST ('$search')+MATCH (Hype.Hype,Headline,SubHead1,SubHead2,Hype.Feature1,Hype.Feature2,Hype.Feature3,
    			Hype.Feature4,Hype.Feature5,Hype.Feature6,Hype.Feature7,Hype.Feature8,Hype.Feature9,Hype.Feature10) AGAINST ('$search')+
    			MATCH (Hype.Feature11,Hype.Feature12,Hype.Feature13,Hype.Feature14,Hype.Feature15,Feature16,
    			Feature17,Feature18,Feature19,Feature20,Hype.Extra,Hype.PageTitle,Hype.PgDesc,Hype.Keywords) AGAINST ('$search') AS relev, Title, items.PageName, Hype.PgDesc, Hype.Feature1, Hype.Feature2, Hype.Feature3, Hype.Feature4, Hype.Feature5, Hype.Feature6, Hype.Feature7,
    			Hype.Feature8, Hype.Feature9, Hype.Feature10, items.Thumbnail, items.MemberOf
    			FROM items, Hype
    			WHERE items.PageName = Hype.PageName AND Hype.SiteName='Sol Site' AND items.PageName<>'' and subcat<>'' and subcat is not null and discon_yn=0 and SOL_YN<>0 AND ((MATCH (Title,items.PageName)
    			AGAINST ('$search') OR MATCH (Hype.Hype,Headline,SubHead1,SubHead2,Hype.Feature1,Hype.Feature2,Hype.Feature3,
    			Hype.Feature4,Hype.Feature5,Hype.Feature6,Hype.Feature7,Hype.Feature8,Hype.Feature9,Hype.Feature10) AGAINST ('$search') OR
    			MATCH (Hype.Feature11,Hype.Feature12,Hype.Feature13,Hype.Feature14,Hype.Feature15,Feature16,
    			Feature17,Feature18,Feature19,Feature20,Hype.Extra,Hype.PageTitle,Hype.PgDesc,Hype.Keywords) AGAINST ('$search'))".$ExtraWhere.") order by relev desc";
    	}
    Code (markup):
     
    jayg5000, Dec 15, 2006 IP
  4. p2y

    p2y Well-Known Member

    Messages:
    581
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    123
    #4
    //edit : he already solved ^^
     
    p2y, Dec 15, 2006 IP
  5. jayg5000

    jayg5000 Active Member

    Messages:
    223
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #5
    I don't know if you are refering to the previous post but I am still confused on the filtering of my search results. Help?!
     
    jayg5000, Dec 15, 2006 IP