Sean,

>Dan, this looks great.  I like the Ajax/array flexibility.
>
>Do you have some sample backend code that populates the ajax listbox? (e.g.
>your autocomplete.cfm)

Here's the URL to the AJAX template:

http://www.pengoworks.com/workshop/jquery/autocomplete_ajax.cfm?q=sp

That currently returns:

Sparta|896
Spencer|897
Spencerville|898
Spring Valley|899
Springboro|900
Springfield|901

The code basically expects a pipe delimited list of options separated by new
lines. The pipe delimited list is then split into an array.

>Also, how do you match content in the middle of a string?  (typing 'rica'
>will bring up 'Africa')  I haven't had much luck with matchSubset or
>matchContains...

Well, the matchSubset actually is a cache checking option. It's designed to
expand the cache search.

The matchContains is what you want to set to 1. This should make sure the JS
portion of the code actually searches for the matches anywhere in the
string.

On top of that, your AJAX page also needs to return matches for both "exact"
(matches at the start of the string) and "contain" (matches anywhere in the
string.)

The way I handle this is to provide "exact" returns first and then "contain"
matches second.

My SQL would look something like:

select
        1 as ExactMatch, UserId, Name
from
        User
where
        Name like 'Dan%'

union

select
        0 as ExactMatch, UserId, Name
from
        User
where
        UserId not in (
                select
                        UserId
                from
                        User
                where
                        Name like 'Dan%'
        )
and
        Name like '%Dan%'


order by
        ExactMatch desc, Name asc

This allows me to show exact/best matches at top and other interesting
matches at the bottom. The code that I'm using needed to allow users to
search by either last name or first name. For users who type the last name
in first (which is the way the results are returned) then those exact
matches appear right at top.

I'll try to actually write some documentation when I get a chance. I was
trying to find Dylan's original post to the mailing list where he documented
the plug-in, but I couldn't find it when I went back to look for it. It
almost looked like the post was archived.

-Dan


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to