Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
Quick search for search-as-you-type
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jeffrey04  
View profile  
 More options Sep 9 2009, 4:15 am
From: Jeffrey04 <jeffre...@gmail.com>
Date: Wed, 9 Sep 2009 01:15:22 -0700 (PDT)
Local: Wed, Sep 9 2009 4:15 am
Subject: Quick search for search-as-you-type
this is a hack that uses search-as-you-type to provide quick search

copy and paste the following code to a file named responder.php saved
in the same folder as search-responder.php

<?php

function format($keyword, $result) {
    return count($result) == 1 ?
        array(
            'query' => $keyword,
            'results' => $result,
            'autocompletedQuery' => $result[0]['name']
        )
        : array(
            'query' => $keyword,
            'results' => $result
        );

}

function parse($query) {
    $document = new DOMDocument();
    $document->loadXML($query);

    return parse_resouces($document->getElementsByTagName('RES'));

}

function parse_record($record) {
    return array(
        'name' => read_tag($record->getElementsByTagName('T')),
        'type' => 'Suggestions',
        'content' => read_content(
            read_tag($record->getElementsByTagName('T')),
            read_tag($record->getElementsByTagName('S'))
        ),
        'moreDetailsUrl' => read_tag($record->getElementsByTagName
('U')),
        'style' => 'expanded'
    );

}

function parse_resouces($resources) {
    $result = array();

    if($resources->length != 0) {
        for($resource_index = 0;
            $resource_index < $resources->length;
            $resource_index++) {

            for($child_index = 0,
                $child_list = $resources->item($resource_index)-

>childNodes;

                $child_index < $child_list->length;
                $child_index++) {
                if(strtolower($child_list->item($child_index)-
>tagName) == 'r') {

                    $result[] = parse_record($child_list->item
($child_index));
                }
            }

        }
    }

    return $result;

}

function query($keyword) {
    return file_get_contents(sprintf(
        'http://192.168.1.28/search?'
            . 'q=%s'
            . '&getfields=*'
            . '&access=%s'
            . '&client=%s'
            . '&num=5'
            . '&filter=0'
            . '&output=xml_no_dtd'
            . '&site=%s',
        urlencode($keyword),
        'p',
        'default_frontend',
        'default_collection'
    ));

}

function read_content($title, $snippet) {
    return sprintf('<h1>%s</h1><br /><span type="summary">%s</span>',
$title, $snippet);

}

function read_tag($tag) {
    $result = array();

    for($tag_index = 0;
        $tag_index < $tag->length;
        $tag_index++) {

        for($child_index = 0,
            $child_list = $tag->item($tag_index)->childNodes;
            $child_index < $child_list->length;
            $child_index++) {
            $result[] = strip_tags($child_list->item($child_index)-

>wholeText);

        }
    }

    return implode(' - ', $result);

}

function output($result) {
    return sprintf(
        'searchAsYouType.handleAjaxResponse(%s)',
        json_encode($result)
    );

}

echo output(format($_GET['query'], parse(query($_GET['query']))));
// file ends

Then change search-as-you-type.js and replace search-responder.php to
responder.php at about line 31

    // The fully qualified URL to the Ajax responder.
    // e.g. http://intranet.company.com/search-as-you-type/responder.php
    ajaxResponderUrl:
      "url/to/responder.php",

Then everything should just work. I do not have much time to provide
support to this script, however, you can always reply to this thread
if you are in doubt XD


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »