SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How could be this search type ?!

    hi ..

    i need to search i the db by word, let say if i have in the db with words : 'This nice cat.' , i need to find this if i type in the search box : 'this is cat' , or 'cat is nice' .

    also if i have ' SitePoint.com ' how can do this to find it if i type : 'site*' ?


    how ????

  2. #2
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    found it, i need mysql 4 to do that

    but any way FULLTEXT didn`t work with me any1 know whay ?

    i have title and des so :

    MATCH (title,des) AGAINST ('$keyword')

    and with mysql i change the tabels :
    [php]

    ALTER TABLE house ADD FULLTEXT (title,des)
    ALTER TABLE house ADD FULLTEXT (des,title)

    [php]

    but cann`t find any with search ? whay ??

  3. #3
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried something like this?
    PHP Code:
    $s mysql_query("SELECT * FROM table WHERE words LIKE '%$search%' ORDER BY words ASC"); 
    I'm not really sure, bu I think thats what you use in a search script.
    - the lid is off the maple syrup again!

  4. #4
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $s = mysql_query("SELECT * FROM table WHERE words LIKE '%$search%' ORDER BY words ASC");
    this what am using, but as i said if u have :
    ' this is cat '

    and u search this cat , with u way will not find it, but with fulltext u will find it !!

    any any1 know what the wong with this query, i got no error and no result

    PHP Code:
        $querymysql_query("select * from house  where MATCH (title,des) AGAINST ('$keyword') "); 

    Code:
    Keyname  Type      Cardinality  Field 
    title    FULLTEXT  None         title  
                                    des   1
    ??

  5. #5
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did a test with this and it worked fine.
    PHP Code:
    $s mysql_query("SELECT * FROM test WHERE words LIKE '%$search%' ORDER BY words");
    while (
    $r mysql_fetch_object($s)) {
      echo 
    $r->words"<br>";

    It let my search for multiple words at a time.
    - the lid is off the maple syrup again!

  6. #6
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    there are some mistake here, shouldn`t work with, fust fulltext can search with this way !

  7. #7
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    But you shouldn't have to change stuff to fulltext just so you can search though them. using
    PHP Code:
    something LIKE '%$search%' 
    will search hrough anything.
    - the lid is off the maple syrup again!

  8. #8
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Grrrrrrrrr ........
    dumb manual ...

    that whay didn`t work with me :
    Tim Gustafson: Note: you should add at least 3 rows to the table before you try to match anything, and what you're searching for should only be contained in one of the three rows. This is because of the 50% thereshold. If you insert only one row, then now matter what you search for, it is in 50% or more of the rows in the table, and therefore disregarded.
    it was at the end of the manual, as comments ...

    now, he user type one word i`ll use Like '%cc%' if more the full text mode ..


    thx ..

  9. #9
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure how well this works but you could try this and search for "some to search for" or something for" and it would print everything containing those words even if they arn't exactly the same.
    PHP Code:
    <?
    if ($_POST) {
        
    $words explode(" "$_POST['search']);
        for (
    $i 0$i <= sizeof($words)-1$i++) {
            if (
    $i == 0) {
                
    $where "WHERE words LIKE '%$words[0]%' ";
            } else {
                
    $where .= " AND words LIKE '%$words[$i]%'";
            }
        }
        
    $s mysql_query ("SELECT * FROM table " .$where" ORDER BY words ASC");
        while (
    $r mysql_fetch_object($s)) {
            echo 
    $r->words"<br>";
        }
    }
    ?>
    What it does is puts all the search words into an array and then finds matches for all those words in the table.
    Last edited by notepad_coder; Jun 9, 2002 at 07:16.
    - the lid is off the maple syrup again!

  10. #10
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here is my way ...

    PHP Code:

        
    if($keyword){
            
    // remove the space from the beginning //
            
    $keyword ltrim($keyword);    
            
    // also from the end //
            
    $keyword rtrim($keyword);    
        }        
        if(
    $keyword != "" And substr_count("$keyword"," ") >=1){ // More than 1 word            
                
    $By_Like " And MATCH (title,des) AGAINST ('$keyword')";
                
    $Match_Word =1;
                
    //echo "many";
                
    }
        elseif(
    $keyword != "" And substr_count("$keyword"," ") < 1){ // then just 1 word
            
    $By_Like "  And( title like '%$keyword%'  OR   des like '%$keyword%') ";
            
    $Match_Word =0;
            
    //echo " 1 word ";
        
    }


    ///


        
    $querymysql_query("select *  from house where
         active='yes' And 
         country ='
    $Country
         
    $By_City 
         
    $By_Cat  And
         (
    $s_type)  $By_Like
         "
    );


    ///



            
    if($By_Like And $Match_Word=0){
                
    $des ereg_replace("$keyword","<font color=#FF0000>$keyword</font>",$des);
            }
            elseif(
    $By_Like And $Match_Word=1){
                
    $This_des explode(' '$keyword);
                            
                foreach (
    $This_des as $xdes){
                    if(
    $xdes !=""){
                        
                        
    $des ereg_replace("$xdes","<font color=#FF0000>$xdes</font>",$des);
                    }
                }
            } 
    and it`s work as need ..


Bookmarks

Posting Permissions

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