Package java.text

Examples of java.text.Collator


  public void testFarsi() throws Exception {
    // Neither Java 1.4.2 nor 1.5.0 has Farsi Locale collation available in
    // RuleBasedCollator.  However, the Arabic Locale seems to order the Farsi
    // characters properly.
    Collator collator = Collator.getInstance(new Locale("ar"));
    Query query = new TermRangeQuery("content", "\u062F", "\u0698", true, true, collator);
    // Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi
    // orders the U+0698 character before the U+0633 character, so the single
    // index Term below should NOT be returned by a TermRangeQuery with a Farsi
    // Collator (or an Arabic one for the case when Farsi is not supported).
View Full Code Here


    assertEquals("The index Term should be included.", 1, hits.length);
    searcher.close();
  }
 
  public void testDanish() throws Exception {
    Collator collator = Collator.getInstance(new Locale("da", "dk"));
    // Danish collation orders the words below in the given order (example taken
    // from TestSort.testInternationalSort() ).
    String[] words = { "H\u00D8T", "H\u00C5T", "MAND" };
    Query query = new TermRangeQuery("content", "H\u00D8T", "MAND", false, false, collator);
View Full Code Here

    // Copied from beforeClass, but scaled down to few docs:
    // since otherwise this test can run for a very long
    // time (1-2 hours or more; see Lucene-Solr-4.x-Linux Build #2204):
    final Locale locale = LuceneTestCase.randomLocale(random());
    Collator collator = Collator.getInstance(locale);
    collator.setStrength(Collator.IDENTICAL);
    collator.setDecomposition(Collator.NO_DECOMPOSITION);

    int numDocs = 20 * RANDOM_MULTIPLIER;
    Directory dir = newDirectory();
    RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
    for (int i = 0; i < numDocs; i++) {
View Full Code Here

  }


  Comparator comparatorStringLocale(final String fieldName,
      Locale locale) {
    final Collator collator = Collator.getInstance(locale);
    return new ShardComparator(fieldName) {
      @Override
      public final int compare(final Object o1, final Object o2) {
        ShardDoc sd1 = (ShardDoc) o1;
        ShardDoc sd2 = (ShardDoc) o2;
        Comparable v1 = (Comparable)sortVal(sd1);
        Comparable v2 = (Comparable)sortVal(sd2);
        if (v1==v2)
          return 0;
        if (v1==null)
          return 1;
        if(v2==null)
          return -1;
        return -collator.compare(v1,v2);
      }
    };
  }
View Full Code Here

    private String patternText;

    @Override
    protected Comparator<Object> getItemsComparator() {
        if (fComparator == null) {
            final Collator collator = Collator.getInstance();
            if (collator instanceof RuleBasedCollator) {
                final RuleBasedCollator rbc = (RuleBasedCollator) collator;
                final String rules = rbc.getRules();
                final String newRules = rules.replaceFirst("<\'.\'<", "<").replaceFirst(
                        "<\'_\'<", "<\'.\'<\'_\'<");
View Full Code Here

 
  public class JSONObjectComparable extends JSONObject implements Comparator<JSONObject>{
    
    public int compare(JSONObject o1, JSONObject o2) {
      try{
        Collator collator = Collator.getInstance();
        String thisName = o1.getString("name");
        String compareName = o2.getString("name");
        if(!thisName.equals(compareName)){
          int retval = collator.compare(thisName, compareName);
          return retval;
        }else{
          String thisAuthorEmail = o1.getString("authorEmail");
          String compareAuthorEmail = o2.getString("authorEmail");
          int retval = collator.compare(thisAuthorEmail, compareAuthorEmail);
          return retval;
        }
      } catch (JSONException e) {
      }
    return 0;
View Full Code Here

    // Neither Java 1.4.2 nor 1.5.0 has Farsi Locale collation available in
    // RuleBasedCollator. However, the Arabic Locale seems to order the
    // Farsi
    // characters properly.
    Collator c = Collator.getInstance(new Locale("ar"));
    qp.setRangeCollator(c);

    // Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi
    // orders the U+0698 character before the U+0633 character, so the
    // single
View Full Code Here

  public void testFarsi() throws Exception {
    // Neither Java 1.4.2 nor 1.5.0 has Farsi Locale collation available in
    // RuleBasedCollator.  However, the Arabic Locale seems to order the Farsi
    // characters properly.
    Collator collator = Collator.getInstance(new Locale("ar"));
    Query query = new TermRangeQuery("content", "\u062F", "\u0698", true, true, collator);
    // Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi
    // orders the U+0698 character before the U+0633 character, so the single
    // index Term below should NOT be returned by a TermRangeQuery with a Farsi
    // Collator (or an Arabic one for the case when Farsi is not supported).
View Full Code Here

    assertEquals("The index Term should be included.", 1, hits.length);
    searcher.close();
  }
 
  public void testDanish() throws Exception {
    Collator collator = Collator.getInstance(new Locale("da", "dk"));
    // Danish collation orders the words below in the given order (example taken
    // from TestSort.testInternationalSort() ).
    String[] words = { "H\u00D8T", "H\u00C5T", "MAND" };
    Query query = new TermRangeQuery("content", "H\u00D8T", "MAND", false, false, collator);
View Full Code Here

        new WhitespaceAnalyzer());

    // Neither Java 1.4.2 nor 1.5.0 has Farsi Locale collation available in
    // RuleBasedCollator. However, the Arabic Locale seems to order the Farsi
    // characters properly.
    Collator c = Collator.getInstance(new Locale("ar"));
    qp.setRangeCollator(c);

    // Unicode order would include U+0633 in [ U+062F - U+0698 ], but Farsi
    // orders the U+0698 character before the U+0633 character, so the single
    // index Term below should NOT be returned by a ConstantScoreRangeQuery
View Full Code Here

TOP

Related Classes of java.text.Collator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.