SOLR-1930: remove solr deprecations - fieldType.getValueSource migration

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1052889 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2010-12-26 14:25:42 +00:00
parent 91e9459ef2
commit 315370dcbb
17 changed files with 45 additions and 427 deletions

View File

@ -18,6 +18,7 @@
package org.apache.solr.schema;
import org.apache.lucene.search.SortField;
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.ValueSource;
import org.apache.lucene.document.Fieldable;
import org.apache.solr.util.BCDUtils;
@ -36,7 +37,8 @@ public class BCDIntField extends FieldType {
return getStringSort(field,reverse);
}
public ValueSource getValueSource(SchemaField field) {
@Override
public ValueSource getValueSource(SchemaField field, QParser qparser) {
throw new UnsupportedOperationException("ValueSource not implemented");
}

View File

@ -20,6 +20,7 @@ package org.apache.solr.schema;
import org.apache.lucene.search.SortField;
import org.apache.lucene.util.BytesRef;
import org.apache.noggit.CharArr;
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.OrdFieldSource;
import org.apache.lucene.analysis.Analyzer;
@ -43,7 +44,8 @@ public class BoolField extends FieldType {
return getStringSort(field,reverse);
}
public ValueSource getValueSource(SchemaField field) {
@Override
public ValueSource getValueSource(SchemaField field, QParser qparser) {
return new OrdFieldSource(field.name);
}

View File

@ -22,6 +22,7 @@ import org.apache.lucene.search.cache.ByteValuesCreator;
import org.apache.lucene.search.cache.CachedArrayCreator;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.ByteFieldSource;
@ -41,7 +42,8 @@ public class ByteField extends FieldType {
return new SortField(field.name, SortField.BYTE, reverse);
}
public ValueSource getValueSource(SchemaField field) {
@Override
public ValueSource getValueSource(SchemaField field, QParser qparser) {
return new ByteFieldSource( new ByteValuesCreator( field.name, null, CachedArrayCreator.CACHE_VALUES_AND_BITS ) );
}

View File

@ -22,6 +22,7 @@ import org.apache.lucene.search.SortField;
import org.apache.lucene.search.cache.CachedArrayCreator;
import org.apache.lucene.search.cache.DoubleValuesCreator;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.DoubleFieldSource;
import org.apache.solr.search.function.ValueSource;
@ -41,7 +42,8 @@ public class DoubleField extends FieldType {
return new SortField(field.name, SortField.DOUBLE, reverse);
}
public ValueSource getValueSource(SchemaField field) {
@Override
public ValueSource getValueSource(SchemaField field, QParser qparser) {
// fieldCache doesn't support double
return new DoubleFieldSource( new DoubleValuesCreator( field.name, null, CachedArrayCreator.CACHE_VALUES_AND_BITS ) );
}

View File

@ -490,19 +490,10 @@ public abstract class FieldType extends FieldProperties {
* Lucene FieldCache.)
*/
public ValueSource getValueSource(SchemaField field, QParser parser) {
return getValueSource(field);
}
/**
* @deprecated use {@link #getValueSource(SchemaField, QParser)}
*/
@Deprecated
public ValueSource getValueSource(SchemaField field) {
// return new OrdFieldSource(field.name);
return new StrFieldSource(field.name);
}
/**
* Returns a Query instance for doing range searches on this field type. {@link org.apache.solr.search.SolrQueryParser}
* currently passes part1 and part2 as null if they are '*' respectively. minInclusive and maxInclusive are both true
@ -540,6 +531,8 @@ public abstract class FieldType extends FieldProperties {
*
*/
public Query getFieldQuery(QParser parser, SchemaField field, String externalVal) {
return new TermQuery(new Term(field.getName(), toInternal(externalVal)));
BytesRef br = new BytesRef();
readableToIndexed(externalVal, br);
return new TermQuery(new Term(field.getName(), br));
}
}

View File

@ -20,6 +20,7 @@ package org.apache.solr.schema;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.cache.CachedArrayCreator;
import org.apache.lucene.search.cache.FloatValuesCreator;
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.FloatFieldSource;
import org.apache.lucene.document.Fieldable;
@ -39,7 +40,8 @@ public class FloatField extends FieldType {
return new SortField(field.name,SortField.FLOAT, reverse);
}
public ValueSource getValueSource(SchemaField field) {
@Override
public ValueSource getValueSource(SchemaField field, QParser qparser) {
return new FloatFieldSource( new FloatValuesCreator( field.name, null, CachedArrayCreator.CACHE_VALUES_AND_BITS ) );
}

View File

@ -20,6 +20,7 @@ package org.apache.solr.schema;
import org.apache.lucene.search.SortField;
import org.apache.lucene.search.cache.CachedArrayCreator;
import org.apache.lucene.search.cache.IntValuesCreator;
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.IntFieldSource;
import org.apache.lucene.document.Fieldable;
@ -39,7 +40,8 @@ public class IntField extends FieldType {
return new SortField(field.name,SortField.INT, reverse);
}
public ValueSource getValueSource(SchemaField field) {
@Override
public ValueSource getValueSource(SchemaField field, QParser qparser) {
return new IntFieldSource(new IntValuesCreator( field.name, null, CachedArrayCreator.CACHE_VALUES_AND_BITS ) );
}

View File

@ -22,6 +22,7 @@ import org.apache.lucene.search.SortField;
import org.apache.lucene.search.cache.CachedArrayCreator;
import org.apache.lucene.search.cache.LongValuesCreator;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.LongFieldSource;
@ -42,7 +43,8 @@ public class LongField extends FieldType {
return new SortField(field.name,SortField.LONG, reverse);
}
public ValueSource getValueSource(SchemaField field) {
@Override
public ValueSource getValueSource(SchemaField field, QParser qparser) {
return new LongFieldSource( new LongValuesCreator( field.name, null, CachedArrayCreator.CACHE_VALUES_AND_BITS ) );
}

View File

@ -24,6 +24,7 @@ import org.apache.lucene.document.Fieldable;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.*;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.DocValues;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.SolrIndexReader;
@ -95,7 +96,7 @@ public class RandomSortField extends FieldType {
}
@Override
public ValueSource getValueSource(SchemaField field) {
public ValueSource getValueSource(SchemaField field, QParser qparser) {
return new RandomValueSource(field.getName());
}

View File

@ -22,6 +22,7 @@ import org.apache.lucene.search.cache.CachedArrayCreator;
import org.apache.lucene.search.cache.ShortValuesCreator;
import org.apache.solr.response.TextResponseWriter;
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.ShortFieldSource;
@ -45,7 +46,8 @@ public class ShortField extends FieldType {
return new SortField(field.name, SortField.SHORT, reverse);
}
public ValueSource getValueSource(SchemaField field) {
@Override
public ValueSource getValueSource(SchemaField field, QParser qparser) {
return new ShortFieldSource(new ShortValuesCreator( field.name, null, CachedArrayCreator.CACHE_VALUES_AND_BITS ) );
}

View File

@ -22,6 +22,7 @@ import org.apache.lucene.util.BytesRef;
import org.apache.noggit.CharArr;
import org.apache.solr.search.MutableValueDouble;
import org.apache.solr.search.MutableValue;
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.FieldCacheSource;
import org.apache.solr.search.function.DocValues;
@ -45,7 +46,8 @@ public class SortableDoubleField extends FieldType {
return getStringSort(field,reverse);
}
public ValueSource getValueSource(SchemaField field) {
@Override
public ValueSource getValueSource(SchemaField field, QParser qparser) {
return new SortableDoubleFieldSource(field.name);
}

View File

@ -22,6 +22,7 @@ import org.apache.lucene.util.BytesRef;
import org.apache.noggit.CharArr;
import org.apache.solr.search.MutableValueFloat;
import org.apache.solr.search.MutableValue;
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.FieldCacheSource;
import org.apache.solr.search.function.DocValues;
@ -45,7 +46,8 @@ public class SortableFloatField extends FieldType {
return getStringSort(field,reverse);
}
public ValueSource getValueSource(SchemaField field) {
@Override
public ValueSource getValueSource(SchemaField field, QParser qparser) {
return new SortableFloatFieldSource(field.name);
}

View File

@ -22,6 +22,7 @@ import org.apache.lucene.util.BytesRef;
import org.apache.noggit.CharArr;
import org.apache.solr.search.MutableValueInt;
import org.apache.solr.search.MutableValue;
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.FieldCacheSource;
import org.apache.solr.search.function.DocValues;
@ -45,7 +46,8 @@ public class SortableIntField extends FieldType {
return getStringSort(field,reverse);
}
public ValueSource getValueSource(SchemaField field) {
@Override
public ValueSource getValueSource(SchemaField field, QParser qparser) {
return new SortableIntFieldSource(field.name);
}

View File

@ -22,6 +22,7 @@ import org.apache.lucene.util.BytesRef;
import org.apache.noggit.CharArr;
import org.apache.solr.search.MutableValueLong;
import org.apache.solr.search.MutableValue;
import org.apache.solr.search.QParser;
import org.apache.solr.search.function.ValueSource;
import org.apache.solr.search.function.FieldCacheSource;
import org.apache.solr.search.function.DocValues;
@ -45,7 +46,8 @@ public class SortableLongField extends FieldType {
return getStringSort(field,reverse);
}
public ValueSource getValueSource(SchemaField field) {
@Override
public ValueSource getValueSource(SchemaField field, QParser qparser) {
return new SortableLongFieldSource(field.name);
}

View File

@ -174,7 +174,8 @@ public class TrieField extends FieldType {
}
}
public ValueSource getValueSource(SchemaField field) {
@Override
public ValueSource getValueSource(SchemaField field, QParser qparser) {
int flags = CachedArrayCreator.CACHE_VALUES_AND_BITS;
switch (type) {
case INTEGER:

View File

@ -35,7 +35,7 @@ import org.apache.solr.response.TextResponseWriter;
* @see UUID#randomUUID
* @version $Id$
*/
public class UUIDField extends FieldType {
public class UUIDField extends StrField {
private static final String NEW = "NEW";
private static final char DASH='-';

View File

@ -1,401 +0,0 @@
/**
* 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.
*/
/**
*/
package org.apache.solr.update;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.DocsEnum;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.MultiFields;
import org.apache.lucene.document.Document;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.BytesRef;
import java.util.HashSet;
import java.util.concurrent.Future;
import java.util.concurrent.ExecutionException;
import java.io.IOException;
import java.net.URL;
import org.apache.solr.search.SolrIndexSearcher;
import org.apache.solr.search.QueryParsing;
import org.apache.solr.common.SolrException;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.SolrCore;
/**
* <code>DirectUpdateHandler</code> implements an UpdateHandler where documents are added
* directly to the main lucene index as opposed to adding to a separate smaller index.
* For this reason, not all combinations to/from pending and committed are supported.
*
* @version $Id$
* @since solr 0.9
*
* @deprecated Use {@link DirectUpdateHandler2} instead. This is only kept around for back-compatibility (way back).
*/
@Deprecated
public class DirectUpdateHandler extends UpdateHandler {
// the set of ids in the "pending set" (those docs that have been added, but
// that are not yet visible.
final HashSet<String> pset;
IndexWriter writer;
SolrIndexSearcher searcher;
int numAdds=0; // number of docs added to the pending set
int numPending=0; // number of docs currently in this pending set
int numDeleted=0; // number of docs deleted or
public DirectUpdateHandler(SolrCore core) throws IOException {
super(core);
pset = new HashSet<String>(256);
}
protected void openWriter() throws IOException {
if (writer==null) {
writer = createMainIndexWriter("DirectUpdateHandler", false);
}
}
protected void closeWriter() throws IOException {
try {
if (writer!=null) writer.close();
} finally {
// TODO: if an exception causes the writelock to not be
// released, we could delete it here.
writer=null;
}
}
protected void openSearcher() throws IOException {
if (searcher==null) {
searcher = core.newSearcher("DirectUpdateHandler");
}
}
protected void closeSearcher() throws IOException {
try {
if (searcher!=null) searcher.close();
} finally {
// TODO: if an exception causes the writelock to not be
// released, we could delete it here.
searcher=null;
}
}
protected void doAdd(Document doc) throws IOException {
closeSearcher(); openWriter();
writer.addDocument(doc);
}
protected boolean existsInIndex(String indexedId) throws IOException {
if (idField == null) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Operation requires schema to have a unique key field");
closeWriter();
openSearcher();
IndexReader ir = searcher.getReader();
Term idTerm = idTerm(indexedId);
DocsEnum tdocs = MultiFields.getTermDocsEnum(ir,
MultiFields.getDeletedDocs(ir),
idTerm.field(),
idTerm.bytes());
if (tdocs != null) {
return tdocs.nextDoc() != DocsEnum.NO_MORE_DOCS;
} else {
return false;
}
}
protected int deleteInIndex(String indexedId) throws IOException {
if (idField == null) throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Operation requires schema to have a unique key field");
closeWriter(); openSearcher();
IndexReader ir = searcher.getReader();
int num=0;
Term term = new Term(idField.getName(), indexedId);
num = ir.deleteDocuments(term);
if (core.log.isTraceEnabled()) {
core.log.trace( core.getLogId()+"deleted " + num + " docs matching id " + idFieldType.indexedToReadable(indexedId));
}
return num;
}
protected void overwrite(String indexedId, Document doc) throws IOException {
if (indexedId ==null) indexedId =getIndexedId(doc);
deleteInIndex(indexedId);
doAdd(doc);
}
/************** Direct update handler - pseudo code ***********
def add(doc, id, allowDups, overwritePending, overwriteCommitted):
if not overwritePending and not overwriteCommitted:
#special case... no need to check pending set, and we don't keep
#any state around about this addition
if allowDups:
committed[id]=doc #100
return
else:
#if no dups allowed, we must check the *current* index (pending and committed)
if not committed[id]: committed[id]=doc #000
return
#001 (searchd addConditionally)
if not allowDups and not overwritePending and pending[id]: return
del committed[id] #delete from pending and committed 111 011
committed[id]=doc
pending[id]=True
****************************************************************/
// could return the number of docs deleted, but is that always possible to know???
public void delete(DeleteUpdateCommand cmd) throws IOException {
if (!cmd.fromPending && !cmd.fromCommitted)
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"meaningless command: " + cmd);
if (!cmd.fromPending || !cmd.fromCommitted)
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"operation not supported" + cmd);
String indexedId = idFieldType.toInternal(cmd.id);
synchronized(this) {
deleteInIndex(indexedId);
pset.remove(indexedId);
}
}
// TODO - return number of docs deleted?
// Depending on implementation, we may not be able to immediately determine num...
public void deleteByQuery(DeleteUpdateCommand cmd) throws IOException {
if (!cmd.fromPending && !cmd.fromCommitted)
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"meaningless command: " + cmd);
if (!cmd.fromPending || !cmd.fromCommitted)
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"operation not supported: " + cmd);
Query q = QueryParsing.parseQuery(cmd.query, schema);
int totDeleted = 0;
synchronized(this) {
closeWriter(); openSearcher();
// if we want to count the number of docs that were deleted, then
// we need a new instance of the DeleteHitCollector
final DeleteHitCollector deleter = new DeleteHitCollector(searcher);
searcher.search(q, null, deleter);
totDeleted = deleter.deleted;
}
if (core.log.isDebugEnabled()) {
core.log.debug(core.getLogId()+"docs deleted:" + totDeleted);
}
}
/**************** old hit collector... new one is in base class
// final DeleteHitCollector deleter = new DeleteHitCollector();
class DeleteHitCollector extends HitCollector {
public int deleted=0;
public void collect(int doc, float score) {
try {
searcher.getReader().delete(doc);
deleted++;
} catch (IOException e) {
try { closeSearcher(); } catch (Exception ee) { SolrException.log(SolrCore.log,ee); }
SolrException.log(SolrCore.log,e);
throw new SolrException( SolrException.StatusCode.SERVER_ERROR,"Error deleting doc# "+doc,e);
}
}
}
***************************/
public int mergeIndexes(MergeIndexesCommand cmd) throws IOException {
throw new SolrException(
SolrException.ErrorCode.BAD_REQUEST,
"DirectUpdateHandler doesn't support mergeIndexes. Use DirectUpdateHandler2 instead.");
}
public void commit(CommitUpdateCommand cmd) throws IOException {
Future[] waitSearcher = null;
if (cmd.waitSearcher) {
waitSearcher = new Future[1];
}
synchronized (this) {
pset.clear();
closeSearcher(); // flush any deletes
if (cmd.optimize || cmd.expungeDeletes) {
openWriter(); // writer needs to be open to optimize
if(cmd.optimize) writer.optimize(cmd.maxOptimizeSegments);
if(cmd.expungeDeletes) writer.expungeDeletes(cmd.expungeDeletes);
}
closeWriter();
callPostCommitCallbacks();
if (cmd.optimize) {
callPostOptimizeCallbacks();
}
core.getSearcher(true,false,waitSearcher);
}
if (waitSearcher!=null && waitSearcher[0] != null) {
try {
waitSearcher[0].get();
} catch (InterruptedException e) {
SolrException.log(log,e);
} catch (ExecutionException e) {
SolrException.log(log,e);
}
}
}
/**
* @since Solr 1.4
*/
public void rollback(RollbackUpdateCommand cmd) throws IOException {
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,
"DirectUpdateHandler doesn't support rollback. Use DirectUpdateHandler2 instead.");
}
///////////////////////////////////////////////////////////////////
/////////////////// helper method for each add type ///////////////
///////////////////////////////////////////////////////////////////
protected int addNoOverwriteNoDups(AddUpdateCommand cmd) throws IOException {
if (cmd.indexedId ==null) {
cmd.indexedId =getIndexedId(cmd.doc);
}
synchronized (this) {
if (existsInIndex(cmd.indexedId)) return 0;
doAdd(cmd.doc);
}
return 1;
}
protected int addConditionally(AddUpdateCommand cmd) throws IOException {
if (cmd.indexedId ==null) {
cmd.indexedId =getIndexedId(cmd.doc);
}
synchronized(this) {
if (pset.contains(cmd.indexedId)) return 0;
// since case 001 is currently the only case to use pset, only add
// to it in that instance.
pset.add(cmd.indexedId);
overwrite(cmd.indexedId,cmd.doc);
return 1;
}
}
// overwrite both pending and committed
protected synchronized int overwriteBoth(AddUpdateCommand cmd) throws IOException {
overwrite(cmd.indexedId, cmd.doc);
return 1;
}
// add without checking
protected synchronized int allowDups(AddUpdateCommand cmd) throws IOException {
doAdd(cmd.doc);
return 1;
}
public int addDoc(AddUpdateCommand cmd) throws IOException {
// if there is no ID field, use allowDups
if( idField == null ) {
cmd.allowDups = true;
cmd.overwriteCommitted = false;
cmd.overwritePending = false;
}
if (!cmd.allowDups && !cmd.overwritePending && !cmd.overwriteCommitted) {
return addNoOverwriteNoDups(cmd);
} else if (!cmd.allowDups && !cmd.overwritePending && cmd.overwriteCommitted) {
return addConditionally(cmd);
} else if (!cmd.allowDups && cmd.overwritePending && !cmd.overwriteCommitted) {
// return overwriteBoth(cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"unsupported param combo:" + cmd);
} else if (!cmd.allowDups && cmd.overwritePending && cmd.overwriteCommitted) {
return overwriteBoth(cmd);
} else if (cmd.allowDups && !cmd.overwritePending && !cmd.overwriteCommitted) {
return allowDups(cmd);
} else if (cmd.allowDups && !cmd.overwritePending && cmd.overwriteCommitted) {
// return overwriteBoth(cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"unsupported param combo:" + cmd);
} else if (cmd.allowDups && cmd.overwritePending && !cmd.overwriteCommitted) {
// return overwriteBoth(cmd);
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"unsupported param combo:" + cmd);
} else if (cmd.allowDups && cmd.overwritePending && cmd.overwriteCommitted) {
return overwriteBoth(cmd);
}
throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"unsupported param combo:" + cmd);
}
public void close() throws IOException {
synchronized(this) {
closeSearcher();
closeWriter();
}
}
/////////////////////////////////////////////////////////////////////
// SolrInfoMBean stuff: Statistics and Module Info
/////////////////////////////////////////////////////////////////////
public String getName() {
return DirectUpdateHandler.class.getName();
}
public String getVersion() {
return SolrCore.version;
}
public String getDescription() {
return "Update handler that directly changes the on-disk main lucene index";
}
public Category getCategory() {
return Category.CORE;
}
public String getSourceId() {
return "$Id$";
}
public String getSource() {
return "$URL$";
}
public URL[] getDocs() {
return null;
}
public NamedList getStatistics() {
NamedList lst = new SimpleOrderedMap();
return lst;
}
}