You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jason Smith <js...@tutorbuddy.com> on 2001/07/10 21:27:19 UTC

Sorting search results in Cocoon

I'm kind of new at this whole XML/XSP/XSL thing, so if this has a simple
solution,
please bear with me.

Here's the situation: I have a search engine that passes out search results
as XML
to anything that can make a HTTP request to it. When it returns the results,
it looks 
something like this:

<searchresults>
	<result>
		<name>Result 1</name>
		<description>This is result 1</description>
		<href>http://here.com/index.html</href>
		<score>2.3</score>
	</result>

	<result>
		<name>Result 2</name>
		<description>This is another result</description>
		<href>http://there.com/index.html</href>
		<score>1.2</score>
	</result>		

	etc.
</searchresults>


The <result> elements can be repeated infinitely depending on how many
search
results the engine finds that match search query. <score> is the search
result's 
ranking against the search query; the rest of the elements in <result> are 
self-explanatory. 

The search engine returns ALL matches at once in one big XML file. There
could be a dozen search results, 100, or 1.

How would one go about limiting those results in Cocoon? Say I get 100
results,
but I only want to display the top 10 results by score. I'm assuming XSP
is the answer, but I've been going nuts trying to get this stuff to work.
I have O'Reilly's "Java and XML" on back-order, so hopefully that can clear
up my confusion, but until then, anybody got any ideas or some direction
for me?

Thanks for any help.

J

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>


Re: Sorting search results in Cocoon

Posted by Sergio Carvalho <se...@acm.org>.
The most efficient way would be to limit the XML source - having the search engine do the sorting and limiting for yourself. That being impossible, you can do it with an XSLT transformation for sorting: 
 http://www.w3.org/TR/xslt.html#sorting
 http://www.w3.org/TR/xslt.html#copying
and another to select the topmost N:
 http://www.w3.org/TR/xslt.html#section-Applying-Template-Rules
 http://www.w3.org/TR/xpath.html#function-position

You can get better help at XML/XSL specific mailing lists.

On Tue, 10 Jul 2001 15:27:19 -0400, Jason Smith <js...@tutorbuddy.com> wrote:
--
> I'm kind of new at this whole XML/XSP/XSL thing, so if this has a simple
> solution,
> please bear with me.
> 
> Here's the situation: I have a search engine that passes out search results
> as XML
> to anything that can make a HTTP request to it. When it returns the results,
> it looks 
> something like this:
> 
> <searchresults>
> 	<result>
> 		<name>Result 1</name>
> 		<description>This is result 1</description>
> 		<href>http://here.com/index.html</href>
> 		<score>2.3</score>
> 	</result>
> 
> 	<result>
> 		<name>Result 2</name>
> 		<description>This is another result</description>
> 		<href>http://there.com/index.html</href>
> 		<score>1.2</score>
> 	</result>		
> 
> 	etc.
> </searchresults>
> 
> 
> The <result> elements can be repeated infinitely depending on how many
> search
> results the engine finds that match search query. <score> is the search
> result's 
> ranking against the search query; the rest of the elements in <result> are 
> self-explanatory. 
> 
> The search engine returns ALL matches at once in one big XML file. There
> could be a dozen search results, 100, or 1.
> 
> How would one go about limiting those results in Cocoon? Say I get 100
> results,
> but I only want to display the top 10 results by score. I'm assuming XSP
> is the answer, but I've been going nuts trying to get this stuff to work.
> I have O'Reilly's "Java and XML" on back-order, so hopefully that can clear
> up my confusion, but until then, anybody got any ideas or some direction
> for me?
> 
> Thanks for any help.
> 
> J
> 
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
> 
> To unsubscribe, e-mail: <co...@xml.apache.org>
> For additional commands, e-mail: <co...@xml.apache.org>



--
Sergio Carvalho
---------------
sergio.carvalho@acm.org

If at first you don't succeed, skydiving is not for you

---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <co...@xml.apache.org>
For additional commands, e-mail: <co...@xml.apache.org>