You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by gs...@apache.org on 2008/07/01 23:49:16 UTC
svn commit: r673221 - in /lucene/solr/trunk: ./
src/java/org/apache/solr/request/ src/java/org/apache/solr/schema/
src/java/org/apache/solr/search/function/
Author: gsingers
Date: Tue Jul 1 14:49:16 2008
New Revision: 673221
URL: http://svn.apache.org/viewvc?rev=673221&view=rev
Log:
SOLR-482: add byte/short sorting support
Added:
lucene/solr/trunk/src/java/org/apache/solr/schema/ByteField.java (with props)
lucene/solr/trunk/src/java/org/apache/solr/schema/ShortField.java (with props)
lucene/solr/trunk/src/java/org/apache/solr/search/function/ByteFieldSource.java (with props)
lucene/solr/trunk/src/java/org/apache/solr/search/function/ShortFieldSource.java (with props)
Modified:
lucene/solr/trunk/CHANGES.txt
lucene/solr/trunk/src/java/org/apache/solr/request/JSONResponseWriter.java
lucene/solr/trunk/src/java/org/apache/solr/request/TextResponseWriter.java
lucene/solr/trunk/src/java/org/apache/solr/request/XMLWriter.java
Modified: lucene/solr/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/CHANGES.txt?rev=673221&r1=673220&r2=673221&view=diff
==============================================================================
--- lucene/solr/trunk/CHANGES.txt (original)
+++ lucene/solr/trunk/CHANGES.txt Tue Jul 1 14:49:16 2008
@@ -300,6 +300,8 @@
54. SOLR-423: Added Request Handler close hook notification so that RequestHandlers can be notified when a core is closing. (gsingers, ryan)
55. SOLR-603: Added ability to partially optimize. (gsingers)
+
+56. SOLR-483: Add byte/short sorting support (gsingers)
Changes in runtime behavior
1. SOLR-559: use Lucene updateDocument, deleteDocuments methods. This
Modified: lucene/solr/trunk/src/java/org/apache/solr/request/JSONResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/JSONResponseWriter.java?rev=673221&r1=673220&r2=673221&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/request/JSONResponseWriter.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/request/JSONResponseWriter.java Tue Jul 1 14:49:16 2008
@@ -719,6 +719,16 @@
writer.write(val);
}
+ @Override
+ public void writeShort(String name, String val) throws IOException {
+ writer.write(val);
+ }
+
+ public void writeByte(String name, String val) throws IOException {
+ writer.write(val);
+
+ }
+
// TODO: refactor this out to a DateUtils class or something...
public void writeDate(String name, Date val) throws IOException {
// using a stringBuilder for numbers can be nice since
Modified: lucene/solr/trunk/src/java/org/apache/solr/request/TextResponseWriter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/TextResponseWriter.java?rev=673221&r1=673220&r2=673221&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/request/TextResponseWriter.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/request/TextResponseWriter.java Tue Jul 1 14:49:16 2008
@@ -228,4 +228,16 @@
/** if this form of the method is called, val is the Solr ISO8601 based date format */
public abstract void writeDate(String name, String val) throws IOException;
+
+ public abstract void writeShort(String name, String val) throws IOException;
+
+ public void writeShort(String name, short val) throws IOException{
+ writeShort(name, Short.toString(val));
+ }
+
+ public abstract void writeByte(String name, String s) throws IOException;
+
+ public void writeByte(String name, byte val) throws IOException{
+ writeByte(name, Byte.toString(val));
+ }
}
Modified: lucene/solr/trunk/src/java/org/apache/solr/request/XMLWriter.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/request/XMLWriter.java?rev=673221&r1=673220&r2=673221&view=diff
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/request/XMLWriter.java (original)
+++ lucene/solr/trunk/src/java/org/apache/solr/request/XMLWriter.java Tue Jul 1 14:49:16 2008
@@ -640,6 +640,24 @@
writeBool(name,Boolean.toString(val));
}
+ public void writeShort(String name, String val) throws IOException {
+ writePrim("short",name,val,false);
+ }
+
+ public void writeShort(String name, short val) throws IOException {
+ writeInt(name,Short.toString(val));
+ }
+
+
+ public void writeByte(String name, String val) throws IOException {
+ writePrim("byte",name,val,false);
+ }
+
+ public void writeByte(String name, byte val) throws IOException {
+ writeInt(name,Byte.toString(val));
+ }
+
+
public void writeFloat(String name, String val) throws IOException {
writePrim("float",name,val,false);
}
Added: lucene/solr/trunk/src/java/org/apache/solr/schema/ByteField.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/ByteField.java?rev=673221&view=auto
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/ByteField.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/ByteField.java Tue Jul 1 14:49:16 2008
@@ -0,0 +1,60 @@
+package org.apache.solr.schema;
+/**
+ * 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.Fieldable;
+import org.apache.lucene.search.SortField;
+
+import org.apache.solr.request.TextResponseWriter;
+import org.apache.solr.request.XMLWriter;
+import org.apache.solr.search.function.ValueSource;
+import org.apache.solr.search.function.ByteFieldSource;
+
+import java.io.IOException;
+import java.util.Map;
+
+/**
+ * @version $Id: LongField.java 555343 2007-07-11 17:46:25Z hossman $
+ */
+public class ByteField extends FieldType {
+ protected void init(IndexSchema schema, Map<String, String> args) {
+ restrictProps(SORT_MISSING_FIRST | SORT_MISSING_LAST);
+ }
+
+ /////////////////////////////////////////////////////////////
+ public SortField getSortField(SchemaField field, boolean reverse) {
+ return new SortField(field.name, SortField.BYTE, reverse);
+ }
+
+ public ValueSource getValueSource(SchemaField field) {
+ return new ByteFieldSource(field.name);
+ }
+
+
+ public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
+ xmlWriter.writeByte(name, f.stringValue());
+ }
+
+ public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
+ writer.writeByte(name, f.stringValue());
+ }
+
+ @Override
+ public Byte toObject(Fieldable f) {
+ return Byte.valueOf(toExternal(f));
+ }
+}
\ No newline at end of file
Propchange: lucene/solr/trunk/src/java/org/apache/solr/schema/ByteField.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: lucene/solr/trunk/src/java/org/apache/solr/schema/ShortField.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/schema/ShortField.java?rev=673221&view=auto
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/schema/ShortField.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/schema/ShortField.java Tue Jul 1 14:49:16 2008
@@ -0,0 +1,51 @@
+package org.apache.solr.schema;
+
+import org.apache.lucene.document.Fieldable;
+import org.apache.lucene.search.SortField;
+
+import org.apache.solr.request.TextResponseWriter;
+import org.apache.solr.request.XMLWriter;
+import org.apache.solr.search.function.ValueSource;
+import org.apache.solr.search.function.ShortFieldSource;
+
+import java.io.IOException;
+import java.util.Map;
+
+
+/**
+ *
+ *
+ **/
+public class ShortField extends FieldType {
+ protected void init(IndexSchema schema, Map<String, String> args) {
+ restrictProps(SORT_MISSING_FIRST | SORT_MISSING_LAST);
+ }
+
+ /////////////////////////////////////////////////////////////
+
+ public SortField getSortField(SchemaField field, boolean reverse) {
+
+ return new SortField(field.name, SortField.SHORT, reverse);
+ }
+
+ public ValueSource getValueSource(SchemaField field) {
+
+ return new ShortFieldSource(field.name);
+ }
+
+
+ public void write(XMLWriter xmlWriter, String name, Fieldable f) throws IOException {
+ xmlWriter.writeShort(name, f.stringValue());
+ }
+
+ @Override
+ public void write(TextResponseWriter writer, String name, Fieldable f) throws IOException {
+ writer.writeShort(name, f.stringValue());
+ }
+
+ @Override
+ public Short toObject(Fieldable f) {
+ return Short.valueOf(toExternal(f));
+ }
+
+}
Propchange: lucene/solr/trunk/src/java/org/apache/solr/schema/ShortField.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: lucene/solr/trunk/src/java/org/apache/solr/search/function/ByteFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/function/ByteFieldSource.java?rev=673221&view=auto
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/function/ByteFieldSource.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/function/ByteFieldSource.java Tue Jul 1 14:49:16 2008
@@ -0,0 +1,104 @@
+package org.apache.solr.search.function;
+/**
+ * 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.index.IndexReader;
+import org.apache.lucene.search.FieldCache;
+
+import java.io.IOException;
+
+/**
+ * Obtains int field values from the {@link org.apache.lucene.search.FieldCache}
+ * using <code>getInts()</code>
+ * and makes those values available as other numeric types, casting as needed. *
+ *
+ * @version $Id: IntFieldSource.java 555343 2007-07-11 17:46:25Z hossman $
+ */
+
+public class ByteFieldSource extends FieldCacheSource {
+ FieldCache.ByteParser parser;
+
+ public ByteFieldSource(String field) {
+ this(field, null);
+ }
+
+ public ByteFieldSource(String field, FieldCache.ByteParser parser) {
+ super(field);
+ this.parser = parser;
+ }
+
+ public String description() {
+ return "byte(" + field + ')';
+ }
+
+ public DocValues getValues(IndexReader reader) throws IOException {
+ final byte[] arr = (parser == null) ?
+ cache.getBytes(reader, field) :
+ cache.getBytes(reader, field, parser);
+ return new DocValues() {
+ @Override
+ public byte byteVal(int doc) {
+ return (byte) arr[doc];
+ }
+
+ @Override
+ public short shortVal(int doc) {
+ return (short) arr[doc];
+ }
+
+ public float floatVal(int doc) {
+ return (float) arr[doc];
+ }
+
+ public int intVal(int doc) {
+ return (int) arr[doc];
+ }
+
+ public long longVal(int doc) {
+ return (long) arr[doc];
+ }
+
+ public double doubleVal(int doc) {
+ return (double) arr[doc];
+ }
+
+ public String strVal(int doc) {
+ return Byte.toString(arr[doc]);
+ }
+
+ public String toString(int doc) {
+ return description() + '=' + byteVal(doc);
+ }
+
+ };
+ }
+
+ public boolean equals(Object o) {
+ if (o.getClass() != ByteFieldSource.class) return false;
+ ByteFieldSource
+ other = (ByteFieldSource) o;
+ return super.equals(other)
+ && this.parser == null ? other.parser == null :
+ this.parser.getClass() == other.parser.getClass();
+ }
+
+ public int hashCode() {
+ int h = parser == null ? Byte.class.hashCode() : parser.getClass().hashCode();
+ h += super.hashCode();
+ return h;
+ }
+}
\ No newline at end of file
Propchange: lucene/solr/trunk/src/java/org/apache/solr/search/function/ByteFieldSource.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: lucene/solr/trunk/src/java/org/apache/solr/search/function/ShortFieldSource.java
URL: http://svn.apache.org/viewvc/lucene/solr/trunk/src/java/org/apache/solr/search/function/ShortFieldSource.java?rev=673221&view=auto
==============================================================================
--- lucene/solr/trunk/src/java/org/apache/solr/search/function/ShortFieldSource.java (added)
+++ lucene/solr/trunk/src/java/org/apache/solr/search/function/ShortFieldSource.java Tue Jul 1 14:49:16 2008
@@ -0,0 +1,85 @@
+package org.apache.solr.search.function;
+
+import org.apache.lucene.search.FieldCache;
+import org.apache.lucene.index.IndexReader;
+
+import java.io.IOException;
+
+
+/**
+ *
+ *
+ **/
+public class ShortFieldSource extends FieldCacheSource{
+ FieldCache.ShortParser parser;
+
+ public ShortFieldSource(String field) {
+ this(field, null);
+ }
+
+ public ShortFieldSource(String field, FieldCache.ShortParser parser) {
+ super(field);
+ this.parser = parser;
+ }
+
+ public String description() {
+ return "short(" + field + ')';
+ }
+
+ public DocValues getValues(IndexReader reader) throws IOException {
+ final short[] arr = (parser == null) ?
+ cache.getShorts(reader, field) :
+ cache.getShorts(reader, field, parser);
+ return new DocValues() {
+ @Override
+ public byte byteVal(int doc) {
+ return (byte) arr[doc];
+ }
+
+ @Override
+ public short shortVal(int doc) {
+ return (short) arr[doc];
+ }
+
+ public float floatVal(int doc) {
+ return (float) arr[doc];
+ }
+
+ public int intVal(int doc) {
+ return (int) arr[doc];
+ }
+
+ public long longVal(int doc) {
+ return (long) arr[doc];
+ }
+
+ public double doubleVal(int doc) {
+ return (double) arr[doc];
+ }
+
+ public String strVal(int doc) {
+ return Short.toString(arr[doc]);
+ }
+
+ public String toString(int doc) {
+ return description() + '=' + shortVal(doc);
+ }
+
+ };
+ }
+
+ public boolean equals(Object o) {
+ if (o.getClass() != ShortFieldSource.class) return false;
+ ShortFieldSource
+ other = (ShortFieldSource) o;
+ return super.equals(other)
+ && this.parser == null ? other.parser == null :
+ this.parser.getClass() == other.parser.getClass();
+ }
+
+ public int hashCode() {
+ int h = parser == null ? Short.class.hashCode() : parser.getClass().hashCode();
+ h += super.hashCode();
+ return h;
+ }
+}
Propchange: lucene/solr/trunk/src/java/org/apache/solr/search/function/ShortFieldSource.java
------------------------------------------------------------------------------
svn:eol-style = native