Solr/XForms Continued

Once I got down to implementing my Solr/Xforms integration I realized how many options I really have. In addition to the two mentioned in my last post I could also populate my Solr instance by sending a get request that would replace a dummy instance with a Solr record (generated by an XQuery). This request could be triggered when the user marks the form as complete. Then the instance could be sent to Solr when the user clicks on the publish button. Unfortunately I can’t seem to get this option working. I’m not sure if it is because of the way I have my instances are set up, or if I need an additional model for the Solr data. I’m using this tutorial as an example, and will keep plugging away at it. But for now I’m using the pop-up window method.

Here is what my “publish” button looks like:

<xforms:trigger ref="//dc:status[. = 'complete']">

  <xforms:label>Publish</xforms:label>

  <xforms:action ev:event="DOMActivate">

    <xforms:send submission="submitMetadata" />

    <xforms:load resource="javascript:openWin('addRecs.xql?pid={$pid}')" />

  </xforms:action>

</xforms:trigger>

This creates a pop-up XForm window generated by the addRecs.xql. This XQuery grabs all the descriptive metadata and also any transcripts if they are available and transforms it into a Solr style xml. It can be used for a single record or for all the records in the database. The pop-up XForm is very simple it looks like this:

<html xmlns:xf="http://www.w3.org/2002/xforms"

xmlns:ev="http://www.w3.org/2001/xml-events"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"

xmlns:dc="http://purl.org/dc/elements/1.1/" xsl:version="2.0">

  <head>

    <title>Send Data to Indexer</title>

    <meta http-equiv="Pragma" content="no-cache"/>

      <xf:model>

        <xf:instance>

   	  <add><!--Your Solr Record goes here --></add>

	</xf:instance>

	<xf:instance id="solr-resp">

	  <results xmlns=""/>

	</xf:instance>

	<xf:instance id="sendCommit">

	  <commit/>

	</xf:instance>

	<xf:submission id="submit" method="post" replace="instance"
	  instance="solr-resp" action="http://localhost/solr/update"/>

	*<xf:submission id="submitCommit" method="post" replace="instance"
	  instance="commit" ref="instance('sendCommit')" action="http://localhost/solr/update"/>

      </xf:model>

    </head>

    <body>

      <div id="main">

   	<div id="formInfo">

	  <xf:switch>

	   <xf:case id="case1" selected="true()">

	    <h2>Title of Record</h2>

		<div>

		<xf:trigger>

		  <xf:label>Add</xf:label>

		  <xf:action ev:event="DOMActivate">

		  <xf:send submission="submit" />

		  <xf:toggle case="case2" ev:event="DOMActivate"/>

		  </xf:action>

	   	</xf:trigger>

		</div>

	  </xf:case>

	  <xf:case id="case2">

	    <h2>Item submitted!</h2>

	    <div>

	     <xf:trigger>

	      <xf:label>Okay</xf:label>

		<xf:action ev:event="DOMActivate">

		<xf:send submission="submitCommit" />

		<xf:load resource="javascript:window.close()" />

	        </xf:action>

	    </xf:trigger>

	   </div>

	 </xf:case>

	</xf:switch>

	</div>

     </div>

    </body>

</html>

When the user presses the “add” button the main instance is posted to Solr and the form toggles to the commit view. This view says: “Item Submitted!” The user presses “okay” to send the commit command and close the pop-up window. It may not be the most elegant solution but it works for now.

I also took this opportunity to revamp the user interface. Previously it was one long form with multiple save buttons scattered throughout the form. This was unwieldy and really didn’t make much sense, so I’ve be switched to a tabbed UI (like this) with 4 tabs: “Citation Information,” “Resource Description,” “Subject Analysis,” “Related Items” and “View”. The tabs will eliminate the need for multiple save buttons throughout the form, and make the data more compact and, I hope, easier to navigate. Here is a snapshot of what the new form looks like:

XForm metadata editor

As you can see there are 4 tabs and two buttons. The “View” tab first saves the record and then toggles to an xforms:case with xforms:output for each element. In addition this gives a link to the “public view” of the record so the metadata librarian can see the page images and the data in context. It is a little garish but the multi-colored tabs saves me from writing any JavaScript to highlight the active tab.

*Opps, the code for the pop-up window was missing a crucial part, the ref attribute in the second submit. I added it to the code above, so everything should work now. The ref attribute isn’t necessary (although it may be good practice) in the first submission because if there is no instance specified the control will assume the first instance. (So yesterday’s code sent the record to Solr twice, but never sent a commit.)

Advertisements

14 Responses to “Solr/XForms Continued”

  1. XForms exhaustion « the DIL Says:

    […] the DIL One ‘l’ short of a savory little herb. A Digital Initiative Librarian’s blog. « Solr/XForms Continued […]

  2. Update on CDI XForms « the DIL Says:

    […] “processing pages” on xforms@code4lib. This version is in xquery and includes the new tabbed version of the DC forms and also a version of my Solr form. I have also included a sample record. […]

  3. Krista Says:

    Hi, I am trying to copy your code to an extent (this is my first attempt at XForms). I want to use an xform to add and commit information to Solr directly. (Only Solr, not eXist) I’m having trouble… for one thing, my triggers are not even displayed as buttons. Can you give me any hints?

    Here is my code:

    Add New OPPIE Help Page

    Add New Help Page
    Enter data for help page below.

    Title
    ID
    Creation Date

    Add

    Item submitted

    Commit

    <!– –>

    Thank you!

  4. Krista Says:

    Ok… here is my code again.

    <head>
    <title>Add New OPPIE Help Page</title>

    <xf:model id=”model1″>
    <xf:instance id=”add”>
    <add>
    <doc>
    <field name=”pagetitle”/>
    <field name=”systemid”/>
    <field name =”creationdate”/>
    </doc>
    </add>
    </xf:instance>
    <xf:instance id=”commit”>
    <commit/>
    </xf:instance>

    <xf:submission id=”submit” method=”post” replace=”instance” inxtance=”add” ref=”instance(‘add’)” action=”http://emperor.lanl.gov:8150/solr/update” />
    <xf:submission id=”submitCommit” method=”post” replace=”instance” instance=”commit” ref=”instance(‘commit’)” action=”http://emperor.lanl.gov:8150/solr/update”/>
    </xf:model>

    </head>

    <body>
    <h1>Add New Help Page</h1>
    <p>Enter data for help page below.</p>

    <input type=”text” model=”model1″ ref=”pagetitle”><label>Title</label></input><br/>
    <input type=”text” model=”model1″ ref=”systemid”><label>ID</label></input><br/>
    <input type=”text” model=”model1″ ref=”creationdate”><label>Creation Date</label></input><br/>

    <xf:switch>
    <xf:case id=”case1″>
    <xf:trigger>
    <xf:label<head>
    <title>Add New OPPIE Help Page</title>

    <xf:model id=”model1″>
    <xf:instance id=”add”>
    <add>
    <doc>
    <field name=”pagetitle”/>
    <field name=”systemid”/>
    <field name =”creationdate”/>
    </doc>
    </add>
    </xf:instance>
    <xf:instance id=”commit”>
    <commit/>
    </xf:instance>

    <xf:submission id=”submit” method=”post” replace=”instance” inxtance=”add” ref=”instance(‘add’)” action=”http://emperor.lanl.gov:8150/solr/update” />
    <xf:submission id=”submitCommit” method=”post” replace=”instance” instance=”commit” ref=”instance(‘commit’)” action=”http://emperor.lanl.gov:8150/solr/update”/>
    </xf:model>

    </head>

    <body>
    <h1>Add New Help Page</h1>
    <p>Enter data for help page below.</p>

    <input type=”text” model=”model1″ ref=”pagetitle”><label>Title</label></input><br/>
    <input type=”text” model=”model1″ ref=”systemid”><label>ID</label></input><br/>
    <input type=”text” model=”model1″ ref=”creationdate”><label>Creation Date</label></input><br/>

    <xf:switch>
    <xf:case id=”case1″>
    <xf:trigger>
    <xf:label>Add</xf:label>
    <xf:action ev:event=”DOMActivate”>
    <xf:send submission=”submit” />
    <xf:toggle case=”case2″ ev:event=”DOMActivate”/>
    </xf:action>
    </xf:trigger>
    </xf:case>
    <xf:case id=”case2″>
    <h2>Item submitted</h2>
    <xf:trigger>
    <xf:label>Commit</xf:label>
    <xf:action ev:event=”DOMActivate”>
    <xf:send submission=”submitCommit” />
    <!– <xf:load resource=”javascript:window.close()”/> –>
    </xf:action>
    </xf:trigger>
    </xf:case>
    </xf:switch>
    </body>
    </html>Add</xf:label>
    <xf:action ev:event=”DOMActivate”>
    <xf:send submission=”submit” />
    <xf:toggle case=”case2″ ev:event=”DOMActivate”/>
    </xf:action>
    </xf:trigger>
    </xf:case>
    <xf:case id=”case2″>
    <h2>Item submitted</h2>
    <xf:trigger>
    <xf:label>Commit</xf:label>
    <xf:action ev:event=”DOMActivate”>
    <xf:send submission=”submitCommit” />
    <!– <xf:load resource=”javascript:window.close()”/> –>
    </xf:action>
    </xf:trigger>
    </xf:case>
    </xf:switch>
    </body>
    </html>

  5. wsalesky Says:

    Krista,
    I responded to you via e-mail, with a working version of your form. Let me know if you didn’t get it.

  6. ilango gurusamy Says:

    Hi
    The article was very interesting and I intend to try out your examples.
    Could you explain how you got X-Forms and Solr configured?

    Thanks very much.
    ilango

  7. ilango gurusamy Says:

    Krista
    How did you get XForms to work with Solr. I would appreciate your help very much

  8. wsalesky Says:

    Ilango,
    You should be able to post directly from your XForm to Solr.
    like this:

    < xf:submission id=”submitCommit” method=”post” replace=”instance”
    instance=”sendCommit” ref=”instance(‘sendCommit’)” action=”http://cdi.uvm.edu:8082/solr/update”/>

    This will post the contents of your xforms instance (id=”solr”) to your Solr, you will also need to have a button to send a commit command as well. If you would like I can send you a sample xforms doc that sends a dublin core record to solr, and then sends a commit command.

  9. wsalesky Says:

    Okay, here is a link to a sample form. If you view the source code you will be able to see how i get my xforms talking to solr.
    Solr Form

    Hope that helps. Let me know if you have other questions.

  10. ilango gurusamy Says:

    Thanks very much. I appreciate your reply. I will try your suggestions in an hour and get back to you.

  11. ilango gurusamy Says:

    Hi
    That will be great. Could you send me the sample XForms doc that sends a Dublin Core Record to Solr.

    I would appreciate that very much.

    This is my first attempt at XForms and I have in mind the following sample application:

    I have a simple XForm with a push button on it, that has a label “Create a description”

    This will pull up a pop-up window with the following in it:
    1) A Drop-Down Menu (Pick-List) “Countries” with say, USA, Russia, Germany as individual menu items.
    2) A second Drop-Down Menu called “States”. The set of items in this menu is dependent on the selection made by the user in Countries. If the User selected USA in the first menu, the items in the second list will be ‘Arkansas’, ‘Michigan’,’Alaska’.
    If the user’s choice was Russia, the corresponding items in the second pick list would be ‘Primorsky Krai’,’Ingushetiya’ & ‘Smolenskaya’.
    If the user’s choice were to be Germany, we might have a corresponding set
    3) A third Drop-down menu called Capital whose item set is again dependent on the selections made in ‘States’

    So, if the user’s choice were to be Primorsky Krai the corresponding item set in the third menu would consist of one item “Vladivostok’ ( i hope i got my geography right!)

    Clicking on Vladivostok would result in the following action: a text-box under these menus is populated with a description of Vladivostok.
    “Vladivostok (Russian: Владивосто́к (help·info)) is Russia’s largest port city on the Pacific Ocean and the administrative center of Primorsky Krai. It is situated at the head of the Golden Horn Bay not far from the Russo-Chinese border and North Korea. It is the home port of the Russian Pacific Fleet.”

    What approach can I take for this little application?

    thanks very much
    ilango

  12. ilango gurusamy Says:

    Thanks for sending me the sample. I hadn’t seen it this morning and I sent out a request for the sample. My apologies.

  13. ilango gurusamy Says:

    I am already working on my little app as diligently as I can. Sorry about the long post. I do not mean to burden you!!

  14. ilango gurusamy Says:

    I have come up with a way to do this, but I still have a problem with how to get the data into the instance from a Relational Database or an XML database using eXist.
    I can post the code if you think it might help other people here as well, including having you look over my code at your convenience.
    thanks

Comments are closed.


%d bloggers like this: