@@ -0,0 +1,3188 @@
+package lux;%0A%0Aimport static org.junit.Assert.assertEquals;%0A%0Aimport java.util.Iterator;%0A%0Aimport org.apache.lucene.store.RAMDirectory;%0Aimport org.apache.lucene.document.Field.Store;%0A%0Aimport lux.XdmResultSet;%0Aimport lux.index.XmlIndexer;%0Aimport lux.index.field.XPathField;%0Aimport lux.index.field.FieldDefinition.Type;%0A%0Aimport net.sf.saxon.s9api.XdmItem;%0A%0Aimport org.junit.AfterClass;%0Aimport org.junit.BeforeClass;%0Aimport org.junit.Test;%0A%0A%0A/**%0A * Tests for features related to XPathFields.%0A */%0Apublic class XPathFieldTest %7B%0A    %0A    private static RAMDirectory dir;%0A    private static IndexTestSupport indexTestSupport;%0A%0A    @BeforeClass%0A    public static void setup () throws Exception %7B%0A        XmlIndexer indexer = new XmlIndexer ();%0A        indexer.getConfiguration().addField(new XPathField%3CInteger%3E(%22doctype%22, %22name(/*)%22, null, Store.NO, Type.STRING));%0A        %0A        dir = new RAMDirectory();%0A        indexTestSupport = new IndexTestSupport (indexer, dir);%0A    %7D%0A%0A    @AfterClass%0A    public static void cleanup () throws Exception %7B%0A        indexTestSupport.close(); // indexwriter close?%0A        dir.close();%0A    %7D%0A%0A    /**%0A     * test to ensure that ordering by lux:key() works%0A     *%0A     * function lux:key(name as xs:string) returning item%0A     * is a special function for use that accepts the name of a lucene field. %0A     * As an order by expression, it causes the enclosing sequence to be ordered%0A     * by the value of the given field. %0A     */%0A    @Test%0A    public void testOrderByKey () throws Exception %7B%0A        Evaluator eval = indexTestSupport.makeEvaluator();%0A        final String PITHY_QUOTE = %22%5C%22There are more things in heaven and earth, Horatio%5C%22%22; // , than are dreamt of in your philosophy%0A%0A        String xquery = %22for $doc in lux:search('%22 + PITHY_QUOTE + %22') return $doc/*/name()%22;%0A        XdmResultSet baseline = eval.evaluate (xquery);%0A        // should be ordered in document creation order, which corresponds%0A        // to document order from the original hamlet.xml:%0A        // PLAY, ACT, SCENE, SPEECH, LINE%0A        assertEquals (5, baseline.size());%0A        Iterator%3CXdmItem%3E iter = baseline.iterator();%0A        assertEquals (%22PLAY%22, iter.next().getStringValue());%0A        assertEquals (%22ACT%22, iter.next().getStringValue());%0A        assertEquals (%22SCENE%22, iter.next().getStringValue());%0A        assertEquals (%22SPEECH%22, iter.next().getStringValue());%0A        assertEquals (%22LINE%22, iter.next().getStringValue());%0A%0A        xquery = %22for $doc in lux:search('%22 + PITHY_QUOTE + %22')%22 + %0A            %22 order by lux:key($doc,'doctype') return $doc/*/name()%22;%0A        XdmResultSet results = eval.evaluate (xquery);%0A        // should be ordered by the names of the root elements:%0A        // ACT, LINE, PLAY, SCENE, SPEECH%0A        assertEquals (5, results.size());%0A        iter = results.iterator();%0A        assertEquals (%22ACT%22, iter.next().getStringValue());%0A        assertEquals (%22LINE%22, iter.next().getStringValue());%0A        assertEquals (%22PLAY%22, iter.next().getStringValue());%0A        assertEquals (%22SCENE%22, iter.next().getStringValue());%0A        assertEquals (%22SPEECH%22, iter.next().getStringValue());%0A    %7D%0A%0A    // TODO: test empty greatest / empty least%0A%7D%0A

test for ordering by lux:key() - now go make it so!