Example usage for java.text Collator compare

List of usage examples for java.text Collator compare

Introduction

In this page you can find the example usage for java.text Collator compare.

Prototype

@Override
public int compare(Object o1, Object o2) 

Source Link

Document

Compares its two arguments for order.

Usage

From source file:org.jahia.ajax.gwt.content.server.JahiaContentManagementServiceImpl.java

@Override
public PagingLoadResult<GWTJahiaNode> searchSQL(String searchString, int limit, int offset,
        List<String> nodeTypes, List<String> fields, boolean sortOnDisplayName)
        throws GWTJahiaServiceException {
    List<GWTJahiaNode> gwtJahiaNodes = search.searchSQL(searchString, limit, offset, nodeTypes, null, null,
            fields, retrieveCurrentSession());
    int total = gwtJahiaNodes.size();
    if (limit >= 0) {
        try {//from  w  ww  .  j a  va  2 s. co m
            Query q = retrieveCurrentSession().getWorkspace().getQueryManager().createQuery(searchString,
                    Query.JCR_SQL2);
            total = (int) q.execute().getNodes().getSize();
        } catch (RepositoryException e) {
            logger.error(e.getMessage(), e);
        }
    }
    if (sortOnDisplayName) {
        final Collator collator = Collator.getInstance(retrieveCurrentSession().getLocale());
        Collections.sort(gwtJahiaNodes, new Comparator<GWTJahiaNode>() {
            @Override
            public int compare(GWTJahiaNode o1, GWTJahiaNode o2) {
                return collator.compare(o1.getDisplayName(), o2.getDisplayName());
            }
        });
    }
    return new BasePagingLoadResult<GWTJahiaNode>(gwtJahiaNodes, offset, total);
}

From source file:org.nuclos.client.main.MainController.java

public List<GenericAction> getGenericActions() {
    List<GenericAction> result = new ArrayList<GenericAction>();

    getFileMenuActions(result);/*from   ww  w .j av a 2s.  com*/
    getAdministrationMenuActions(result);
    getConfigurationMenuActions(result);
    //getHelpMenuActions(result);

    List<GenericAction> sortedResult = new ArrayList<GenericAction>();
    getEntityMenuActions(sortedResult);
    getNucletComponentMenuActions(sortedResult);
    getCustomComponentMenuActions(sortedResult);
    getTasklistMenuActions(sortedResult);

    final Collator collator = Collator.getInstance(Locale.getDefault());
    final Comparator<String[]> arrayCollator = ComparatorUtils.arrayComparator(collator);
    Collections.sort(sortedResult, new Comparator<GenericAction>() {
        @Override
        public int compare(GenericAction p1, GenericAction p2) {
            int cmp = arrayCollator.compare(p1.y.x, p2.y.x);
            if (cmp == 0)
                cmp = collator.compare(p1.y.y.getValue(Action.NAME), p2.y.y.getValue(Action.NAME));
            return cmp;
        }
    });
    result.addAll(sortedResult);

    addSearchFilterActions(result);
    addReportActions(result);
    getWorkspaceChooserController().addGenericActions(result);

    return result;
}

From source file:Main.java

public static final int compareNatural(String firstString, String secondString) {
    int firstIndex = 0;
    int secondIndex = 0;

    Collator collator = Collator.getInstance();

    while (true) {
        if (firstIndex == firstString.length() && secondIndex == secondString.length()) {
            return 0;
        }/*www  .j av a  2  s . c o  m*/
        if (firstIndex == firstString.length()) {
            return -1;
        }
        if (secondIndex == secondString.length()) {
            return 1;
        }

        if (Character.isDigit(firstString.charAt(firstIndex))
                && Character.isDigit(secondString.charAt(secondIndex))) {
            int firstZeroCount = 0;
            while (firstString.charAt(firstIndex) == '0') {
                firstZeroCount++;
                firstIndex++;
                if (firstIndex == firstString.length()) {
                    break;
                }
            }
            int secondZeroCount = 0;
            while (secondString.charAt(secondIndex) == '0') {
                secondZeroCount++;
                secondIndex++;
                if (secondIndex == secondString.length()) {
                    break;
                }
            }
            if ((firstIndex == firstString.length() || !Character.isDigit(firstString.charAt(firstIndex)))
                    && (secondIndex == secondString.length()
                            || !Character.isDigit(secondString.charAt(secondIndex)))) {
                continue;
            }
            if ((firstIndex == firstString.length() || !Character.isDigit(firstString.charAt(firstIndex)))
                    && !(secondIndex == secondString.length()
                            || !Character.isDigit(secondString.charAt(secondIndex)))) {
                return -1;
            }
            if ((secondIndex == secondString.length()
                    || !Character.isDigit(secondString.charAt(secondIndex)))) {
                return 1;
            }

            int diff = 0;
            do {
                if (diff == 0) {
                    diff = firstString.charAt(firstIndex) - secondString.charAt(secondIndex);
                }
                firstIndex++;
                secondIndex++;
                if (firstIndex == firstString.length() && secondIndex == secondString.length()) {
                    return diff != 0 ? diff : firstZeroCount - secondZeroCount;
                }
                if (firstIndex == firstString.length()) {
                    if (diff == 0) {
                        return -1;
                    }
                    return Character.isDigit(secondString.charAt(secondIndex)) ? -1 : diff;
                }
                if (secondIndex == secondString.length()) {
                    if (diff == 0) {
                        return 1;
                    }
                    return Character.isDigit(firstString.charAt(firstIndex)) ? 1 : diff;
                }
                if (!Character.isDigit(firstString.charAt(firstIndex))
                        && !Character.isDigit(secondString.charAt(secondIndex))) {
                    if (diff != 0) {
                        return diff;
                    }
                    break;
                }
                if (!Character.isDigit(firstString.charAt(firstIndex))) {
                    return -1;
                }
                if (!Character.isDigit(secondString.charAt(secondIndex))) {
                    return 1;
                }
            } while (true);
        } else {
            int aw = firstIndex;
            int bw = secondIndex;
            do {
                firstIndex++;
            } while (firstIndex < firstString.length() && !Character.isDigit(firstString.charAt(firstIndex)));
            do {
                secondIndex++;
            } while (secondIndex < secondString.length()
                    && !Character.isDigit(secondString.charAt(secondIndex)));

            String as = firstString.substring(aw, firstIndex);
            String bs = secondString.substring(bw, secondIndex);
            int subwordResult = collator.compare(as, bs);
            if (subwordResult != 0) {
                return subwordResult;
            }
        }
    }
}

From source file:org.alfresco.repo.node.getchildren.GetChildrenCannedQueryTest.java

private void sortAndCheck(NodeRef parentNodeRef, QName sortPropQName, boolean sortAscending) {
    List<Pair<QName, Boolean>> sortPairs = new ArrayList<Pair<QName, Boolean>>(1);
    sortPairs.add(new Pair<QName, Boolean>(sortPropQName, sortAscending));

    PagingResults<NodeRef> results = list(parentNodeRef, -1, -1, 0, null, null, sortPairs);

    int count = results.getPage().size();
    assertTrue(count > 3);/* w  w  w  .j a  va 2  s . co  m*/

    if (logger.isInfoEnabled()) {
        logger.info("testSorting: " + count + " items [" + sortPropQName + ","
                + (sortAscending ? " ascending" : " descending") + "]");
    }

    Collator collator = AlfrescoCollator.getInstance(I18NUtil.getContentLocale());

    // check order
    Serializable prevVal = null;
    NodeRef prevNodeRef = null;
    int currentIteration = 0;

    boolean allValsNull = true;

    for (NodeRef nodeRef : results.getPage()) {
        currentIteration++;

        Serializable val = null;

        if (sortPropQName.equals(GetChildrenCannedQuery.SORT_QNAME_CONTENT_SIZE)
                || sortPropQName.equals(GetChildrenCannedQuery.SORT_QNAME_CONTENT_MIMETYPE)) {
            // content data properties (size or mimetype)
            ContentData cd = (ContentData) nodeService.getProperty(nodeRef, ContentModel.PROP_CONTENT);
            if (cd != null) {
                if (sortPropQName.equals(GetChildrenCannedQuery.SORT_QNAME_CONTENT_SIZE)) {
                    val = cd.getSize();
                } else if (sortPropQName.equals(GetChildrenCannedQuery.SORT_QNAME_CONTENT_MIMETYPE)) {
                    val = cd.getMimetype();
                }
            }
        } else if (sortPropQName.equals(GetChildrenCannedQuery.SORT_QNAME_NODE_TYPE)) {
            val = nodeService.getType(nodeRef);
        } else if (sortPropQName.equals(GetChildrenCannedQuery.SORT_QNAME_NODE_IS_FOLDER)) {
            val = dictionaryService.isSubClass(nodeService.getType(nodeRef), ContentModel.TYPE_FOLDER);
        } else {
            val = nodeService.getProperty(nodeRef, sortPropQName);
        }

        if (logger.isInfoEnabled()) {
            logger.info("testSorting:     [" + nodeRef + ", " + val + "]");
        }

        int result = 0;

        if (val != null) {
            allValsNull = false;
        }

        if (prevVal == null) {
            result = (val == null ? 0 : 1);
        } else if (val == null) {
            result = -1;
        } else {
            if (val instanceof Date) {
                result = ((Date) val).compareTo((Date) prevVal);
            } else if (val instanceof String) {
                result = collator.compare((String) val, (String) prevVal);
            } else if (val instanceof Long) {
                result = ((Long) val).compareTo((Long) prevVal);
            } else if (val instanceof Integer) {
                result = ((Integer) val).compareTo((Integer) prevVal);
            } else if (val instanceof QName) {
                result = ((QName) val).compareTo((QName) prevVal);
            } else if (val instanceof Boolean) {
                result = ((Boolean) val).compareTo((Boolean) prevVal);
            } else {
                fail("Unsupported sort type (" + nodeRef + "): " + val.getClass().getName());
            }

            String prevName = (String) nodeService.getProperty(prevNodeRef, ContentModel.PROP_NAME);
            String currName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);

            if (!sortAscending) {
                assertTrue("Not descending: " + result + "\n" + "   Iteration: " + currentIteration + " out of "
                        + count + "\n" + "   Previous:  " + prevNodeRef + " had " + prevVal + " (" + prevName
                        + ")\n" + "   Current :  " + nodeRef + " had " + val + " (" + currName + ")",
                        result <= 0);
            } else {
                assertTrue("Not ascending: " + result + "\n" + "   Iteration: " + currentIteration + " out of "
                        + count + "\n" + "   Previous:  " + prevNodeRef + " had " + prevVal + " (" + prevName
                        + ")\n" + "   Current :  " + nodeRef + " had " + val + " (" + currName + ")",
                        result >= 0);
            }
        }
        prevVal = val;
        prevNodeRef = nodeRef;
    }

    assertFalse("All values were null", allValsNull);
}

From source file:org.alfresco.repo.search.impl.lucene.ADMLuceneTest.java

/**
 * @throws Exception/*  www.j  a v a 2 s.com*/
 */
public void testSort() throws Exception {
    Collator collator = Collator.getInstance(I18NUtil.getLocale());

    luceneFTS.pause();
    buildBaseIndex();
    runBaseTests();

    ADMLuceneSearcherImpl searcher = buildSearcher();

    SearchParameters sp = new SearchParameters();
    sp.addStore(rootNodeRef.getStoreRef());
    sp.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp.setQuery("PATH:\"//.\"");
    sp.addSort("ID", true);
    ResultSet results = searcher.query(sp);

    String current = null;
    for (ResultSetRow row : results) {
        String id = row.getNodeRef().getId();

        if (current != null) {
            if (collator.compare(current, id) > 0) {
                fail();
            }
        }
        current = id;
    }
    results.close();

    SearchParameters sp2 = new SearchParameters();
    sp2.addStore(rootNodeRef.getStoreRef());
    sp2.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp2.setQuery("PATH:\"//.\"");
    sp2.addSort("ID", false);
    results = searcher.query(sp2);

    current = null;
    for (ResultSetRow row : results) {
        String id = row.getNodeRef().getId();
        if (current != null) {
            if (collator.compare(current, id) < 0) {
                fail();
            }
        }
        current = id;
    }
    results.close();

    luceneFTS.resume();

    SearchParameters sp3 = new SearchParameters();
    sp3.addStore(rootNodeRef.getStoreRef());
    sp3.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp3.setQuery("PATH:\"//.\"");
    sp3.addSort(SearchParameters.SORT_IN_DOCUMENT_ORDER_ASCENDING);
    results = searcher.query(sp3);

    int count = 0;
    for (ResultSetRow row : results) {
        assertEquals(documentOrder[count++], row.getNodeRef());
    }
    results.close();

    SearchParameters sp4 = new SearchParameters();
    sp4.addStore(rootNodeRef.getStoreRef());
    sp4.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp4.setQuery("PATH:\"//.\"");
    sp4.addSort(SearchParameters.SORT_IN_DOCUMENT_ORDER_DESCENDING);
    results = searcher.query(sp4);

    count = 1;
    for (ResultSetRow row : results) {
        assertEquals(documentOrder[documentOrder.length - (count++)], row.getNodeRef());
    }
    results.close();

    SearchParameters sp5 = new SearchParameters();
    sp5.addStore(rootNodeRef.getStoreRef());
    sp5.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp5.setQuery("PATH:\"//.\"");
    sp5.addSort(SearchParameters.SORT_IN_SCORE_ORDER_ASCENDING);
    results = searcher.query(sp5);

    float score = 0;
    for (ResultSetRow row : results) {
        assertTrue(score <= row.getScore());
        score = row.getScore();
    }
    results.close();

    SearchParameters sp6 = new SearchParameters();
    sp6.addStore(rootNodeRef.getStoreRef());
    sp6.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp6.setQuery("PATH:\"//.\"");
    sp6.addSort(SearchParameters.SORT_IN_SCORE_ORDER_DESCENDING);
    results = searcher.query(sp6);

    score = 1.0f;
    for (ResultSetRow row : results) {
        assertTrue(score >= row.getScore());
        score = row.getScore();
    }
    results.close();

    // sort by created date

    SearchParameters sp7 = new SearchParameters();
    sp7.addStore(rootNodeRef.getStoreRef());
    sp7.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp7.setQuery("PATH:\"//.\"");
    sp7.addSort("@" + createdDate.getPrefixedQName(namespacePrefixResolver), true);
    results = searcher.query(sp7);

    Date date = null;
    for (ResultSetRow row : results) {
        Date currentBun = DefaultTypeConverter.INSTANCE.convert(Date.class,
                nodeService.getProperty(row.getNodeRef(), createdDate));
        // System.out.println(currentBun);
        if (date != null) {
            assertTrue(date.compareTo(currentBun) <= 0);
        }
        date = currentBun;
    }
    results.close();

    SearchParameters sp8 = new SearchParameters();
    sp8.addStore(rootNodeRef.getStoreRef());
    sp8.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp8.setQuery("PATH:\"//.\"");
    sp8.addSort("@" + createdDate, false);
    results = searcher.query(sp8);

    date = null;
    for (ResultSetRow row : results) {
        Date currentBun = DefaultTypeConverter.INSTANCE.convert(Date.class,
                nodeService.getProperty(row.getNodeRef(), createdDate));
        // System.out.println(currentBun);
        if ((date != null) && (currentBun != null)) {
            assertTrue(date.compareTo(currentBun) >= 0);
        }
        date = currentBun;
    }
    results.close();

    SearchParameters sp_7 = new SearchParameters();
    sp_7.addStore(rootNodeRef.getStoreRef());
    sp_7.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp_7.setQuery("PATH:\"//.\"");
    sp_7.addSort("@" + ContentModel.PROP_MODIFIED, true);
    results = searcher.query(sp_7);

    date = null;
    for (ResultSetRow row : results) {
        Date currentBun = DefaultTypeConverter.INSTANCE.convert(Date.class,
                nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_MODIFIED));
        if (currentBun != null) {
            Calendar c = new GregorianCalendar();
            c.setTime(currentBun);
            c.set(Calendar.MILLISECOND, 0);
            c.set(Calendar.SECOND, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.HOUR_OF_DAY, 0);
            currentBun = c.getTime();
        }
        if ((date != null) && (currentBun != null)) {
            assertTrue(date.compareTo(currentBun) <= 0);
        }
        date = currentBun;
    }
    results.close();

    SearchParameters sp_8 = new SearchParameters();
    sp_8.addStore(rootNodeRef.getStoreRef());
    sp_8.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp_8.setQuery("PATH:\"//.\"");
    sp_8.addSort("@" + ContentModel.PROP_MODIFIED, false);
    results = searcher.query(sp_8);

    date = null;
    for (ResultSetRow row : results) {
        Date currentBun = DefaultTypeConverter.INSTANCE.convert(Date.class,
                nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_MODIFIED));
        // System.out.println(currentBun);
        if (currentBun != null) {
            Calendar c = new GregorianCalendar();
            c.setTime(currentBun);
            c.set(Calendar.MILLISECOND, 0);
            c.set(Calendar.SECOND, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.HOUR_OF_DAY, 0);
            currentBun = c.getTime();
        }

        if ((date != null) && (currentBun != null)) {
            assertTrue(date.compareTo(currentBun) >= 0);
        }
        date = currentBun;
    }
    results.close();

    // sort by double

    SearchParameters sp9 = new SearchParameters();
    sp9.addStore(rootNodeRef.getStoreRef());
    sp9.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp9.setQuery("PATH:\"//.\"");
    sp9.addSort("@" + orderDouble, true);
    results = searcher.query(sp9);

    Double d = null;
    for (ResultSetRow row : results) {
        Double currentBun = DefaultTypeConverter.INSTANCE.convert(Double.class,
                nodeService.getProperty(row.getNodeRef(), orderDouble));
        // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun);
        if (d != null) {
            assertTrue(d.compareTo(currentBun) <= 0);
        }
        d = currentBun;
    }
    results.close();

    SearchParameters sp10 = new SearchParameters();
    sp10.addStore(rootNodeRef.getStoreRef());
    sp10.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp10.setQuery("PATH:\"//.\"");
    sp10.addSort("@" + orderDouble, false);
    results = searcher.query(sp10);

    d = null;
    for (ResultSetRow row : results) {
        Double currentBun = DefaultTypeConverter.INSTANCE.convert(Double.class,
                nodeService.getProperty(row.getNodeRef(), orderDouble));
        // System.out.println(currentBun);
        if ((d != null) && (currentBun != null)) {
            assertTrue(d.compareTo(currentBun) >= 0);
        }
        d = currentBun;
    }
    results.close();

    // sort by float

    SearchParameters sp11 = new SearchParameters();
    sp11.addStore(rootNodeRef.getStoreRef());
    sp11.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp11.setQuery("PATH:\"//.\"");
    sp11.addSort("@" + orderFloat, true);
    results = searcher.query(sp11);

    Float f = null;
    for (ResultSetRow row : results) {
        Float currentBun = DefaultTypeConverter.INSTANCE.convert(Float.class,
                nodeService.getProperty(row.getNodeRef(), orderFloat));
        // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun);
        if (f != null) {
            assertTrue(f.compareTo(currentBun) <= 0);
        }
        f = currentBun;
    }
    results.close();

    SearchParameters sp12 = new SearchParameters();
    sp12.addStore(rootNodeRef.getStoreRef());
    sp12.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp12.setQuery("PATH:\"//.\"");
    sp12.addSort("@" + orderFloat, false);
    results = searcher.query(sp12);

    f = null;
    for (ResultSetRow row : results) {
        Float currentBun = DefaultTypeConverter.INSTANCE.convert(Float.class,
                nodeService.getProperty(row.getNodeRef(), orderFloat));
        // System.out.println(currentBun);
        if ((f != null) && (currentBun != null)) {
            assertTrue(f.compareTo(currentBun) >= 0);
        }
        f = currentBun;
    }
    results.close();

    // sort by long

    SearchParameters sp13 = new SearchParameters();
    sp13.addStore(rootNodeRef.getStoreRef());
    sp13.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp13.setQuery("PATH:\"//.\"");
    sp13.addSort("@" + orderLong, true);
    results = searcher.query(sp13);

    Long l = null;
    for (ResultSetRow row : results) {
        Long currentBun = DefaultTypeConverter.INSTANCE.convert(Long.class,
                nodeService.getProperty(row.getNodeRef(), orderLong));
        // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun);
        if (l != null) {
            assertTrue(l.compareTo(currentBun) <= 0);
        }
        l = currentBun;
    }
    results.close();

    SearchParameters sp14 = new SearchParameters();
    sp14.addStore(rootNodeRef.getStoreRef());
    sp14.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp14.setQuery("PATH:\"//.\"");
    sp14.addSort("@" + orderLong, false);
    results = searcher.query(sp14);

    l = null;
    for (ResultSetRow row : results) {
        Long currentBun = DefaultTypeConverter.INSTANCE.convert(Long.class,
                nodeService.getProperty(row.getNodeRef(), orderLong));
        // System.out.println(currentBun);
        if ((l != null) && (currentBun != null)) {
            assertTrue(l.compareTo(currentBun) >= 0);
        }
        l = currentBun;
    }
    results.close();

    // sort by int

    SearchParameters sp15 = new SearchParameters();
    sp15.addStore(rootNodeRef.getStoreRef());
    sp15.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp15.setQuery("PATH:\"//.\"");
    sp15.addSort("@" + orderInt, true);
    results = searcher.query(sp15);

    Integer i = null;
    for (ResultSetRow row : results) {
        Integer currentBun = DefaultTypeConverter.INSTANCE.convert(Integer.class,
                nodeService.getProperty(row.getNodeRef(), orderInt));
        // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun);
        if (i != null) {
            assertTrue(i.compareTo(currentBun) <= 0);
        }
        i = currentBun;
    }
    results.close();

    SearchParameters sp16 = new SearchParameters();
    sp16.addStore(rootNodeRef.getStoreRef());
    sp16.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp16.setQuery("PATH:\"//.\"");
    sp16.addSort("@" + orderInt, false);
    results = searcher.query(sp16);

    i = null;
    for (ResultSetRow row : results) {
        Integer currentBun = DefaultTypeConverter.INSTANCE.convert(Integer.class,
                nodeService.getProperty(row.getNodeRef(), orderInt));
        // System.out.println(currentBun);
        if ((i != null) && (currentBun != null)) {
            assertTrue(i.compareTo(currentBun) >= 0);
        }
        i = currentBun;
    }
    results.close();

    // sort by text

    SearchParameters sp17 = new SearchParameters();
    sp17.addStore(rootNodeRef.getStoreRef());
    sp17.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp17.setQuery("PATH:\"//.\"");
    sp17.addSort("@" + orderText, true);
    results = searcher.query(sp17);

    String text = null;
    for (ResultSetRow row : results) {
        String currentBun = DefaultTypeConverter.INSTANCE.convert(String.class,
                nodeService.getProperty(row.getNodeRef(), orderText));
        // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ " "+currentBun);
        if ((text != null) && (currentBun != null)) {
            assertTrue(collator.compare(text, currentBun) <= 0);
        }
        text = currentBun;
    }
    results.close();

    SearchParameters sp18 = new SearchParameters();
    sp18.addStore(rootNodeRef.getStoreRef());
    sp18.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp18.setQuery("PATH:\"//.\"");
    sp18.addSort("@" + orderText, false);
    results = searcher.query(sp18);

    text = null;
    for (ResultSetRow row : results) {
        String currentBun = DefaultTypeConverter.INSTANCE.convert(String.class,
                nodeService.getProperty(row.getNodeRef(), orderText));
        // System.out.println(currentBun);
        if ((text != null) && (currentBun != null)) {
            assertTrue(collator.compare(text, currentBun) >= 0);
        }
        text = currentBun;
    }
    results.close();

    // sort by content size

    // sort by ML text

    // Locale[] testLocales = new Locale[] { I18NUtil.getLocale(), Locale.ENGLISH, Locale.FRENCH, Locale.CHINESE };
    Locale[] testLocales = new Locale[] { I18NUtil.getLocale(), Locale.ENGLISH, Locale.FRENCH };
    for (Locale testLocale : testLocales) {
        Collator localisedCollator = Collator.getInstance(testLocale);

        SearchParameters sp19 = new SearchParameters();
        sp19.addStore(rootNodeRef.getStoreRef());
        sp19.setLanguage(SearchService.LANGUAGE_LUCENE);
        sp19.setQuery("PATH:\"//.\"");
        sp19.addSort("@" + orderMLText, true);
        sp19.addLocale(testLocale);
        results = searcher.query(sp19);

        text = null;
        for (ResultSetRow row : results) {
            MLText mltext = DefaultTypeConverter.INSTANCE.convert(MLText.class,
                    nodeService.getProperty(row.getNodeRef(), orderMLText));
            if (mltext != null) {
                String currentBun = mltext.getValue(testLocale);
                // System.out.println( (currentBun == null ? "null" : NumericEncoder.encode(currentBun))+ "
                // "+currentBun);
                if ((text != null) && (currentBun != null)) {
                    assertTrue(localisedCollator.compare(text, currentBun) <= 0);
                }
                text = currentBun;
            }
        }
        results.close();

        SearchParameters sp20 = new SearchParameters();
        sp20.addStore(rootNodeRef.getStoreRef());
        sp20.setLanguage(SearchService.LANGUAGE_LUCENE);
        sp20.setQuery("PATH:\"//.\"");
        sp20.addSort("@" + orderMLText, false);
        sp20.addLocale(testLocale);
        results = searcher.query(sp20);

        text = null;
        for (ResultSetRow row : results) {
            MLText mltext = DefaultTypeConverter.INSTANCE.convert(MLText.class,
                    nodeService.getProperty(row.getNodeRef(), orderMLText));
            if (mltext != null) {
                String currentBun = mltext.getValue(testLocale);
                if ((text != null) && (currentBun != null)) {
                    assertTrue(localisedCollator.compare(text, currentBun) >= 0);
                }
                text = currentBun;
            }
        }
        results.close();

    }

    luceneFTS.resume();

    SearchParameters spN = new SearchParameters();
    spN.addStore(rootNodeRef.getStoreRef());
    spN.setLanguage(SearchService.LANGUAGE_LUCENE);
    spN.setQuery("PATH:\"//.\"");
    spN.addSort("cabbage", false);
    results = searcher.query(spN);
    results.close();

    // test sort on unkown properties ALF-4193

    spN = new SearchParameters();
    spN.addStore(rootNodeRef.getStoreRef());
    spN.setLanguage(SearchService.LANGUAGE_LUCENE);
    spN.setQuery("PATH:\"//.\"");
    spN.addSort("PARENT", false);
    results = searcher.query(spN);
    results.close();

    spN = new SearchParameters();
    spN.addStore(rootNodeRef.getStoreRef());
    spN.setLanguage(SearchService.LANGUAGE_LUCENE);
    spN.setQuery("PATH:\"//.\"");
    spN.addSort("@PARENT:PARENT", false);
    results = searcher.query(spN);
    results.close();

    luceneFTS.resume();

    // sort by content size

    SearchParameters sp20 = new SearchParameters();
    sp20.addStore(rootNodeRef.getStoreRef());
    sp20.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp20.setQuery("PATH:\"//.\"");
    sp20.addSort("@" + ContentModel.PROP_CONTENT + ".size", false);
    results = searcher.query(sp20);

    Long size = null;
    for (ResultSetRow row : results) {
        ContentData currentBun = DefaultTypeConverter.INSTANCE.convert(ContentData.class,
                nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_CONTENT));
        // System.out.println(currentBun);
        if ((size != null) && (currentBun != null)) {
            assertTrue(size.compareTo(currentBun.getSize()) >= 0);
        }
        if (currentBun != null) {
            size = currentBun.getSize();
        }
    }
    results.close();

    // sort by content mimetype

    SearchParameters sp21 = new SearchParameters();
    sp21.addStore(rootNodeRef.getStoreRef());
    sp21.setLanguage(SearchService.LANGUAGE_LUCENE);
    sp21.setQuery("PATH:\"//.\"");
    sp21.addSort("@" + ContentModel.PROP_CONTENT + ".mimetype", false);
    results = searcher.query(sp21);

    String mimetype = null;
    for (ResultSetRow row : results) {
        ContentData currentBun = DefaultTypeConverter.INSTANCE.convert(ContentData.class,
                nodeService.getProperty(row.getNodeRef(), ContentModel.PROP_CONTENT));
        // System.out.println(currentBun);
        if ((mimetype != null) && (currentBun != null)) {
            assertTrue(mimetype.compareTo(currentBun.getMimetype()) >= 0);
        }
        if (currentBun != null) {
            mimetype = currentBun.getMimetype();
        }
    }
    results.close();

}