PassMark Logo
Home » Forum

Announcement

Collapse
No announcement yet.

Geting rid of multi recommended links

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Geting rid of multi recommended links

    The boss gave me all kinds of terms to use for creating recommended links, but if someone put a couple of the same terms in, it would show the recommended link twice.

    No can do says the boss, so I gotta find a way to use all the terms and yet display only one instance of the recommended link.

    Here is my solution to the problem. It may not be helpful to everyone, and there might be some other things I am missing in regards to other recommended links appearing. But we need to use the terms, and we don’t need multiple instances of a recommended link.

    E D I T

    Please see my reply below for the revised code.
    http://www.wrensoft.com/forum/showpo...77&postcount=3
    The original solution was incorrect.
    Last edited by CyJobes; Feb-26-2010, 02:50 PM. Reason: The original solution was incorrect.

  • #2
    It is on our list of things to do for the next version (tendatively numbered V6.1 but is most likely to be V7 now given the big changes we've made).

    We're looking into making it possible to specify multiple words/phrases for a single recommended link. This will prevent the need for multiple entries. It will also be better than the filtering method above because it means less entries in the index, and less search time.
    --Ray
    Wrensoft Web Software
    Sydney, Australia
    Zoom Search Engine

    Comment


    • #3
      I found an error with the solution I had created. This error was allowing only ONE recommended link to appear, even if there were words that could have been associated with other recommended links.

      The following fix would allow multiple words to find other recommended links, without producing duplicates of the same recommended link.

      Just before the RecLinkWordMatch function place the declaration of a new array like this:
      PHP Code:
      $url_dup_array= array();
      function 
      RecLinkWordMatch($rec_word$rec_idx)

      Now we need to add this to the function as a global variable. Just after the function, and before the other global variables, place the following:
      PHP Code:
      global $url_dup_array
      In the end, the first part of the function should look like this:
      PHP Code:
      $url_dup_array= array();
      function 
      RecLinkWordMatch($rec_word$rec_idx)
      {    
          global 
      $url_dup_array
      Next, scroll down within the same function and find the 'if' statement that looks like this:
      PHP Code:
              if ($result == 0)
              { 
      Now we have to move a few lines. Look for
      PHP Code:
      $pgdata GetPageData($rec_idx);
      $url $pgdata[$PAGEDATA_URL]; 
      and move them to just after the ‘if’ statement. It should end up looking like this:
      PHP Code:
              if ($result == 0)
              {
                  
      $bRecLinkFound true;
                  
      $pgdata GetPageData($rec_idx); 
      Now we add a few lines of code that will keep the script from creating a duplicate of a recommended link. The new lines look like this:
      PHP Code:
                  $url $pgdata[$PAGEDATA_URL];
                  
                  if (
      in_array($pgdata[$PAGEDATA_URL], $url_dup_array))
                  {                
                          continue;    
                  }            
                  
      $url_dup_array[] = $pgdata[$PAGEDATA_URL]; 
      In the end, the repositioned code and new lines just under the ‘if’ statement should look like this:
      PHP Code:
              if ($result == 0)
              {
                  
      $bRecLinkFound true;
                  
      $pgdata GetPageData($rec_idx);
                  
      $url $pgdata[$PAGEDATA_URL];
                  
                  if (
      in_array($pgdata[$PAGEDATA_URL], $url_dup_array))
                  {                
                          continue;    
                  }            
                  
      $url_dup_array[] = $pgdata[$PAGEDATA_URL]; 
      Here is the entire revised function:
      PHP Code:
      // matches the recommended link word against the user search query
      $url_dup_array= array();
      function 
      RecLinkWordMatch($rec_word$rec_idx)
      {    
          global 
      $url_dup_array;
          global 
      $NumSearchWords$queryForSearch$queryForURL$query$num_rec_words;
          global 
      $SearchWords$UseWildCards$SearchAsSubstring$ToLowerSearchWords;
          global 
      $OutputBuffers$OUTPUT_RECOMMENDED;
          global 
      $PAGEDATA_URL$PAGEDATA_TITLE$PAGEDATA_DESC$PAGEDATA_IMG$UseZoomImage;
          global 
      $zoom_target$GotoHighlight$PdfHighlight;
          global 
      $num_recs_found;
          global 
      $STR_RECOMMENDED;

          
      $bRecLinkFound false;

          for (
      $sw 0$sw <= $NumSearchWords$sw++)
          {
              
              
      // if finished with last search word, check the full search query
              
      $result 1;
              if (
      $sw == $NumSearchWords)
                  
      $result wordcasecmp($queryForSearch$rec_word);
              else if (
      strlen($SearchWords[$sw]) > 0)
              {
                  if (
      $UseWildCards[$sw] == 1)
                  {
                      
      $pattern "/";

                      
      // match entire word
                      
      if ($SearchAsSubstring == 0)
                          
      $pattern $pattern "\A";

                      
      $pattern $pattern $RegExpSearchWords[$sw];

                      if (
      $SearchAsSubstring == 0)
                          
      $pattern $pattern "\Z";

                      if (
      $ToLowerSearchWords != 0)
                          
      $pattern $pattern "/i";
                      else
                          
      $pattern $pattern "/";

                      
      $result = !(preg_match($pattern$rec_word));
                  }
                  else if (
      $SearchAsSubstring == 0)
                  {
                      
      $result wordcasecmp($SearchWords[$sw], $rec_word);
                  }
                  else
                  {
                      if (
      mystristr($rec_word$SearchWords[$sw]) == FALSE)
                          
      $result 1;    // not matched
                      
      else
                          
      $result 0;    // matched
                  
      }

                  if (
      $result != 0)
                  {
                      
      // if not matched, we check if the word is a wildcard
                      
      if (strpos($rec_word"*") !== false || strpos($rec_word"?") !== false)
                      {
                          
      $RecWordRegExp "/\A" pattern2regexp($rec_word) . "\Z/i";
                          
      $result = !(preg_match($RecWordRegExp$SearchWords[$sw]));
                      }
                  }
              }


                  
                  
              if (
      $result == 0)
              {
                  
      $bRecLinkFound true;
                  
      $pgdata GetPageData($rec_idx);
                  
      $url $pgdata[$PAGEDATA_URL];
                  
                  if (
      in_array($pgdata[$PAGEDATA_URL], $url_dup_array))
                  {                
                          continue;    
                  }            
                  
      $url_dup_array[] = $pgdata[$PAGEDATA_URL];
                  
                  if (
      $num_recs_found == 0)
                  {
                      
      $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<div class=\"recommended\">\n";
                      
      $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<div class=\"recommended_heading\">$STR_RECOMMENDED</div>\n";
                  }
                  
                  
                  
      $title $pgdata[$PAGEDATA_TITLE];
                  
      $description $pgdata[$PAGEDATA_DESC];
                  if (
      $UseZoomImage)
                      
      $image $pgdata[$PAGEDATA_IMG];

                  
      $urlLink $url;
                  
      //$urlLink = rtrim($urls[$rec_idx]);

                  
      if ($GotoHighlight == 1)
                  {
                      if (
      $SearchAsSubstring == 1)
                          
      $urlLink RecLinkAddParamToURL($urlLink"zoom_highlightsub=".$queryForURL);
                      else
                          
      $urlLink RecLinkAddParamToURL($urlLink"zoom_highlight=".$queryForURL);
                  }
                  if (
      $PdfHighlight == 1)
                  {
                      if (
      stristr($urlLink".pdf") != FALSE)
                          
      $urlLink $urlLink."#search=&quot;".str_replace("\""""$query)."&quot;";
                  }
                  
      $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<div class=\"recommend_block\">\n";
                  if (
      $UseZoomImage)
                  {
                      if (
      strlen($image) > 0)
                      {
                          
      $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<div class=\"recommend_image\">";
                          
      $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<a href=\"".$urlLink."\"" $zoom_target "><img src=\"$image\" alt=\"\" class=\"recommend_image\"></a>";
                          
      $OutputBuffers[$OUTPUT_RECOMMENDED] .= "</div>";
                      }
                  }
                  
      $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<div class=\"recommend_title\">";
                  
      $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<a href=\"".$urlLink."\"" $zoom_target ">";
                  if (
      strlen($title) > 1)
                      
      $OutputBuffers[$OUTPUT_RECOMMENDED] .= PrintHighlightDescription($title);
                  else
                      
      $OutputBuffers[$OUTPUT_RECOMMENDED] .= PrintHighlightDescription($pgdata[$PAGEDATA_URL]);
                  
      $OutputBuffers[$OUTPUT_RECOMMENDED] .= "</a></div>\n";
                  
      $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<div class=\"recommend_description\">";
                  
      $OutputBuffers[$OUTPUT_RECOMMENDED] .= PrintHighlightDescription($description);
                  
      $OutputBuffers[$OUTPUT_RECOMMENDED] .= "</div>\n";
                  
      $OutputBuffers[$OUTPUT_RECOMMENDED] .= "<div class=\"recommend_infoline\">$url</div>\n";
                  
      $OutputBuffers[$OUTPUT_RECOMMENDED] .= "</div>";
                  
      $num_recs_found++;
                  break;
              }
          }
          return 
      $bRecLinkFound;

      Comment

      Working...
      X