Listing search results in groups

Jake Howlett, 8 January 2001

Category: Miscellaneous; Keywords: search results

Searching domino may be simple and, sometimes, even powerful, but when it comes to displaying the results in a browser we, the developers, are left fairly restricted.

There seem to be several ways of presenting a large list of search results, depending on the site you use and the server they are running.

Consider this screen-grab from the Notes.net Discussion Forum:

Image

And this one from a search on the Microsoft.com homepage:

Image

I'll leave it up to you to decide which you prefer. Me, I'm with the Microsoft version. Not that I'm a great advocate of Microsoft, but the style they use is more common of web-sites nowadays. As ever, Lotus/Iris are not following suit.

Personally, I had never tried to reproduce this numbered-list style of results in domino, as I could see no way of doing it without using complicated scripts. Luckily, Chris Thorpe, of the Reader's Digest, has come up with a "simple" solution he is willing to share with us all.

The screen-grab below is of a search results form ($$SearchTemplateDefault) that uses this method. Doesn't look very "Notesy" does it ;-)

Image

Anyway, how do you do it?! Simple really (when you know how). Start by creating a Computed-Text area on the results form in place of your usual "Next" and "Previous" navigation links. Add the following formula to it:

REM "NOTE: start param must be before count param in the original URL";
pageString := "<a href=\"SearchView?" + @LeftBack(Query_String;"&start") + "&start=";

REM "We are limited to 250 docs by domino!!";
hitNum := @If(TotalHits > 250;250;TotalHits);

adJust := @Integer(hitNum/10);
endDate := @Text(@Adjust([01/01/1900];0;0;adJust;0;0;0);"D0S0");
numRange := @Explode(@TextToTime("01/01/1900 - " + endDate));
numList := (@TextToTime(numRange) - [01/01/1900]) / 86400;

textList1 := @Text(numList*10) + " - " + @Text((numList + 1)*10);
textList10 := @Text(numList * 10);

@If(TotalHits > 10;"<p>"+ @Implode(pageString + textList10 + "&count=10\">" + textList1 + "</a>";" | ");"&nbsp;")

By now you are probably thinking: "What on Earth is all that about?" Don't worry so was I when I first saw it.

Unless you really want to know how, you can simply paste the formula in and it should work after you've changed the name of the view you are searching. If you are like me and want to learn *exactly* what is happening, read on....

Line 1: pageString := "<a href=\"SearchView?" + @LeftBack(Query_String;"&start") + "&start=";

This line works out the what the first part of all the links is going to be. It is important that the "&count=" parameter appears after "&start=" so that it is not included in this part.

Line 2: hitNum := @If(TotalHits > 250;250;TotalHits);

This limits the whole thing to 250 hits - this is the default setting for the HTTP domino server task (NAB).

Line 3: adJust := @Integer(hitNum/10);

Here we divide the number of hits by 10 (hits per page) so we know exactly how many links we need to create.

Now this is where the clever part is.

Line 4: endDate := @Text(@Adjust([01/01/1900]; 0; 0; adJust; 0; 0; 0); "D0S0");

Create a date that is that is same number of days after 1/1/1900 as the number of pages required (adJust).

Line 5: numRange := @Explode( @TextToTime( "01/01/1900 - " + endDate));

The trick - use @Explode to produce a LIST of date strings between 1/1/1900 and the date from Line 4. This will contain the same number of items (dates) as links are required. Cool!

Line 6: numList := (@TextToTime(numRange) - [01/01/1900]) / 86400;

Turn this list of dates in to a list of multiples of 10 by subtracting 1/1/1900 from them all and then dividing by the number of seconds in a day.

Line 7: textList1 := @Text(numList*10) + " - " + @Text((numList + 1)*10);

Creates a list of number ranges from the start number times ten to a number ten greater. ie 0-10:10-20:20-30 etc

Line 8: textList10 := @Text(numList * 10);

Produces a list of values to append to the "&count=" parameter.

Line 9: @If(TotalHits > 10;"<p>"+ @Implode(pageString + textList10 + "&count=10\">" + textList1 + "</a>";" | ");"&nbsp;")

Bring it all together to produce the necessary HTML. Et Voila!

Finally, in Chris Thorpe's own words:

It's perverse, but it works!


To see more of his handywork and to see this technique in action take a look at this food recipe search. You can also download an example database I knocked up by clicking on its screenshot below:

Image



Note: The limitation of 250 documents in the result set is a default domino setting. You can change it using the following notes.ini entry:

QueryMaxResults=XXXX;

I've not tried this, but apparently anything approaching or above 5000 can become unstable.

Thanks to Lahbib Mouran for letting me know about this tip which first appeared here