• php

    Posted on October 28th, 2008

    Written by jossi fresco

    Tags

    , ,
    Sphider mod

    Sphider is an open source lightweight web spider and search engine written in PHP, using MySQL as its back-end database. It is used widely in thousands of sites an can be easily expanded to support searching Adobe PDFs and Word docs.

    More info here: http://www.sphider.eu/

    The mod

    Off-the-shelf, Sphider only returns one portion of a document in which the searched keyword is found. With this mod, Sphider will display as many as 5 portions of a document instead:

    replace lines 564 to 572 in searchfunctions.php:

    $begin_pos = max(0, $places[$begin] - 30);
    $fulltxt = substr($fulltxt, $begin_pos, $desc_length);
    if ($places[$begin] > 0) {
    	$begin_pos = strpos($fulltxt, " ");
    }
    $fulltxt = substr($fulltxt, $begin_pos, $desc_length);
    $fulltxt = substr($fulltxt, 0, strrpos($fulltxt, " "))  ;
    $fulltxt = $fulltxt;
    
    }

    with this:

    $tempfulltxt ="";
    $begin_pos = max(0, $places[$begin] - 30);
    $tempfulltxt = substr($fulltxt, $begin_pos, $desc_length);
    
    if ($places[$begin] > 0) {
    	$begin_pos = strpos($tempfulltxt, " ");
    }
    
    $tempfulltxt = substr($tempfulltxt, $begin_pos, $desc_length);
    $tempfulltxt = substr($tempfulltxt, 0, strrpos($tempfulltxt, " "))  ;
    $text_a = "<ul><li>" . $tempfulltxt . "</li>";
    
    $idx = 0;
    
    while ($idx < count($places) && $idx < 5) {
    
    	if ($idx <> $begin) {
    		$tempfulltxt ="";
    		$begin_pos = max(0, $places[$idx] - 30);
    		$tempfulltxt = substr($fulltxt, $begin_pos, $desc_length);
    
    		if ($places[$idx] > 0) {
    			$begin_pos = strpos($tempfulltxt, " ");
    		}
    		$tempfulltxt = substr($tempfulltxt, $begin_pos, $desc_length);
    		$tempfulltxt = substr($tempfulltxt, 0, strrpos($tempfulltxt, " "))  ;
    		if ($tempfulltxt<> "")
    			$text_a .= "<li>" . $tempfulltxt . "</li>";
    	}		
    
    	$idx++;
    
    }
    
    }
    
    $fulltxt= $text_a . "</ul>";
    $text_a="";

    Download this mod

    This entry was posted on Tuesday, October 28th, 2008 at 5:43 pm and is filed under php. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
  • 3 Comments

    Take a look at some of the responses we've had to this article.

    1. Posted on June 8th

      thats lovely but it just changes my look and feel. i dont like the ul thing

    2. jossi fresco
      Posted on June 18th

      You can replace the ul tags with divs and style the divs with CSS classes with display:table, display table:row and display:table-cell.

      See http://www.quirksmode.org/css/display.html

    3. Carlos
      Posted on January 8th

      Loved this mod, thank you very much.

      I changed the limit from 5 results to 10 by modifying this line:

      while ($idx < count($places) && $idx < 5) {

  • Post a Comment

    Let us know what you thought.

  • Name:

    Email (required):

    Website:

    Message: