PhpDig.net

PhpDig.net (http://www.phpdig.net/forum/index.php)
-   How-to Forum (http://www.phpdig.net/forum/forumdisplay.php?f=33)
-   -   Implementing search into other pages (http://www.phpdig.net/forum/showthread.php?t=709)

kh44na 03-23-2004 09:41 AM

Search Results
 
Hello,

Instead of having my search results displayed in the traditional "php dig template page" - I wanted to have the search results placed into a page on my website that matches the "look and feel" or "design" of my website more accurately.

Would anyone be able to assist me in how I can go about doing so?

Thanks in advance.

Charter 03-24-2004 09:03 AM

Hi. There is a tutorial here on how to include files in the templates, but if you want to have your own page from scratch, just do the following.

In search.php use 'array' rather than $template, assigning the output from phpdigSearch to a variable, like so:
PHP Code:

$the_output phpdigSearch($id_connect$query_string$option$refine,
              
$refine_url$lim_start$limite$browse,
              
$site$path$relative_script_path'array'); 

Afterwards add the following line:
PHP Code:

print_r($the_output); 

Then using a known keyword, do a search via URL (http://www.domain.com/dir/search.php?query_string=keyword) to see all the key value pairs that could be used.

Josiah 03-25-2004 11:40 AM

When I'm replacing the $template variable with 'array' -- do I just leave it as 'array', or do modify the 'array'?

I tried using your code as-is, and something is going wacko.

Charter 03-25-2004 02:32 PM

Hi. Just leave it as posted, and then after doing a search, you'll see key value pairs that you can use in a custom page. For example, searching for the word test would produce a similar key value pair as the following, assuming the word test is a keyword in your table:

[result_message] => Results 1-9, 9 total, on "test" (0.32 seconds)

To display the 'Results 1-9, 9 total, on "test" (0.32 seconds)' result message in a custom page, just use the following:
PHP Code:

echo $the_output['result_message']; 

That is, if you replace:
PHP Code:

print_r($the_output); 

with the following:
PHP Code:

echo $the_output['result_message']; 

then the only thing you will see onscreen is the following:

Results 1-9, 9 total, on "test" (0.32 seconds)

If you were to replace:
PHP Code:

print_r($the_output); 

with the following:
PHP Code:

include "custom_search_page.php"

then you could use the $the_output['key'] variables in the custom_search_page.php file.

Josiah 03-25-2004 07:13 PM

I'm doing something wrong, but here's my stab at it -- tell me what's wrong....

PHP Code:

$output phpdigSearch($id_connect$query_string$option$refine,
               
$refine_url$lim_start$limite$browse,
               
$site$path$relative_script_path'array');
               
echo 
$output['powered_by_link'],
    
$output['title_message'],
    
$output['phpdig_version'],
    
$output['nav_bar'],
    
$output['pages_bar'],
    
$output['next_link'],
    
$output['form_head'],
    
$output['form_foot'],
    
$output['form_title'],
    
$output['form_select'],
    
$output['form_button'],
    
$output['form_radio'],
    
$output['results'],
    
$output['weight'],
    
$output['img_tag'],
    
$output['page_link'],
    
$output['limit_links'],
    
$output['filesize'],
    
$output['update_date'],
    
$output['complete_path'],
    
$output['link_title'],
    
$output['text']; 


Charter 03-25-2004 07:20 PM

Hi. Try checking the HTML source and then order the $output['key'] variables so that they make correct HTML output.

Charter 03-25-2004 09:16 PM

Hi. Here's more info...
PHP Code:

$output phpdigSearch($id_connect$query_string$option$refine,
                       
$refine_url$lim_start$limite$browse,
                       
$site$path$relative_script_path'array');

if (
is_file("custom_search_page.php")) {
    include 
"custom_search_page.php";
} else { exit(); } 

Save the following in the same directory as the search.php file.
PHP Code:

<?php
// custom_search_page.php

if (eregi("custom_search_page.php",$_SERVER['SCRIPT_FILENAME']) || 
    
eregi("custom_search_page.php",$_SERVER['REQUEST_URI'])) {
    exit();
}

echo 
"<html><body>";

echo 
$output['result_message'],
     
$output['powered_by_link'],
     
$output['title_message'],
     
$output['phpdig_version'],
     
$output['nav_bar'],
     
$output['pages_bar'],
     
$output['next_link'],
     
$output['form_head'],
     
$output['form_title'],
     
$output['form_field'],
     
$output['form_select'],
     
$output['form_button'],
     
$output['form_radio'],
     
$output['form_foot'];

if (!empty(
$output['results'])) {
    
$num_out count($output['results']);
} else { 
$num_out 0; }
$num_start $lim_start 1;
$num_end $lim_start $num_out;

for (
$i=$num_start$i<=$num_end$i++) {
     echo 
$i.". ";
     
$output2 $output['results'][$i];
     echo 
$output2['weight'],
          
$output2['img_tag'],
          
$output2['page_link'],
          
$output2['limit_links'],
          
$output2['filesize'],
          
$output2['update_date'],
          
$output2['complete_path'],
          
$output2['link_title'],
          
$output2['text'];
     echo 
"<br><br>";
}

echo 
"</body></html>";

?>

Remember to remove any "word" wrapping in the above code.

Josiah 03-26-2004 05:26 AM

Quote:

Fatal error: Call to undefined function: ____eregi() in [pathto]public_html/search/custom_search_page.php on line 4

Charter 03-26-2004 03:06 PM

Hi. The eregi function is a defined function. Check the custom_search_page.php for extra or missing characters, and for incorrect code wrapping. Also, when doing copy paste, do the paste into a text only editor, and then save the file.

Josiah 03-27-2004 09:42 AM

Worked great! Thanks, Charter!

gooseman 03-29-2004 03:55 AM

Highlighted text extract or summary
 
I'm using the same method to customise the output.

But I find that using $output['text'] on my site just outputs the metatag description.

If I use the template output included, the output is an extract of the page eg. blah blah blah keyword blah... keyword blah blah... etc...

How do I output the ['text'] so that it appears as in the template?

Many thanks!

Charter 03-29-2004 05:24 AM

Hi. Are you using the code in this post?

gooseman 03-29-2004 05:59 AM

Yeah!

I realised I set the config to not do context searches (CONTENT_TEXT = 0), as I couldn't index on my server. I'm now doing it locally. I've set the flag back to 1 and it's working now! Doh! Thanks

motopsycho 05-05-2004 09:21 AM

Hope I am not intruding...
 
Hello,
This thread was exactly what I was looking for. It worked great. Could I bother you for some idea of how to add the keyword highlighting to your custom code above?


Thanks.

OceanSurf 09-08-2004 01:03 AM

I used Charters code posted 03-26-2004 06:16 AM
this is how I made my highlighting. not perfectet it thou.

Add this function to your custom_search_page.php
PHP Code:

function color_result($text) {
    
// explode the keywords
    
$keywords explode(" "$_REQUEST['query_string']);
    
// now color the words 
    
foreach ($keywords as $replace)
        {
         
$text str_replace($replace"<font color=\"#FF0000\"><b>".$replace."</b></font>"$text);
        }
    return 
$text;    


and at the bottom when printing the result use it like this:
PHP Code:

echo color_result($output2['text']); 

i tried it a couple of times and it worked just fine (for now ;) ).


All times are GMT -8. The time now is 09:38 PM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.