|
454 | 454 | <sect2> |
455 | 455 | <title>Re-indexing</title> |
456 | 456 |
|
457 | | - <para>After you have created or modified your configuration file, you must re-index any data that you have. This can be done by executing the |
458 | | - following two XQuery lines:</para> |
| 457 | + <para>After you have created or modified your collection configuration |
| 458 | + file, you must re-index any data that you have. This can be done |
| 459 | + by executing the following two XQuery lines (supplying your |
| 460 | + eXist administrative user's password in place of |
| 461 | + <code>myadminpassword</code>, since reindexing requires |
| 462 | + administrative privileges):</para> |
459 | 463 |
|
460 | 464 | <programlisting xlink:href="listings/listing-7.txt"/> |
461 | | - <para>You can run this query directly in <!--eXide-->, or you can also |
462 | | - store the following XQuery script in the app's |
463 | | - <code>admin</code> collection and call it via your browser. |
464 | | - The script will login as the administrator and then run the |
465 | | - <code>xmldb:reindex</code> function (which needs |
466 | | - administrative privileges) on the data collection. It also |
467 | | - returns the time used to reindex the collection. For collections |
468 | | - that are under 1,000 medium sized 10K byte documents, this |
469 | | - script usually runs in a few seconds. Tools are available for |
470 | | - larger collections to schedule indexing during off hours with |
471 | | - the eXist job scheduler.</para> |
| 465 | + <para>You can run this query directly in eXide, or you can also store the |
| 466 | + following XQuery script in the app's <code>admin</code> |
| 467 | + collection and call it via your browser. The script will login |
| 468 | + as the administrator and then run the <code>xmldb:reindex</code> |
| 469 | + function on the data collection. It also returns the time used |
| 470 | + to reindex the collection. For collections that are under 1,000 |
| 471 | + medium sized 10K byte documents, this script usually runs in a |
| 472 | + few seconds. Tools are available for larger collections to |
| 473 | + schedule indexing during off hours with the eXist job |
| 474 | + scheduler.</para> |
472 | 475 | <para><code>/db/apps/terms/admin/reindex.xq</code></para> |
473 | 476 | <programlisting xlink:href="listings/listing-8.txt"/> |
474 | 477 | <para>The result will be:</para> |
|
584 | 587 | <para>Note that this form does "double duty" as both a form for new items |
585 | 588 | and a form for updating existing items. The |
586 | 589 | <code>new=true</code> parameter must always be passed to the |
587 | | - form when creating a new item. A more sophisticated production |
| 590 | + form when creating a new item. (A more sophisticated production |
588 | 591 | systems would check for these parameters and return error codes |
589 | | - if one or the other is not passed to the form.</para> |
| 592 | + if one or the other is not passed to the form.) In order to |
| 593 | + create the new item, the form fetches a document containing |
| 594 | + blank fields to be used as a template for the form.</para> |
| 595 | + <para> |
| 596 | + <code>/db/apps/terms/edit/new-instance.xml</code>:</para> |
| 597 | + |
| 598 | + <programlisting xlink:href="listings/listing-13.xml"/> |
590 | 599 | <para>All XForms hold the form data in the <tag>xf:model</tag> element. |
591 | 600 | This form uses a single <tag>xf:instance</tag> element within |
592 | 601 | the model to store the data that will saved when the user clicks |
|
605 | 614 | <para>The query that is used is wrapped inside of the <code>action</code> |
606 | 615 | attribute of the save submission. Here is the portion from |
607 | 616 | <code>edit.xq</code> with this code: </para> |
608 | | - <programlisting xlink:href="listings/listing-13.txt"/> |
| 617 | + <programlisting xlink:href="listings/listing-14.txt"/> |
609 | 618 | <para>You can see that if the user is creating a new item the data is sent |
610 | 619 | via an HTTP POST request to the <code>save-new.xq</code> query. |
611 | 620 | If the user does not have a new item the POST data is sent to |
|
619 | 628 | updated. </para> |
620 | 629 | <para>The next section of code to notice is that the ID element is only displayed using a read-only <tag>xf:output</tag> element if the form is |
621 | 630 | in update mode.</para> |
622 | | - <programlisting xlink:href="listings/listing-14.txt"/> |
| 631 | + <programlisting xlink:href="listings/listing-15.txt"/> |
623 | 632 | <para>This shows some of the power of combining XQuery and XForms. In this |
624 | 633 | case we are using logic on the server to conditionally include |
625 | 634 | portions of the form based on the context. Contextual indicators |
|
652 | 661 | with elements. </para> |
653 | 662 | <para>The final part of the form contains the instructions needed to place the XSLTForms processing instruction at the top of the file when it |
654 | 663 | is rendered.</para> |
655 | | - <programlisting xlink:href="listings/listing-15.txt"/> |
656 | | - <para>You can also add a directive that will put the XSLTForms system into a debug mode by adding the following .</para> |
657 | 664 | <programlisting xlink:href="listings/listing-16.txt"/> |
| 665 | + <para>You can also add a directive that will put the XSLTForms system into a debug mode by adding the following:</para> |
| 666 | + <programlisting xlink:href="listings/listing-17.txt"/> |
658 | 667 | </sect2> |
659 | 668 |
|
660 | 669 | <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> |
|
666 | 675 | next ID to be used in a small XML file with only one element in the root called <emphasis role="bold">next-id</emphasis>. Here is that file: </para> |
667 | 676 | <para> |
668 | 677 | <code>/db/apps/terms/edit/next-id.xml</code>: </para> |
669 | | - <programlisting language="xml" xlink:href="listings/listing-17.xml"/> |
| 678 | + <programlisting language="xml" xlink:href="listings/listing-18.xml"/> |
670 | 679 | <para>The <tag>next-id</tag> element is updated using an XQuery "update |
671 | 680 | function" when new items are saved to the data collection. We |
672 | 681 | save the file using the number as the filename; in this case, |
|
679 | 688 |
|
680 | 689 | <para> |
681 | 690 | <code>/db/apps/terms/edit/save-new.xq</code>: </para> |
682 | | - <programlisting xlink:href="listings/listing-18.txt"/> |
| 691 | + <programlisting xlink:href="listings/listing-19.txt"/> |
683 | 692 | </sect2> |
684 | 693 |
|
685 | 694 | <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> |
|
692 | 701 | updated and re-indexed upon the store operation. </para> |
693 | 702 | <para> |
694 | 703 | <code>/db/apps/terms/edit/update.xq</code>:</para> |
695 | | - <programlisting xlink:href="listings/listing-19.txt"/> |
| 704 | + <programlisting xlink:href="listings/listing-20.txt"/> |
696 | 705 | </sect2> |
697 | 706 | </sect1> |
698 | 707 |
|
|
718 | 727 | appropriately with a red warning indicator.</para> |
719 | 728 | <para> |
720 | 729 | <code>/db/apps/terms/edit/delete-confirm.xq</code>: </para> |
721 | | - <programlisting xlink:href="listings/listing-20.txt"/> |
| 730 | + <programlisting xlink:href="listings/listing-21.txt"/> |
722 | 731 | </sect2> |
723 | 732 | </sect1> |
724 | 733 |
|
|
730 | 739 | <para>The delete script also takes a single REST parameter of the ID</para> |
731 | 740 | <para> |
732 | 741 | <code>/db/apps/terms/edit/delete.xq</code>: </para> |
733 | | - <programlisting xlink:href="listings/listing-21.txt"/> |
| 742 | + <programlisting xlink:href="listings/listing-22.txt"/> |
734 | 743 | </sect1> |
735 | 744 |
|
736 | 745 | <!-- ================================================================== --> |
|
743 | 752 | below.</para> |
744 | 753 | <para> |
745 | 754 | <code>/db/apps/terms/index.html</code>: </para> |
746 | | - <programlisting language="xml" xlink:href="listings/listing-22.xml"/> |
| 755 | + <programlisting language="xml" xlink:href="listings/listing-23.xml"/> |
747 | 756 | <informalfigure> |
748 | 757 | <mediaobject> |
749 | 758 | <imageobject> |
|
0 commit comments