Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2003
    Location
    australia
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Search Engine problem

    Hi all,

    I'm developing a search engine function on my site. It searches a list of names. In fact famous Australian names. But the code I'm using is listing too many names and I want to reduce the list it brings up.

    For instance I put the name Ancher in and the results page lists 5 names. The list it is picking from is over 200 but in the "An" section it looks like this,

    Ancher, Sydney
    Anderson, Dame Judith
    Angliss, William
    Annear, Harold Desbrowe
    Ansett, Sir Reginald
    Antill, John

    I suspect its looking at the first two letters only but limiting its final list to 5 entries as it will not include the last name. The outcome might be better if the search looks at the first three letters. The code is as follows, so if anyone has some time can they just paste the section I need to change.

    Thanks in advance
    Abbas

    var cookies = document.cookie;
    var p = cookies.indexOf("d=");
    if (p != -1) {
    var st = p + 2;
    var en = cookies.indexOf(";", st);
    if (en == -1) {
    en = cookies.length;
    }
    var d = cookies.substring(st, en);
    d = unescape(d);
    }
    var od = d;
    var m = 0;
    if (d.charAt(0) == '"' && d.charAt(d.length - 1) == '"') {
    m = 1;
    }
    var r = new Array();
    var co = 0;
    if (m == 0) {
    var woin = new Array();
    var w = d.split(" ");
    for (var a = 0; a < w.length; a++) {
    woin[a] = 0;
    if (w[a].charAt(0) == '-') {
    woin[a] = 1;
    }
    }
    for (var a = 0; a < w.length; a++) {
    w[a] = w[a].replace(/^\-|^\+/gi, "");
    }
    a = 0;
    for (var c = 0; c < s.length; c++) {
    pa = 0;
    nh = 0;
    for (var i = 0; i < woin.length; i++) {
    if (woin[i] == 0) {
    nh++;
    var pat = new RegExp(w[i], "i");
    var rn = s[c].search(pat);
    if (rn >= 0) {
    pa++;
    } else {
    pa = 0;
    }
    }
    if (woin[i] == 1) {
    var pat = new RegExp(w[i], "i");
    var rn = s[c].search(pat);
    if (rn >= 0) {
    pa = 0;
    }
    }
    }
    if (pa == nh) {
    r[a] = s[c];
    a++;
    }
    }
    co = a;
    }

    if (m == 1) {
    d = d.replace(/"/gi, "");
    var a = 0;
    var pat = new RegExp(d, "i");
    for (var c = 0; c < s.length; c++) {
    var rn = s[c].search(pat);
    if (rn >= 0) {
    r[a] = s[c];
    a++;
    }
    }
    co = a;
    }
    function return_query() {
    document.jse_Form.d.value = od;
    }

    function num_jse() {
    document.write(co);
    }

    function out_jse() {
    if (co == 0) {
    document.write('Your search did not match any names.<p>Make sure all keywords are spelt correctly.<br>Try different or more general keywords. ');
    return;
    }
    for (var a = 0; a < r.length; a++) {
    var os = r[a].split("^");
    if (bold == 1 && m == 1) {
    var br = "<b>" + d + "</b>";
    os[2] = os[2].replace(pat, br);
    }
    if (include_num == 1) {
    document.write(a + 1, '. ', os[0], '</a><br>', os[2], '<p>');
    } else {
    document.write('<>', os[0], '</a><br>', os[2], '<p>');
    }
    }
    }

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try searching the forum for a Type Ahead script

  • #3
    New Coder
    Join Date
    Dec 2003
    Location
    australia
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks Willy

    Abbas

  • #4
    New to the CF scene
    Join Date
    May 2004
    Location
    Phoenix AZ
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    JS Search Whole Words Only

    Abbas, my cgi script no longer works on the server hosting my site (angefire.com), so I'm currently using a hosted search engine, but it's a pain.

    So, I'm creating a similar javascript search engine, and am having the same problem you are describing. Although it is labor intensive, I like that I can manage it myself, because the site gets updated daily.

    I've tried lots of different things, but just can't figure it out. It's working great, except that if somone searches for CA (i.e. for state of California) it brings up everything with the same combination of letters, Ca tholic, Frances ca, etc.

    I'm also not very pleased that everything appears in italics. I don't mind the url is in italics, but I can't figure out how to change everything else. If I remove the code for italics, nothing is in italics. I also wanted to make the search term highlighted, because with my color scheme bold doesn't show up really well.

    This is a widely-used GPL script, but there is conflicting information as to who originally wrote it. I have even seen some companies trying to sell it. Mine is a little bit different from yours.

    My site is an adoption reunion search and registry. I haven't rolled the js search out yet, but you can take a look at the source code in the files at.
    http://www.angelfire.com/folk/piecesofdreams
    /pod_form.htm
    /pod_form.js
    /pod_rpt.htm
    /pod_urls.js
    /pod_search.js

    I'm sure somebody here has used it and modified it, to have the option to search for whole words only. If I figure it out, I'll post it here.

    Amy

  • #5
    New Coder
    Join Date
    Dec 2003
    Location
    australia
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Amy,

    Thanks for your reply. I suspect I'm not as advanced in all of this as you may be. I'm just slightly past the cut and paste stage.

    However for what its worth here is a link to one page that I am working on. It might be of fleeting interest to you. Its not "officially" part of my Web site as yet.

    If you type the name Whitlam in the adridged section (and hit go) for instance you will see what I mean.

    http://members.ozemail.com.au/~ilamont/famous.htm

    Cheers
    Abbas


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •