We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Live Search Plugin

Development and Programming

Matt Weinberg's avatar
Matt Weinberg
489 posts
16 years ago
Matt Weinberg's avatar Matt Weinberg

I’m 99.9% sure that the domain you actually load jQuery from has nothing to do with this error, but I’m open to being proven wrong 😊. Are you sure there is no mixing of subdomains happening whatsoever? The error says outright that it’s http://yourdomain.com trying to pull from www.yourdomain.com. What does the error say after you browse to the site using www?

       
mschoening's avatar
mschoening
71 posts
16 years ago
mschoening's avatar mschoening

Oh, no you must have misunderstood: it is actually the www. If I open the website with the www it works just fine. If I leave them out it doesn’t. So you were right! It doesn’t really matter where I load jQuery from.

However I don’t like the workaround of forcing the www. Isn’t there something else I can do?

Thanks, Max

       
Matt Weinberg's avatar
Matt Weinberg
489 posts
16 years ago
Matt Weinberg's avatar Matt Weinberg

Ah ok:)

What if you just call the plugin using a relative path:

$('#keywords').livesearch('/index.php/search/livesearch/', { width: '275', center_results: true });
       
mschoening's avatar
mschoening
71 posts
16 years ago
mschoening's avatar mschoening

Nice, works! Thanks so much!

       
mschoening's avatar
mschoening
71 posts
16 years ago
mschoening's avatar mschoening

How would I do this if I didn’t want to include a script tag in the EE template but rather call the plugin from an outside JS?

How would I have to modify this path:

$('#keywords').livesearch('/index.php/search/livesearch/', { width: '275', center_results: true });
       
Matt Weinberg's avatar
Matt Weinberg
489 posts
16 years ago
Matt Weinberg's avatar Matt Weinberg

The best way is to make sure the js gets called on the same domain as the page the person is on, which likely means using a relative path for it as well.

       
dj-rowan's avatar
dj-rowan
30 posts
16 years ago
dj-rowan's avatar dj-rowan

I am finishing up integration of this plugin on my site now- and I wanted to check about getting the paths correct for different entries/pages.

I found out that the core search feature {exp:search:search_results…}, I could check if an entry has the ‘page_url’ field set, and use this to generate the path, rather than the {auto_path} variable.

like this:

{if page_url != ""}
    <td width="30%" valign="top"><a href="{page_url}">{title}<a></td>
{if:else}
    <td width="30%" valign="top"><a href="{auto_path}">{title}<a></td>
{/if}

I’m trying to wrap my head around how this is possible using the live search plugin.

I’m using the Structure module (not pages), to handle my ‘static’ content/pages. I’d like the livesearch to link to the proper {page_url} when appropriate.

I could use some help finding out how to get the {page_url} value into the pi.live_search.php file. I will keep looking into this.

Perhaps this could be a new feature for the next version of this plugin? To pass a parameter into the {exp:live_search:results} call in order to indicate which url to use as the ‘$link_to’ path.

Many thanks!

Rowan

       
Matt Weinberg's avatar
Matt Weinberg
489 posts
16 years ago
Matt Weinberg's avatar Matt Weinberg

FYI dj-rowan, I answered your question here: http://ellislab.com/forums/viewreply/530472/

       
dj-rowan's avatar
dj-rowan
30 posts
16 years ago
dj-rowan's avatar dj-rowan
FYI dj-rowan, I answered your question here: http://ellislab.com/forums/viewreply/530472/

@slapshotw - thank you for your help! With a bit of persistance and mucking about, I’ve managed to modify the livesearch plugin to suit my needs.

For the information of anyone wanting to extend this plugin- or Pascal (to maybe add in some more flexibility), here’s what I did.

I have an extensive section of my site based on the Solspace Users module. So- custom profile fields and information about people are displayed like weblog entries.

Queries:

$sql = "SELECT distinct(a.entry_id), a.url_title, a.title, b.blog_url, b.comment_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}%' AND (b.weblog_id = 3 OR b.weblog_id = 1 OR b.weblog_id = 12 OR b.weblog_id = 4 OR b.weblog_id = 5 OR b.weblog_id = 11)
                ORDER BY a.title ASC LIMIT 0,10";

        $query = $DB->query($sql);

        $membersql = "SELECT distinct(m.member_id), d.m_field_id_4, d.m_field_id_5, d.m_field_id_8 FROM exp_members as m, exp_member_data as d WHERE m.member_id = d.member_id AND (d.m_field_id_4 like '%{$search_phrase}%' OR d.m_field_id_5 like '%{$search_phrase}%' OR d.m_field_id_8 like '%{$search_phrase}%')";
        $memberquery = $DB->query($membersql);

I extended the first query to search multiple weblogs (some i did not want searched). For the member query- I am searching name and location fields. Pretty straight forward.

The next issue had to do with accessing the ‘site_pages’ array to find out where to link to with each entry. Thanks to slapshotw, his tip in the ‘Structure’ thread helped me out.

Here’s my code:

global $PREFS; 

        $site_pages = $PREFS->ini('site_pages');

        $data = '[';
        foreach($query->result as $row) 
        {
            if (false !== $site_pages 
                && isset($site_pages['uris'])
                && isset($site_pages['uris'][$row['entry_id']])
                )                
            {
                $path = $site_pages['uris'][$row['entry_id']];
            }
            else{
                $path = $row[$link_to];                
            }
                    
            $data .= '{ "title" : "'.$row['title'].'", "path" : "'.$path.$row['url_title'].'" }, ';            
            
        }

        foreach($memberquery->result as $mrow){
            $data .= '{ "title" : "'.$mrow['m_field_id_4'].' '.$mrow['m_field_id_5'].' ('.$mrow['m_field_id_8'].')", "path" : "/instructors/'.$mrow['member_id'].'" }, ';
        }

I hope this helps someone! Thanks for the great plugin Pascal!

cheers,

Rowan

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
16 years ago
Pascal Kriete's avatar Pascal Kriete

Thanks for the kind words, Rowan. And thanks for helping out, Slapshotw.

I do plan on adding more functionality in the long run, but it’s on hold for now. There are other things that need to get done first 😉 .

       
Macrike's avatar
Macrike
137 posts
16 years ago
Macrike's avatar Macrike

Adding this to my list of plugins to try out. :D

       
Euan's avatar
Euan
214 posts
16 years ago
Euan's avatar Euan

I’ve installed it and got it running on a site I’m working on.

However, I’d love to be able to get it to search 1 custom field as well as the title (or search those fields I mark as ‘searchable’).

Has anyone got any thoughts on how to do this? (I’ve zero php knowledge!).

Thanks Euan

       
iDVB's avatar
iDVB
56 posts
16 years ago
iDVB's avatar iDVB

Is this type of configuration susceptible to a type of DOM attack threw that form input? Not sure if my terminology is correct but basically I mean that each time the user adds or minuses a character, there is a round trip to the server DB and then back to client. Is there not a possible load issue here?

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
16 years ago
Pascal Kriete's avatar Pascal Kriete

Euan, I can help you change the query a bit - do you only want it to search through one weblog (as shown earlier) with an added field? Or do you want it to search all weblogs and the extra field where it exists?

DVB, The autocomplete plugin that this was built on has a client side cache, so only the first few characters should run a query, once the result set is smaller than the cache limit it will be filtered directly from the js. It also has support for the ajaxQueue plugin which will cancel any running requests when a new character is added so as not to flood the server. Adding apc or memcached support might be an option down the road, but not everyone has those 😊 .

       
florian's avatar
florian
395 posts
16 years ago
florian's avatar florian

where does the following line of code go?

{exp:live_search:results link="comment"}

I dont think I understand how the implementation works. Here is what I did:

1.) upload the pi file to ee plugin folder 2.) add the general jquery link to the head. like so:

<scr*pt src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript" charset="utf-8"></scr*pt>

3.) upload the jquery.livesearch.js to root and add the file to the head like so:

<scr*pt src="mysite.com/jquery.livesearch.js" type="text/javascript" charset="utf-8"></scr*pt>

4.) create a template called livesearch and add the following code:

<?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="http://.$rowblog_url">.$row['url_title'].'"]'.$row['title'].'</a>
'; 
} 

?>

5.) Create a new template called test and add teh following: (I copied this from this thread from a post Mark did earlier)

{exp:search:simple_form search_in="everywhere"}
<h2 class="sidetitle">Search</h2>

<input type="text" name="keywords" id="keywords" value="" class="input" size="18" maxlength="100" />


<a href="http://{path=search/index}">Advanced Search</a>


<input type="submit" value="submit"  class="submit" /></p>

{/exp:search:simple_form}

<sc*ipt type="text/javasc*ipt">
// The trailing slash is important
$('#keywords').livesearch('{site_url}site/livesearch/');
</sc*ipt>

these are the steps I did. When I go to the test page in the browser it looks like the attached screenshot and nothing happens when I type in the search field.

what am I missing? I also dont quite understand why script is spelled scr*pt ??

Regards, Florian

       
First 2 3 4 5

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.