0

In my web application, the whole search page is written in XQuery. The query does not just find and display the results, but also writes the search term into a protocol file (in eXist db, this is possible with the file:serialize-function).

However, it might happen that writing the protocol takes some time. And of course, the user should not be affected by this delay. So, I'd like to first output the search results and then update the protocol.

I've tried to put the protocol function after the return of the content like:

return $search_results,localfunction:write_protocol()

(The function localfunction:write_protocol() always returns the empty sequence ().)

But that doesn't work. The content of $search_results is only output, once localfunction:write_protocol() is finished.

Is there anything I can do here? (I know, such things are problematic also in more processual languages like PHP.)

cis
  • 1,259
  • 15
  • 48
  • 1
    If I understand correctly, this isn't really specific to XQuery. You could split your page into two requests, return the fast one first, and have that page query the second one via AJAX. – wst Jun 30 '15 at 15:44

2 Answers2

2

I would suggest using the Scheduler module in eXist to schedule an XQuery task to write your protocol file. The scheduler module provides several XQuery functions that you can use from your main query to schedule the sub-task; That will then be done asynchronously to the rest of your query.

adamretter
  • 3,885
  • 2
  • 23
  • 43
0

Instead of writing an external file, could you write the relevant protocol data to a collection in the database?

You could then use an XQuery Trigger to process that collection and write the data to an external file.

There is also the option of a custom log file using util:log-app.

GSpringTech
  • 156
  • 3
  • Sure, writing the protocol entries into the database instead of an external file is possible and maybe even more convenient. However, the problem remains the same: The XQuery will only return the search results once it has finished executing. Thus, the user will have to wait for the protocol entry being written into the database before he sees the results of his search. – cis Jul 01 '15 at 07:20