<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>Enable strict search by means of !searchstring.</title>
        <description> This mod enhances Sphiders capabilities to search strictly for the search query.

Quote recortes:
&amp;lt;&amp;lt;&amp;lt; I am looking for the word &amp;quot;REN&amp;quot;, but I get &amp;quot;REN&amp;quot; and also &amp;quot;impRENsa&amp;quot;, &amp;quot;pRENsa&amp;quot;, compRENsion, etc. &amp;gt;&amp;gt;&amp;gt;

The mod was designed to prevent this behaviour. It will present only the results for &amp;quot;REN&amp;quot; at Sphiders result pages. So it is the reverse function of &amp;quot;Search for part of a word by means of * wildcards&amp;quot; [www.sphider.eu]
Invoke this mod by entering a ! as first character of your search query. 
If the search term will be found only in title, url or meta tags but not in the HTML body, a corresponding message will be displayed. After installing this mod the message will also appear if you do a standard search without invoking the !strict search.


In .../include/searchfuncs.php search for:

$searchword = addslashes($wordarray[$words]);
}

Beyond these rows additionally include:

            $strictpos = strpos($searchword, '!'); //   if  ! is in position 0, we have to search strict
            if ($strictpos === 0) $searchword = str_replace('!', '', $searchword);                      
          


In the same file search for:

	global $sph_messages, $results_per_page,

Delete that row and replace it with:

	global $sph_messages, $results_per_page, $show_meta_description,


In the same file search for:

			$txtlen = strlen($fulltxt);
			if ($txtlen &amp;gt; $desc_length) {
				$places = array();
				foreach($words['hilight'] as $word) {
					$tmp = strtolower($fulltxt);
					$found_in = strpos($tmp, $word);
					$sum = -strlen($word);
					while (!($found_in =='')) {
						$pos = $found_in+strlen($word);
						$sum += $pos;  //FIX!!
						$tmp = substr($tmp, $pos);
						$places[] = $sum;
						$found_in = strpos($tmp, $word);

					}
				}

Delete all that and replace it with the following:

			$txtlen = strlen($fulltxt);          
            $refreshed = ereg_replace(&amp;quot;[*!]&amp;quot;, '',trim($query)); //  works also for *wildcard search       
			if ($show_meta_description === 1 || $txtlen &amp;gt; $desc_length) {                    
                $places = array();
                $strictpos = strpos($query, '!');
                
                if ($strictpos === 0) {    // if !strict search enter here
                    $recovered = str_replace('!', '',trim(strtolower($query)));
                    $words['hilight'][0] = $recovered;  //  replace without ' ! '
                    $strict_length =strlen($recovered);
                 
    				$tmp = strtolower($fulltxt);
                    $found_in = '1';    //  pointer position start
                   
    				foreach($words['hilight'] as $word) {
    					$sum = -strlen($word);                 
    					while (!($found_in =='')) { 
                            $found_in = strpos($tmp, $word);                         
                            $tmp_front = substr($tmp, $found_in-1); //  one character before found match position                     
    						$pos = $found_in+strlen($word);
    						$sum += $pos;
    						$tmp = substr($tmp, $pos);  //  get rest of fulltxt
                            //  check weather found match is realy strict
                            $found_before = preg_match(&amp;quot;/[-_*\:&amp;amp;@\w]/&amp;quot;, substr($tmp_front, 0, 1));                      
                            $found_behind = preg_match(&amp;quot;/[-_*\:&amp;amp;@\w]/&amp;quot;, substr($tmp, 0, 1));

                            if ($found_before ===0 &amp;amp;&amp;amp; $found_behind ===0) {
                                $places[] = $sum;   //  remind position of match
                            }                           
                            $found_in = strpos($tmp, $word);    //  new position of pointer
                            if ($places[0] != '') $found_in = '';   // end if first place was found                                    
    					}
    				}
                } else {    // if not !strict search enter here (standard Sphider)
        			foreach($words['hilight'] as $word) {
        				$tmp = strtolower($fulltxt);
        				$found_in = strpos($tmp, $word);
        				$sum = -strlen($word);
        				while (!($found_in =='')) {
        					$pos = $found_in+strlen($word);
        					$sum += $pos;  //FIX!!
        					$tmp = substr($tmp, $pos);
        					$places[] = $sum;
        					$found_in = strpos($tmp, $word);
        				}
        			}
                }

In the same file search for:

			if ($title=='')
				$title = $sph_messages[&amp;quot;Untitled&amp;quot;];
			$regs = Array();
			foreach($words['hilight'] as $change) {
				while (@eregi(&amp;quot;[^\&amp;gt;](&amp;quot;.$change.&amp;quot;)[^\&amp;lt;]&amp;quot;, &amp;quot; &amp;quot;.$title.&amp;quot; &amp;quot;, $regs)) {
					$title = eregi_replace($regs[1], &amp;quot;&amp;lt;b&amp;gt;&amp;quot;.$regs[1].&amp;quot;&amp;lt;/b&amp;gt;&amp;quot;, $title);
				}

				while (@eregi(&amp;quot;[^\&amp;gt;](&amp;quot;.$change.&amp;quot;)[^\&amp;lt;]&amp;quot;, &amp;quot; &amp;quot;.$fulltxt.&amp;quot; &amp;quot;, $regs)) {
					$fulltxt = eregi_replace($regs[1], &amp;quot;&amp;lt;b&amp;gt;&amp;quot;.$regs[1].&amp;quot;&amp;lt;/b&amp;gt;&amp;quot;, $fulltxt);
				}
				$url2 = $url;
				while (@eregi(&amp;quot;[^\&amp;gt;](&amp;quot;.$change.&amp;quot;)[^\&amp;lt;]&amp;quot;, $url2, $regs)) {
					$url2 = eregi_replace($regs[1], &amp;quot;&amp;lt;b&amp;gt;&amp;quot;.$regs[1].&amp;quot;&amp;lt;/b&amp;gt;&amp;quot;, $url2);
				}
			}

			if (strlen($title) &amp;gt; 80) {
				$title = substr($title, 0,75).&amp;quot;...&amp;quot;;
			}

Delete all that and replace it with the following:

			if ($title=='')
			$title = $sph_messages[&amp;quot;Untitled&amp;quot;];
			$regs = Array();
			if (strlen($title) &amp;gt; 80) {
				$title = substr($title, 0,75).&amp;quot;...&amp;quot;;
			}
    		$url2 = $url;
            if ($places[0] == '') {  // if  no HTML text to highlight
                if ($show_meta_description === 1) $fulltxt = &amp;quot;&amp;lt;font color=\&amp;quot;red\&amp;quot;&amp;gt;Search string '$refreshed' only found in title or url.&amp;lt;/font&amp;gt;&amp;quot;;                
                else $fulltxt = &amp;quot;&amp;lt;font color=\&amp;quot;red\&amp;quot;&amp;gt;Search string '$refreshed' only found in title, url or meta tags.&amp;lt;/font&amp;gt;&amp;quot;;
                $words['hilight'][0] = $refreshed;  
            }
 
            foreach($words['hilight'] as $change) {
                if (!($strictpos === 0)) { 
                    while (@eregi(&amp;quot;[^\&amp;gt;](&amp;quot;.$change.&amp;quot;)[^\&amp;lt;]&amp;quot;, &amp;quot; &amp;quot;.$title.&amp;quot; &amp;quot;, $regs)) {
                        $title = eregi_replace($regs[1], &amp;quot;&amp;lt;b&amp;gt;&amp;quot;.$regs[1].&amp;quot;&amp;lt;/b&amp;gt;&amp;quot;, $title);
                    }
                    while (@eregi(&amp;quot;[^\&amp;gt;](&amp;quot;.$change.&amp;quot;)[^\&amp;lt;]&amp;quot;, $url2, $regs)) {
                        $url2 = eregi_replace($regs[1], &amp;quot;&amp;lt;b&amp;gt;&amp;quot;.$regs[1].&amp;quot;&amp;lt;/b&amp;gt;&amp;quot;, $url2);
                    }                    
                }    
    			while (@eregi(&amp;quot;[^\&amp;gt;](&amp;quot;.$change.&amp;quot;)[^\&amp;lt;]&amp;quot;, &amp;quot; &amp;quot;.$fulltxt.&amp;quot; &amp;quot;, $regs)) {
    				$fulltxt = eregi_replace($regs[1], &amp;quot;&amp;lt;b&amp;gt;&amp;quot;.$regs[1].&amp;quot;&amp;lt;/b&amp;gt;&amp;quot;, $fulltxt);
    			}
    		}
            $places = array();


Happy coding

Tec</description>
        <link>http://www.sphider.eu/forum/read.php?3,2944,2944#msg-2944</link>
        <lastBuildDate>Thu, 23 May 2013 16:16:23 +0300</lastBuildDate>
        <generator>Phorum 5.2.10</generator>
        <item>
            <guid>http://www.sphider.eu/forum/read.php?3,2944,2945#msg-2945</guid>
            <title>Re: Enable strict search by means of !searchstring.</title>
            <link>http://www.sphider.eu/forum/read.php?3,2944,2945#msg-2945</link>
            <description><![CDATA[ Thanks, Tec.<br />
It works OK.<br />
<br />
Key words for some one else:<br />
&quot;Wordbreaker&quot;, &quot;Stemmer&quot; and &quot;Stop List&quot;]]></description>
            <dc:creator>recortes</dc:creator>
            <category>Sphider Mods</category>
            <pubDate>Tue, 04 Dec 2007 01:35:51 +0200</pubDate>
        </item>
        <item>
            <guid>http://www.sphider.eu/forum/read.php?3,2944,2944#msg-2944</guid>
            <title>Enable strict search by means of !searchstring.</title>
            <link>http://www.sphider.eu/forum/read.php?3,2944,2944#msg-2944</link>
            <description><![CDATA[ This mod enhances Sphiders capabilities to search strictly for the search query.<br />
<br />
Quote recortes:<br />
&lt;&lt;&lt; I am looking for the word &quot;REN&quot;, but I get &quot;REN&quot; and also &quot;impRENsa&quot;, &quot;pRENsa&quot;, compRENsion, etc. &gt;&gt;&gt;<br />
<br />
The mod was designed to prevent this behaviour. It will present only the results for &quot;REN&quot; at Sphiders result pages. So it is the reverse function of &quot;Search for part of a word by means of * wildcards&quot; [<a href="http://www.sphider.eu/forum/read.php?3,2585" rel="nofollow" >www.sphider.eu</a>]<br />
Invoke this mod by entering a ! as first character of your search query. <br />
If the search term will be found only in title, url or meta tags but not in the HTML body, a corresponding message will be displayed. After installing this mod the message will also appear if you do a standard search without invoking the !strict search.<br />
<br />
<br />
In .../include/searchfuncs.php search for:<br />
<br />
$searchword = addslashes($wordarray[$words]);<br />
}<br />
<br />
Beyond these rows additionally include:<br />
<br />
            $strictpos = strpos($searchword, '!'); //   if  ! is in position 0, we have to search strict<br />
            if ($strictpos === 0) $searchword = str_replace('!', '', $searchword);                      <br />
          <br />
<br />
<br />
In the same file search for:<br />
<br />
	global $sph_messages, $results_per_page,<br />
<br />
Delete that row and replace it with:<br />
<br />
	global $sph_messages, $results_per_page, $show_meta_description,<br />
<br />
<br />
In the same file search for:<br />
<br />
			$txtlen = strlen($fulltxt);<br />
			if ($txtlen &gt; $desc_length) {<br />
				$places = array();<br />
				foreach($words['hilight'] as $word) {<br />
					$tmp = strtolower($fulltxt);<br />
					$found_in = strpos($tmp, $word);<br />
					$sum = -strlen($word);<br />
					while (!($found_in =='')) {<br />
						$pos = $found_in+strlen($word);<br />
						$sum += $pos;  //FIX!!<br />
						$tmp = substr($tmp, $pos);<br />
						$places[] = $sum;<br />
						$found_in = strpos($tmp, $word);<br />
<br />
					}<br />
				}<br />
<br />
Delete all that and replace it with the following:<br />
<br />
			$txtlen = strlen($fulltxt);          <br />
            $refreshed = ereg_replace(&quot;[*!]&quot;, '',trim($query)); //  works also for *wildcard search       <br />
			if ($show_meta_description === 1 || $txtlen &gt; $desc_length) {                    <br />
                $places = array();<br />
                $strictpos = strpos($query, '!');<br />
                <br />
                if ($strictpos === 0) {    // if !strict search enter here<br />
                    $recovered = str_replace('!', '',trim(strtolower($query)));<br />
                    $words['hilight'][0] = $recovered;  //  replace without ' ! '<br />
                    $strict_length =strlen($recovered);<br />
                 <br />
    				$tmp = strtolower($fulltxt);<br />
                    $found_in = '1';    //  pointer position start<br />
                   <br />
    				foreach($words['hilight'] as $word) {<br />
    					$sum = -strlen($word);                 <br />
    					while (!($found_in =='')) { <br />
                            $found_in = strpos($tmp, $word);                         <br />
                            $tmp_front = substr($tmp, $found_in-1); //  one character before found match position                     <br />
    						$pos = $found_in+strlen($word);<br />
    						$sum += $pos;<br />
    						$tmp = substr($tmp, $pos);  //  get rest of fulltxt<br />
                            //  check weather found match is realy strict<br />
                            $found_before = preg_match(&quot;/[-_*\:&amp;@\w]/&quot;, substr($tmp_front, 0, 1));                      <br />
                            $found_behind = preg_match(&quot;/[-_*\:&amp;@\w]/&quot;, substr($tmp, 0, 1));<br />
<br />
                            if ($found_before ===0 &amp;&amp; $found_behind ===0) {<br />
                                $places[] = $sum;   //  remind position of match<br />
                            }                           <br />
                            $found_in = strpos($tmp, $word);    //  new position of pointer<br />
                            if ($places[0] != '') $found_in = '';   // end if first place was found                                    <br />
    					}<br />
    				}<br />
                } else {    // if not !strict search enter here (standard Sphider)<br />
        			foreach($words['hilight'] as $word) {<br />
        				$tmp = strtolower($fulltxt);<br />
        				$found_in = strpos($tmp, $word);<br />
        				$sum = -strlen($word);<br />
        				while (!($found_in =='')) {<br />
        					$pos = $found_in+strlen($word);<br />
        					$sum += $pos;  //FIX!!<br />
        					$tmp = substr($tmp, $pos);<br />
        					$places[] = $sum;<br />
        					$found_in = strpos($tmp, $word);<br />
        				}<br />
        			}<br />
                }<br />
<br />
In the same file search for:<br />
<br />
			if ($title=='')<br />
				$title = $sph_messages[&quot;Untitled&quot;];<br />
			$regs = Array();<br />
			foreach($words['hilight'] as $change) {<br />
				while (@eregi(&quot;[^\&gt;](&quot;.$change.&quot;)[^\&lt;]&quot;, &quot; &quot;.$title.&quot; &quot;, $regs)) {<br />
					$title = eregi_replace($regs[1], &quot;&lt;b&gt;&quot;.$regs[1].&quot;&lt;/b&gt;&quot;, $title);<br />
				}<br />
<br />
				while (@eregi(&quot;[^\&gt;](&quot;.$change.&quot;)[^\&lt;]&quot;, &quot; &quot;.$fulltxt.&quot; &quot;, $regs)) {<br />
					$fulltxt = eregi_replace($regs[1], &quot;&lt;b&gt;&quot;.$regs[1].&quot;&lt;/b&gt;&quot;, $fulltxt);<br />
				}<br />
				$url2 = $url;<br />
				while (@eregi(&quot;[^\&gt;](&quot;.$change.&quot;)[^\&lt;]&quot;, $url2, $regs)) {<br />
					$url2 = eregi_replace($regs[1], &quot;&lt;b&gt;&quot;.$regs[1].&quot;&lt;/b&gt;&quot;, $url2);<br />
				}<br />
			}<br />
<br />
			if (strlen($title) &gt; 80) {<br />
				$title = substr($title, 0,75).&quot;...&quot;;<br />
			}<br />
<br />
Delete all that and replace it with the following:<br />
<br />
			if ($title=='')<br />
			$title = $sph_messages[&quot;Untitled&quot;];<br />
			$regs = Array();<br />
			if (strlen($title) &gt; 80) {<br />
				$title = substr($title, 0,75).&quot;...&quot;;<br />
			}<br />
    		$url2 = $url;<br />
            if ($places[0] == '') {  // if  no HTML text to highlight<br />
                if ($show_meta_description === 1) $fulltxt = &quot;&lt;font color=\&quot;red\&quot;&gt;Search string '$refreshed' only found in title or url.&lt;/font&gt;&quot;;                <br />
                else $fulltxt = &quot;&lt;font color=\&quot;red\&quot;&gt;Search string '$refreshed' only found in title, url or meta tags.&lt;/font&gt;&quot;;<br />
                $words['hilight'][0] = $refreshed;  <br />
            }<br />
 <br />
            foreach($words['hilight'] as $change) {<br />
                if (!($strictpos === 0)) { <br />
                    while (@eregi(&quot;[^\&gt;](&quot;.$change.&quot;)[^\&lt;]&quot;, &quot; &quot;.$title.&quot; &quot;, $regs)) {<br />
                        $title = eregi_replace($regs[1], &quot;&lt;b&gt;&quot;.$regs[1].&quot;&lt;/b&gt;&quot;, $title);<br />
                    }<br />
                    while (@eregi(&quot;[^\&gt;](&quot;.$change.&quot;)[^\&lt;]&quot;, $url2, $regs)) {<br />
                        $url2 = eregi_replace($regs[1], &quot;&lt;b&gt;&quot;.$regs[1].&quot;&lt;/b&gt;&quot;, $url2);<br />
                    }                    <br />
                }    <br />
    			while (@eregi(&quot;[^\&gt;](&quot;.$change.&quot;)[^\&lt;]&quot;, &quot; &quot;.$fulltxt.&quot; &quot;, $regs)) {<br />
    				$fulltxt = eregi_replace($regs[1], &quot;&lt;b&gt;&quot;.$regs[1].&quot;&lt;/b&gt;&quot;, $fulltxt);<br />
    			}<br />
    		}<br />
            $places = array();<br />
<br />
<br />
Happy coding<br />
<br />
Tec]]></description>
            <dc:creator>Tec</dc:creator>
            <category>Sphider Mods</category>
            <pubDate>Mon, 03 Dec 2007 23:28:34 +0200</pubDate>
        </item>
    </channel>
</rss>
