question about paging

I use Tamino 4.1.4. There are 3,000 articles in the database,each from several kbytes to few mbytes in size. To page these articles,I use Xquery in server.The Xquery string is
“declare namespace ft=“http://www.w3.org/2002/04/xquery-operators-text
(for $a in input()/Document where
ft:text-contains( $a/ZhengWen,‘XXX’) return
{$a/ID,$a/BiaoTi,$a/ZhuTiCi,$a/XingZhi} ) [position()>=1260 and position()<=1272]”
Do in this way,each request to a page will connect Tamino and search again.The response is too slow.
Is there any better solution?
Thanks.

Hello,
optimization across the element constructor is currently not done. Therefore you should specify also the position filter before the element construction.
See hint in future 4.2 documentation:

Element construction
Optimization is currently not done across element construction. Therefore element construction should be postponed to the end of the result construction, for example:

Instead of:

( for $a in input()/contact sort by (zip)
where $a/street eq “AStreet”
and $a/zip gt 2134
return
{($a/name, $a/street,$a/zip)}

sort by (zip)
)[position() > 1100 and position() < 1150]

Use:

for $r in
(
(for $a in input()/contact sort by (zip)
where $a/street eq “AStreet”
and $a/zip gt 2134
return $a
)[position() > 1100 and position() < 1150]
)
return
{($r/name, $r/street)}




Best regards
Walter