Hi Huib
Hi Jan,Op 12 feb 2011, om 01:33 heeft Jan Vlčinský (CAD) het volgende geschreven:I wonder - is there any way, how to optimize collection by REST after new document is submited?On the JAX-RX page (http://docs.basex.org/wiki/JAX-RX_API) it says you can issue commands like this:
<
text
>show users</
text
>
<
parameter
name
=
"wrap"
value
=
"no"
/>
</
command
>
So I guess to optimize you would send this:using this:curl -i -X POST -H "Content-Type: application/query+xml" -d@optimize.xml "localhost:8984/basex/jax-rx/factbook/"where factbook/ specifies the collection to optimize and the optimize.xml file contains the above optimize command.After that you can send a query like this:
<
text
>for $c in //city return $c/name</
text
>
<
parameter
name
=
"count"
value
=
"5"
/>
<
parameter
name
=
"output"
value
=
"indent=no"
/>
</
query
>
I assume, that for proper performance of XQuery is optimize needed, as adding new document probably breaks previous indices.I find BaseX performs really well without regular optimize, but I'm not sure if it uses the indexes or not and when exactly the indexes are no longer used, I can't find any info in the Query Info window for example. But never mind, it works very well and I'll just wait for the incremental indexes. (In fact I just optimized my collection using the above method and BaseX responded a little slower after that, even after a while using it (I thought the caches may have emptied by the optimze - pure speculation here ;-)). After a restart it was up to speed again.)And with REST, as I understand, there is no state. Taking into consideration, that to optimize a collection, it has to be first opened, then in next command it can be optimized, there is a problem, that the optimize command has no context of opened collection, as there is no state preserved. Or do I understand something wrong?The state is missing from the HTTP communication, it's not about the context of an opened collection in BaseX. When using REST you're specifying the context in the URL, e.g. http://localhost:8984/basex/jax-rx/factbook?query=//city/name&count=5 where factbook is the collection your querying.I know, I can use PythonAPI for opening the database and running optimize, but I would prefer to keep my solution as simple as possible and using 2 API (REST + Python API) is more complex then one (just REST).The REST interface is quite simple I find, and it also makes it easy to query your docs from the command line using curl.Hartelijke groet,Huib