[Zebralist] echoedSearchRetrieveRequest

Eric Lease Morgan emorgan at nd.edu
Thu Sep 18 21:58:04 CEST 2008

On Sep 18, 2008, at 3:35 PM, Adam Dickmeiss wrote:

>> Is there any way to get Zebra to include the
>> echoedSearchRetrieveRequest element in SRU results? I would really
>> like to have the query echoed so I can do things like spell-check and
>> alternative query suggestion.
> None of Index Data server tools generate an  
> echoedSearchRetrieveRequest.

I was beginning to think y'all didn't like me.  ;-)

I sort of thought echoedSearchRetrieveRequest wasn't turn on-able, and  
consequently I have taken a different tack, namely, using JavaScript  
to extract the query from the DOM's location.href object. Below is  
most of my code. I include it in my style sheet. It first renders the  
searchRetrieve results, it then extracts the query, and finally it  
invokes a second SRU query to retrieve the author facets to display:

function listFacets() {

   // define sru queries
   var r='./test?recordSchema=zebra::facet::au:p&...query='
   var m='./test?operation=searchRetrieve&...query=author='

   // extract the query
   var u=location.href;
   var p=u.split('?');
   var b=p[1].split('&');
   var i=0;
   var q='';
   while (i<b.length) {
     var a=b[i].split('=');
     if (a[0]=='query') {q=unescape(a[1])}

   // search for facets; ajax hack
   var url=r+q;
   var httpRequest=new XMLHttpRequest();
   httpRequest.onreadystatechange=function() {
     if (httpRequest.readyState==4) {
       var terms=httpRequest.responseXML.getElementsByTagName('term');
       var list='<ol>';
       while(i<terms.length) {
         var facet=terms[i].firstChild.data;
         var item="<a href='"+m+"%22"+facet+"%22"+"'>"+facet 
       list = list + '</ol>';
   httpRequest.open('GET', url, true);

I will probably use a similar technique to get the snippets.

If you use Firefox or Safari you should be able to see how it works at  
the following URL. IE will break. Search for mississippi:


Remember, be gentle. The query extraction is not perfect. I've only  
just started, but I like the fact that there is nothing but SRU and a  
stylesheet. Very little middleware.

Eric Lease Morgan
University of Notre Dame

More information about the Zebralist mailing list