1 of 6
1
LiveSearch
Posted: 20 July 2004 07:01 PM   [ Ignore ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32895
Joined  05-14-2004

*ponders*

Anyone up to making something that works like this?

 Signature 
Profile
MSG
 
 
Posted: 21 July 2004 01:33 AM   [ Ignore ]   [ # 1 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7534
Joined  08-05-2002

Hee hee…took me about forty minutes, but I have it working on my local dev site.

 Signature 
Profile
 
 
Posted: 21 July 2004 01:48 AM   [ Ignore ]   [ # 2 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32895
Joined  05-14-2004

paul…................. *begs* o great developer, let me play? =)

 Signature 
Profile
MSG
 
 
Posted: 21 July 2004 02:14 AM   [ Ignore ]   [ # 3 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7534
Joined  08-05-2002

Here, more or less, is a step by step process:

1.  Grab his livesearch.js file and create your own file by the same name with its content. In that file, you will have to change the URL for grabbing the search data to one of your templates.  I named my template ‘livesearch’ of all things.  So find this:

liveSearchReq.open("GET", "./livesearch.php?s=" + document.forms.searchform.s.value);


And change it to this:

liveSearchReq.open("GET", "./index.php/livesearch/" + document.forms.searchform.s.value+"/");


Now, put that file at the root of your EE site.

2.  Create a new template called ‘livesearch’ and have it set to parse PHP on input.  Inside this file you will put the PHP code for performing the search and outputting the results.  The search term will be sent along in the URL.  Here is my quick example:

<?php

global $IN, $DB, $LOC;

if (!
$IN->QSTR)
{
    
exit;
}

$search_phrase
=& urldecode($IN->QSTR);

$query = $DB->query("SELECT distinct(a.entry_id), a.url_title, a.title, b.blog_url
                                  FROM exp_weblog_titles a, exp_weblogs b
                                  WHERE a.weblog_id = b.weblog_id
                                  AND a.status != 'closed'
                                  AND (a.expiration_date > '"
.$LOC->now."' OR a.expiration_date = '0')
                                  AND a.title LIKE '%{$search_phrase}%'
                                  ORDER BY rand() LIMIT 0,10"
);

if (
$query->num_rows == 0)
{
    
exit('No Results');
}

foreach($query->result as $row)
{
    
echo '<a href="'.$row['blog_url'].$row['url_title'].'">'.$row['title'].'</a><br />';
}

?>

3.  Determine where you want the search to go on your site.  I am using Template 7, so I just substituted the new search for the EE simple search.

<h4>Blog LiveSearch:</h4>
<
form onsubmit="return liveSearchSubmit()" name="searchform" method="get" action="/index.php"
>

<
input type="text" id="livesearch" name="s" size="15" autocomplete="off" onkeypress="liveSearchStart()" />

</
form>

<
div id="LSResult" style="display: none;"><div id="LSShadow"></div></div>


Oh, and at the top of the page, you will have to include the javascript file:

<script type="text/javascript" src="livesearch.js"></script>

 Signature 
Profile
 
 
Posted: 21 July 2004 08:15 AM   [ Ignore ]   [ # 4 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7534
Joined  08-05-2002

Did it work?  Was it magic?

 Signature 
Profile
 
 
Posted: 21 July 2004 11:40 AM   [ Ignore ]   [ # 5 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32895
Joined  05-14-2004

I fell asleep, I’m going to implement this in the next hour or so and I’ll let you know if it works. =)

Thank you Paul!

 Signature 
Profile
MSG
 
 
Posted: 21 July 2004 12:42 PM   [ Ignore ]   [ # 6 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32895
Joined  05-14-2004

Paul,

I have this live at the moment even though it’s not working.  I’m getting *very* strange results.  Would you mind having a look? my site.

I’m sure it’ll quickly be evident what it’s doing wrong.  I’ve followed the steps fastidiuously, although it’s possible I made a mistake - I think I’ve got it the way you wrote.

Thanks Paul! =)

 Signature 
Profile
MSG
 
 
Posted: 21 July 2004 12:49 PM   [ Ignore ]   [ # 7 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7534
Joined  08-05-2002

Sleep, yes, I should get more of that myself.

It is odd.  In the javascript, you are using:  index.php/livesearch/?s=search_term_here, whereas I made it so it went to a template:  index.php/weblog/livesearch/search_term_here/.  So you should modify it to be like that if you want my example to work.  However, I just tried to look at the livesearch template on your site and I get your frontpage.  Are you sure you created this page and that it is accessible to all users (even guests)?

 Signature 
Profile
 
 
Posted: 21 July 2004 12:59 PM   [ Ignore ]   [ # 8 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32895
Joined  05-14-2004

ooh ok, I only replaced the filename, stupid, I’ll fix it. =)  my livesearch template in in the template group includex - is that a problem? does it need to be in weblog?

 Signature 
Profile
MSG
 
 
Posted: 21 July 2004 01:03 PM   [ Ignore ]   [ # 9 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32895
Joined  05-14-2004

http://www.lisa-jill.com/index.php/includes/livesearch/ is the template - it’s definitely there.

I modified that line in the javascript but still getting the same odd result of it repeating the page and overlaid. 

All permissions are set to yes for the livesearch template. =)

 Signature 
Profile
MSG
 
 
Posted: 21 July 2004 01:06 PM   [ Ignore ]   [ # 10 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7534
Joined  08-05-2002

It does not need to be in weblog, but you have to make sure you have the correct link to the template (and template group) in the javascript.

This:

liveSearchReq.open(“GET”, “./index.php/includes/livesearch/” +  document.forms.searchform.s.value+”/”);

Not this:

liveSearchReq.open(“GET”, “./index.php/livesearch/” +  document.forms.searchform.s.value+”/”);

 Signature 
Profile
 
 
Posted: 21 July 2004 01:09 PM   [ Ignore ]   [ # 11 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32895
Joined  05-14-2004

whee, it works.  Not I just need to get it formatted properly so that it looks good.  Thank you so much, I’m sorry I’m so dumb. =)

 Signature 
Profile
MSG
 
 
Posted: 21 July 2004 01:13 PM   [ Ignore ]   [ # 12 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32895
Joined  05-14-2004

One last question, Paul.  Can I somehow make this NOT parse a certain weblog?  In my old search form I had not=“friends” or some such - all private entries.  Possible with this or am I becoming a real thorn? smile

 Signature 
Profile
MSG
 
 
Posted: 21 July 2004 01:17 PM   [ Ignore ]   [ # 13 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32895
Joined  05-14-2004

(must have edit function!)

Also - autocomplete=“off” is not valid and doesn’t appear to affect anything when removed.  The rest is valid xhtml transition.  Yay. smile

 Signature 
Profile
MSG
 
 
Posted: 21 July 2004 01:26 PM   [ Ignore ]   [ # 14 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7534
Joined  08-05-2002

Yes, well, if someone was brilliant enough, they would write this up as a plugin so the results could be created using a tag.  If you know the weblog’s id, then you can easily just add a.weblog_id != ‘7’ or something like that in the query.

autocomplete is not valid (yet), but Camino, IE, Firefox, and Safari all accept it just fine.  Up to you to determine if validity is important enough to do away with it.

 Signature 
Profile
 
 
Posted: 21 July 2004 01:31 PM   [ Ignore ]   [ # 15 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32895
Joined  05-14-2004

*nods*  It is, for me.  Thank you so very much, Paul.  You are amazing and incredibly helpful and I really really really appreciate it.

 Signature 
Profile
MSG
 
 
Posted: 21 July 2004 01:39 PM   [ Ignore ]   [ # 16 ]  
Moderator
Avatar
RankRankRankRankRankRankRankRank
Total Posts:  32895
Joined  05-14-2004

Just a minor amendment to the above stuff.  If you are running your livesearch on several pages (mine is on every page in my site) you might want to modify ./index.php ... to /index.php .... and change the script call to /livesearch.js - that way it’ll always look from the root up and be able to find it.  I had this problem momentarily on my individual entry pages since they call from the comments template.

Just fyi! =)

 Signature 
Profile
MSG
 
 
Posted: 21 July 2004 01:41 PM   [ Ignore ]   [ # 17 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7534
Joined  08-05-2002

I am glad you brought it to my attention.  With a fair bit of tweaking, this could be made into a much more general and powerful tool.  Grabbing data and updating a page (without reloading the page) in real time…quite a few possibilities there.  Shoutboxes…private messaging…link lists…Gmail checking…etc. 

The only downside is the amount of backend work being done by using a template, but there might be ways to manage that that could be looked into.

 Signature 
Profile
 
 
Posted: 21 July 2004 01:42 PM   [ Ignore ]   [ # 18 ]  
Research Scientist
Avatar
RankRankRankRankRankRank
Total Posts:  7534
Joined  08-05-2002

Well, if your entire site is in EE, then ./index.php should still work because really EE is only calling one file ‘index.php’ and everything else is a query string.

 Signature 
Profile
 
 
   
1 of 6
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 64983 Total Logged-in Users: 36
Total Topics: 82024 Total Anonymous Users: 16
Total Replies: 440860 Total Guests: 213
Total Posts: 522884    
Members ( View Memberlist )
Newest Members:  hotglassladyariepChris Bandytony leodennisbaldwinhazlett_davidkpspokeli9htcluizmbent