Ca a l'air très intéressant, mais il faut se recompiler soi-même MySQL, c'est ça ???
Le 8 nov. 2009 à 17:36, prigent.yohann@gmail.com a écrit :
Author: prigent.yohann@gmail.com
Date: Sun Nov 8 17:36:31 2009
New Revision: 32747Log:
import initiale de spip_suggest : le formulaire de recherche version google suggest. Necesite myisam_suggest :
http://blog.dev001.net/2009/01/myisam_suggest-an-autocomplete-tool-for-mysql-fulltext-indices/
Le plugin est en version alpha en attendant de récupérer dynamiquement des index fulltext qu'on choisira evc un cfgAdded:
_plugins_/spip_suggest/
_plugins_/spip_suggest/action/
_plugins_/spip_suggest/action/suggest.php (with props)
_plugins_/spip_suggest/javascript/
_plugins_/spip_suggest/javascript/AutoSuggest.js (with props)
_plugins_/spip_suggest/javascript/jquery.autocomplete.css (with props)
_plugins_/spip_suggest/javascript/jquery.autocomplete.js (with props)
_plugins_/spip_suggest/plugin.xml (with props)
_plugins_/spip_suggest/suggest.html (with props)
_plugins_/spip_suggest/suggest_fonctions.php (with props)Added: _plugins_/spip_suggest/action/suggest.php
--- _plugins_/spip_suggest/action/suggest.php (added)
+++ _plugins_/spip_suggest/action/suggest.php Sun Nov 8 17:36:31 2009
@@ -0,0 +1,17 @@
+<?php
+define('_MYSQL_DIR', '/var/lib/mysql/');
+$services = array('mu_courskry83de' => array('spip_articles' => array('num' => 7)));
+if (!isset($services[$s = @$_GET['s']]) OR !isset($services[$s][$t = @$_GET['t']])) {
+ die ('Usage: ?s=service&t=table');
+}
+$num = $services[$s][$t]['num'];
+# query a nettoyer (charset...)
+$q = @$_GET['q'];
+
+exec($c = 'myisam_suggest '._MYSQL_DIR.$s.'/'.$t.' '.$num.' '.escapeshellarg($q), $lines);
+$res = array();
+print_r($lines);
+foreach (array_map('strtolower',$lines) as $line)
+ $res[trim($line)]++;
+echo json_encode($res);
+?>
\ No newline at end of filePropchange: _plugins_/spip_suggest/action/suggest.php
------------------------------------------------------------------------------
svn:executable =Added: _plugins_/spip_suggest/javascript/AutoSuggest.js
--- _plugins_/spip_suggest/javascript/AutoSuggest.js (added)
+++ _plugins_/spip_suggest/javascript/AutoSuggest.js Sun Nov 8 17:36:31 2009
@@ -0,0 +1,961 @@
+/**
+ * author: Timothy Groves - http://www.brandspankingnew.net
+ * version: 1.2 - 2006-11-17
+ * 1.3 - 2006-12-04
+ * 2.0 - 2007-02-07
+ *
+ */
+
+var useBSNns;
+
+if (useBSNns)
+{
+ if (typeof(bsn) == "undefined")
+ bsn = {}
+ _bsn = bsn;
+}
+else
+{
+ _bsn = this;
+}
+
+if (typeof(_bsn.Autosuggest) == "undefined")
+ _bsn.Autosuggest = {}
+
+_bsn.AutoSuggest = function (fldID, param)
+{
+ // no DOM - give up!
+ //
+ if (!document.getElementById)
+ return false;
+
+ // get field via DOM
+ //
+ this.fld = _bsn.DOM.getElement(fldID);
+
+ if (!this.fld)
+ return false;
+
+ // init variables
+ //
+ this.sInput = "";
+ this.nInputChars = 0;
+ this.aSuggestions = ;
+ this.iHighlighted = 0;
+
+ // parameters object
+ //
+ this.oP = (param) ? param : {};
+
+ // defaults
+ //
+ if (!this.oP.minchars) this.oP.minchars = 1;
+ if (!this.oP.method) this.oP.meth = "get";
+ if (!this.oP.varname) this.oP.varname = "input";
+ if (!this.oP.className) this.oP.className = "autosuggest";
+ if (!this.oP.timeout) this.oP.timeout = 2500;
+ if (!this.oP.delay) this.oP.delay = 500;
+ if (!this.oP.offsety) this.oP.offsety = -5;
+ if (!this.oP.shownoresults) this.oP.shownoresults = true;
+ if (!this.oP.noresults) this.oP.noresults = "No results!";
+ if (!this.oP.maxheight && this.oP.maxheight !== 0) this.oP.maxheight = 250;
+ if (!this.oP.cache && this.oP.cache != false) this.oP.cache = true;
+
+ // set keyup handler for field
+ // and prevent autocomplete from client
+ //
+ var pointer = this;
+
+ // NOTE: not using addEventListener because UpArrow fired twice in Safari
+ //_bsn.DOM.addEvent( this.fld, 'keyup', function(ev){ return pointer.onKeyPress(ev); } );
+
+ this.fld.onkeypress = function(ev){ return pointer.onKeyPress(ev); }
+ this.fld.onkeyup = function(ev){ return pointer.onKeyUp(ev); }
+
+ this.fld.setAttribute("autocomplete","off");
+}
+
+_bsn.AutoSuggest.prototype.onKeyPress = function(ev)
+{
+
+ var key = (window.event) ? window.event.keyCode : ev.keyCode;
+
+ // set responses to keydown events in the field
+ // this allows the user to use the arrow keys to scroll through the results
+ // ESCAPE clears the list
+ // TAB sets the current highlighted value
+ //
+ var RETURN = 13;
+ var TAB = 9;
+ var ESC = 27;
+
+ var bubble = true;
+
+ switch(key)
+ {
+
+ case RETURN:
+ this.setHighlightedValue();
+ bubble = false;
+ break;
+
+ case ESC:
+ this.clearSuggestions();
+ break;
+ }
+
+ return bubble;
+}
+
+_bsn.AutoSuggest.prototype.onKeyUp = function(ev)
+{
+ var key = (window.event) ? window.event.keyCode : ev.keyCode;
+
+
+ // set responses to keydown events in the field
+ // this allows the user to use the arrow keys to scroll through the results
+ // ESCAPE clears the list
+ // TAB sets the current highlighted value
+ //
+
+ var ARRUP = 38;
+ var ARRDN = 40;
+
+ var bubble = true;
+
+ switch(key)
+ {
+
+ case ARRUP:
+ this.changeHighlight(key);
+ bubble = false;
+ break;
+
+ case ARRDN:
+ this.changeHighlight(key);
+ bubble = false;
+ break;
+
+ default:
+ this.getSuggestions(this.fld.value);
+ }
+
+ return bubble;
+
+
+}
+
+_bsn.AutoSuggest.prototype.getSuggestions = function (val)
+{
+
+ // if input stays the same, do nothing
+ //
+ if (val == this.sInput)
+ return false;
+
+
+ // input length is less than the min required to trigger a request
+ // reset input string
+ // do nothing
+ //
+ if (val.length < this.oP.minchars)
+ {
+ this.sInput = "";
+ return false;
+ }
+
+ // if caching enabled, and user is typing (ie. length of input is increasing)
+ // filter results out of aSuggestions from last request
+ //
+ if (val.length>this.nInputChars && this.aSuggestions.length && this.oP.cache)
+ {
+ var arr = ;
+ for (var i=0;i<this.aSuggestions.length;i++)
+ {
+ if (this.aSuggestions[i].value.substr(0,val.length).toLowerCase() == val.toLowerCase())
+ arr.push( this.aSuggestions[i] );
+ }
+
+ this.sInput = val;
+ this.nInputChars = val.length;
+ this.aSuggestions = arr;
+
+ this.createList(this.aSuggestions);
+
+ return false;
+ }
+ else
+ // do new request
+ //
+ {
+ this.sInput = val;
+ this.nInputChars = val.length;
+
+ var pointer = this;
+ clearTimeout(this.ajID);
+ this.ajID = setTimeout( function() { pointer.doAjaxRequest() }, this.oP.delay );
+ }
+
+ return false;
+}
+
+_bsn.AutoSuggest.prototype.doAjaxRequest = function ()
+{
+
+ var pointer = this;
+
+ // create ajax request
+ var url = this.oP.script+this.oP.varname+"="+escape(this.fld.value);
+ var meth = this.oP.meth;
+
+ var onSuccessFunc = function (req) { pointer.setSuggestions(req) };
+ var onErrorFunc = function (status) { alert("AJAX error: "+status); };
+
+ var myAjax = new _bsn.Ajax();
+ myAjax.makeRequest( url, meth, onSuccessFunc, onErrorFunc );
+}
+
+_bsn.AutoSuggest.prototype.setSuggestions = function (req)
+{
+ this.aSuggestions = ;
+
+ if (this.oP.json)
+ {
+ var jsondata = eval('(' + req.responseText + ')');
+
+ for (var i=0;i<jsondata.results.length;i++)
+ {
+ this.aSuggestions.push( { 'id':jsondata.results[i].id, 'value':jsondata.results[i].value, 'info':jsondata.results[i].info } );
+ }
+ }
+ else
+ {
+
+ var xml = req.responseXML;
+
+ // traverse xml
+ //
+ var results = xml.getElementsByTagName('results')[0].childNodes;
+
+ for (var i=0;i<results.length;i++)
+ {
+ if (results[i].hasChildNodes())
+ this.aSuggestions.push( { 'id':results[i].getAttribute('id'), 'value':results[i].childNodes[0].nodeValue, 'info':results[i].getAttribute('info') } );
+ }
+
+ }
+
+ this.idAs = "as_"+this.fld.id;
+
+
+ this.createList(this.aSuggestions);
+
+}
+
+_bsn.AutoSuggest.prototype.createList = function(arr)
+{
+ var pointer = this;
+
+ // get rid of old list
+ // and clear the list removal timeout
+ //
+ _bsn.DOM.removeElement(this.idAs);
+ this.killTimeout();
+
+ // create holding div
+ //
+ var div = _bsn.DOM.createElement("div", {id:this.idAs, className:this.oP.className});
+
+ var hcorner = _bsn.DOM.createElement("div", {className:"as_corner"});
+ var hbar = _bsn.DOM.createElement("div", {className:"as_bar"});
+ var header = _bsn.DOM.createElement("div", {className:"as_header"});
+ header.appendChild(hcorner);
+ header.appendChild(hbar);
+ div.appendChild(header);
+
+ // create and populate ul
+ //
+ var ul = _bsn.DOM.createElement("ul", {id:"as_ul"});
+
+ // loop throught arr of suggestions
+ // creating an LI element for each suggestion
+ //
+ for (var i=0;i<arr.length;i++)
+ {
+ // format output with the input enclosed in a EM element
+ // (as HTML, not DOM)
+ //
+ var val = arr[i].value;
+ var st = val.toLowerCase().indexOf( this.sInput.toLowerCase() );
+ var output = val.substring(0,st) + "<em>" + val.substring(st, st+this.sInput.length) + "</em>" + val.substring(st+this.sInput.length);
+
+ var span = _bsn.DOM.createElement("span", {}, output, true);
+ if (arr[i].info != "")
+ {
+ var br = _bsn.DOM.createElement("br", {});
+ span.appendChild(br);
+ var small = _bsn.DOM.createElement("small", {}, arr[i].info);
+ span.appendChild(small);
+ }
+
+ var a = _bsn.DOM.createElement("a", { href:"#" });
+
+ var tl = _bsn.DOM.createElement("span", {className:"tl"}, " ");
+ var tr = _bsn.DOM.createElement("span", {className:"tr"}, " ");
+ a.appendChild(tl);
+ a.appendChild(tr);
+
+ a.appendChild(span);
+[... 1550 lines stripped ...]
_______________________________________________
Spip-zone-commit@rezo.net - http://listes.rezo.net/mailman/listinfo/spip-zone-commit
-Nicolas
--
Nicolas HOIZEY
Blog : http://www.gasteroprod.com/
Photos : http://flic.kr/nicolas-hoizey/