Apache Lucene open-source search software
SOLR-1930: remove solr deprecations - fieldType.getValueSource migration
Yonik Seeley315370dcbb30
diff --git a/solr/src/java/org/apache/solr/schema/BCDIntField.java b/solr/src/java/org/apache/solr/schema/BCDIntField.javaindex e825dbd2df4..6a2ef7a0ea9 100644--- a/solr/src/java/org/apache/solr/schema/BCDIntField.java+++ b/solr/src/java/org/apache/solr/schema/BCDIntField.java@@ -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");}diff --git a/solr/src/java/org/apache/solr/schema/BoolField.java b/solr/src/java/org/apache/solr/schema/BoolField.javaindex 2e838e8e90f..907849a15ff 100644--- a/solr/src/java/org/apache/solr/schema/BoolField.java+++ b/solr/src/java/org/apache/solr/schema/BoolField.java@@ -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);}diff --git a/solr/src/java/org/apache/solr/schema/ByteField.java b/solr/src/java/org/apache/solr/schema/ByteField.javaindex 8f53ed2b66a..ce84ec3b966 100644--- a/solr/src/java/org/apache/solr/schema/ByteField.java+++ b/solr/src/java/org/apache/solr/schema/ByteField.java@@ -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 ) );}diff --git a/solr/src/java/org/apache/solr/schema/DoubleField.java b/solr/src/java/org/apache/solr/schema/DoubleField.javaindex 2b2a8f42f68..79da6845ccd 100644--- a/solr/src/java/org/apache/solr/schema/DoubleField.java+++ b/solr/src/java/org/apache/solr/schema/DoubleField.java@@ -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 doublereturn new DoubleFieldSource( new DoubleValuesCreator( field.name, null, CachedArrayCreator.CACHE_VALUES_AND_BITS ) );}diff --git a/solr/src/java/org/apache/solr/schema/FieldType.java b/solr/src/java/org/apache/solr/schema/FieldType.javaindex 424e7e51ad6..237750096d0 100644--- a/solr/src/java/org/apache/solr/schema/FieldType.java+++ b/solr/src/java/org/apache/solr/schema/FieldType.java@@ -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));}}diff --git a/solr/src/java/org/apache/solr/schema/FloatField.java b/solr/src/java/org/apache/solr/schema/FloatField.javaindex c9fbeae7e8b..9cd2cad66b0 100644--- a/solr/src/java/org/apache/solr/schema/FloatField.java+++ b/solr/src/java/org/apache/solr/schema/FloatField.java@@ -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 ) );}diff --git a/solr/src/java/org/apache/solr/schema/IntField.java b/solr/src/java/org/apache/solr/schema/IntField.javaindex afb8d775d26..e8ccab2b667 100644--- a/solr/src/java/org/apache/solr/schema/IntField.java+++ b/solr/src/java/org/apache/solr/schema/IntField.java@@ -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 ) );}diff --git a/solr/src/java/org/apache/solr/schema/LongField.java b/solr/src/java/org/apache/solr/schema/LongField.javaindex 30115f2029f..c716552f5af 100644--- a/solr/src/java/org/apache/solr/schema/LongField.java+++ b/solr/src/java/org/apache/solr/schema/LongField.java@@ -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 ) );}diff --git a/solr/src/java/org/apache/solr/schema/RandomSortField.java b/solr/src/java/org/apache/solr/schema/RandomSortField.javaindex 2ac65106eae..1a2891f8ecc 100644--- a/solr/src/java/org/apache/solr/schema/RandomSortField.java+++ b/solr/src/java/org/apache/solr/schema/RandomSortField.java@@ -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());}diff --git a/solr/src/java/org/apache/solr/schema/ShortField.java b/solr/src/java/org/apache/solr/schema/ShortField.javaindex ba68543c1b9..94c77450a74 100644--- a/solr/src/java/org/apache/solr/schema/ShortField.java+++ b/solr/src/java/org/apache/solr/schema/ShortField.java@@ -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 ) );}diff --git a/solr/src/java/org/apache/solr/schema/SortableDoubleField.java b/solr/src/java/org/apache/solr/schema/SortableDoubleField.javaindex 99112568321..f1744efc688 100644--- a/solr/src/java/org/apache/solr/schema/SortableDoubleField.java+++ b/solr/src/java/org/apache/solr/schema/SortableDoubleField.java@@ -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);}diff --git a/solr/src/java/org/apache/solr/schema/SortableFloatField.java b/solr/src/java/org/apache/solr/schema/SortableFloatField.javaindex 0737aa65525..407c17f90e3 100644--- a/solr/src/java/org/apache/solr/schema/SortableFloatField.java+++ b/solr/src/java/org/apache/solr/schema/SortableFloatField.java@@ -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);}diff --git a/solr/src/java/org/apache/solr/schema/SortableIntField.java b/solr/src/java/org/apache/solr/schema/SortableIntField.javaindex 19b7738223b..3771d3eb0e2 100644--- a/solr/src/java/org/apache/solr/schema/SortableIntField.java+++ b/solr/src/java/org/apache/solr/schema/SortableIntField.java@@ -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);}diff --git a/solr/src/java/org/apache/solr/schema/SortableLongField.java b/solr/src/java/org/apache/solr/schema/SortableLongField.javaindex 627d3fa9f4d..b9657d1451a 100644--- a/solr/src/java/org/apache/solr/schema/SortableLongField.java+++ b/solr/src/java/org/apache/solr/schema/SortableLongField.java@@ -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);}diff --git a/solr/src/java/org/apache/solr/schema/TrieField.java b/solr/src/java/org/apache/solr/schema/TrieField.javaindex bcbc2f68b35..2e57c90b56b 100644--- a/solr/src/java/org/apache/solr/schema/TrieField.java+++ b/solr/src/java/org/apache/solr/schema/TrieField.java@@ -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:diff --git a/solr/src/java/org/apache/solr/schema/UUIDField.java b/solr/src/java/org/apache/solr/schema/UUIDField.javaindex aab3709be27..f1bfa424bff 100644--- a/solr/src/java/org/apache/solr/schema/UUIDField.java+++ b/solr/src/java/org/apache/solr/schema/UUIDField.java@@ -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='-';diff --git a/solr/src/java/org/apache/solr/update/DirectUpdateHandler.java b/solr/src/java/org/apache/solr/update/DirectUpdateHandler.javadeleted file mode 100644index a70f9461579..00000000000--- a/solr/src/java/org/apache/solr/update/DirectUpdateHandler.java+++ /dev/null@@ -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;- }-----}