<html> <head> <title>Beispiel Suche</title> </head> <body> <h3>Einfache Suchmaschine</h3> Suche: <input id="query" /> <button id="search">Suche</button> (Beispiel: "content:foobar"; "url:bar"; "title:foo") <hr/> <div id="results"> </div> </body> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script> function on_data(data) { $('#results').empty(); var docs = data.response.docs; $.each(docs, function(i, item) { if (item.content.length > 400) contentpart = item.content.substring(0,400); else contentpart = item.content $('#results').prepend($( '<strong>' + item.title + '</strong><br/>' + '<a href="'+ item.url +'" target="_blank">'+ item.url +'</a>' + '<br/><div style="font-size:80%;">'+ contentpart +'</div><hr/>')); }); var total = 'Seiten gefunden: ' + docs.length + '<hr/>'; $('#results').prepend('<div>' + total + '</div>'); } function on_search() { var query = $('#query').val(); if (query.length == 0) { return; } } var solrServer = 'http://SUCHSERVER:8080/solr'; var url = solrServer + '/select/?q='+encodeURIComponent(query) + '&version=2.2&start=0&rows=50&indent=on&wt=json&callback=?&json.wrf=on_data'; $.getJSON(url); function on_ready() { $('#search').click(on_search); /* Hook enter to search */ $('body').keypress(function(e) { if (e.keyCode == '13') { on_search(); } }); } $(document).ready(on_ready); </script> </html>