Return-Path: X-Original-To: apmail-lucene-commits-archive@www.apache.org Delivered-To: apmail-lucene-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 83C6BE463 for ; Thu, 24 Jan 2013 22:48:19 +0000 (UTC) Received: (qmail 7038 invoked by uid 500); 24 Jan 2013 22:48:19 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 7022 invoked by uid 99); 24 Jan 2013 22:48:19 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Jan 2013 22:48:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Jan 2013 22:48:17 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 7ABB92388847; Thu, 24 Jan 2013 22:47:58 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1438246 - in /lucene/dev/branches/lucene4547/lucene/analysis/icu/src: java/org/apache/lucene/collation/ICUCollationDocValuesField.java test/org/apache/lucene/collation/TestICUCollationDocValuesField.java Date: Thu, 24 Jan 2013 22:47:58 -0000 To: commits@lucene.apache.org From: rmuir@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130124224758.7ABB92388847@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rmuir Date: Thu Jan 24 22:47:58 2013 New Revision: 1438246 URL: http://svn.apache.org/viewvc?rev=1438246&view=rev Log: LUCENE-4035: add docvalues collation field Added: lucene/dev/branches/lucene4547/lucene/analysis/icu/src/java/org/apache/lucene/collation/ICUCollationDocValuesField.java (with props) lucene/dev/branches/lucene4547/lucene/analysis/icu/src/test/org/apache/lucene/collation/TestICUCollationDocValuesField.java (with props) Added: lucene/dev/branches/lucene4547/lucene/analysis/icu/src/java/org/apache/lucene/collation/ICUCollationDocValuesField.java URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/analysis/icu/src/java/org/apache/lucene/collation/ICUCollationDocValuesField.java?rev=1438246&view=auto ============================================================================== --- lucene/dev/branches/lucene4547/lucene/analysis/icu/src/java/org/apache/lucene/collation/ICUCollationDocValuesField.java (added) +++ lucene/dev/branches/lucene4547/lucene/analysis/icu/src/java/org/apache/lucene/collation/ICUCollationDocValuesField.java Thu Jan 24 22:47:58 2013 @@ -0,0 +1,64 @@ +package org.apache.lucene.collation; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.lucene.document.Field; +import org.apache.lucene.document.SortedDocValuesField; +import org.apache.lucene.util.BytesRef; + +import com.ibm.icu.text.Collator; +import com.ibm.icu.text.RawCollationKey; + +/** + * nocommit + */ +public final class ICUCollationDocValuesField extends Field { + private final String name; + private final Collator collator; + private final BytesRef bytes = new BytesRef(); + private final RawCollationKey key = new RawCollationKey(); + + public ICUCollationDocValuesField(String name, Collator collator) { + super(name, SortedDocValuesField.TYPE); + this.name = name; + try { + this.collator = (Collator) collator.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + } + + @Override + public String name() { + return name; + } + + public void setStringValue(String value) { + collator.getRawCollationKey(value, key); + bytes.bytes = key.bytes; + bytes.offset = 0; + bytes.length = key.size; + } + + @Override + public BytesRef binaryValue() { + return bytes; + } + + // nocommit: make this thing trap-free +} Added: lucene/dev/branches/lucene4547/lucene/analysis/icu/src/test/org/apache/lucene/collation/TestICUCollationDocValuesField.java URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene4547/lucene/analysis/icu/src/test/org/apache/lucene/collation/TestICUCollationDocValuesField.java?rev=1438246&view=auto ============================================================================== --- lucene/dev/branches/lucene4547/lucene/analysis/icu/src/test/org/apache/lucene/collation/TestICUCollationDocValuesField.java (added) +++ lucene/dev/branches/lucene4547/lucene/analysis/icu/src/test/org/apache/lucene/collation/TestICUCollationDocValuesField.java Thu Jan 24 22:47:58 2013 @@ -0,0 +1,72 @@ +package org.apache.lucene.collation; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.lucene.codecs.Codec; +import org.apache.lucene.document.Document; +import org.apache.lucene.document.Field; +import org.apache.lucene.document.StringField; +import org.apache.lucene.index.IndexReader; +import org.apache.lucene.index.RandomIndexWriter; +import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.MatchAllDocsQuery; +import org.apache.lucene.search.Sort; +import org.apache.lucene.search.SortField; +import org.apache.lucene.search.TopDocs; +import org.apache.lucene.store.Directory; +import org.apache.lucene.util.LuceneTestCase; + +import com.ibm.icu.text.Collator; +import com.ibm.icu.util.ULocale; + +/** + * trivial test of ICUCollationDocValuesField + */ +public class TestICUCollationDocValuesField extends LuceneTestCase { + public void test() throws Exception { + assumeFalse("3.x codec does not support docvalues", Codec.getDefault().getName().equals("Lucene3x")); + Directory dir = newDirectory(); + RandomIndexWriter iw = new RandomIndexWriter(random(), dir); + Document doc = new Document(); + Field field = newField("field", "", StringField.TYPE_STORED); + ICUCollationDocValuesField collationField = new ICUCollationDocValuesField("collated", Collator.getInstance(ULocale.ENGLISH)); + doc.add(field); + doc.add(collationField); + + field.setStringValue("ABC"); + collationField.setStringValue("ABC"); + iw.addDocument(doc); + + field.setStringValue("abc"); + collationField.setStringValue("abc"); + iw.addDocument(doc); + + IndexReader ir = iw.getReader(); + iw.close(); + + IndexSearcher is = newSearcher(ir); + + SortField sortField = new SortField("collated", SortField.Type.STRING); + + TopDocs td = is.search(new MatchAllDocsQuery(), 5, new Sort(sortField)); + assertEquals("abc", ir.document(td.scoreDocs[0].doc).get("field")); + assertEquals("ABC", ir.document(td.scoreDocs[1].doc).get("field")); + ir.close(); + dir.close(); + } +}