You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by mh...@apache.org on 2013/09/24 20:33:04 UTC
[28/50] [abbrv] git commit: Make index writing work,
but it is still corrupt
Make index writing work, but it is still corrupt
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/ec36d0d5
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/ec36d0d5
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/ec36d0d5
Branch: refs/heads/branch_4x
Commit: ec36d0d5ccabc7e2f17af8b4d25ff5fcaef7a4c2
Parents: 733dc18
Author: Paul Irwin <pa...@gmail.com>
Authored: Tue Aug 6 17:41:56 2013 -0400
Committer: Paul Irwin <pa...@gmail.com>
Committed: Tue Aug 6 17:41:56 2013 -0400
----------------------------------------------------------------------
src/core/Document/Field.cs | 6 +--
src/core/Document/FieldType.cs | 4 +-
src/core/Index/DocValuesProcessor.cs | 2 +-
src/core/Index/DocumentsWriterFlushQueue.cs | 2 +-
src/core/Index/FieldInfos.cs | 27 +++++++------
src/core/Index/IIndexableField.cs | 2 +-
src/core/Index/IIndexableFieldType.cs | 2 +-
src/core/Index/IndexReaderContext.cs | 2 +-
src/core/Index/SegmentInfos.cs | 2 +-
src/core/Store/BufferedIndexInput.cs | 8 ++--
src/core/Store/BufferedIndexOutput.cs | 2 +-
src/core/Store/DataOutput.cs | 2 +-
src/core/Store/RAMOutputStream.cs | 2 +-
src/core/Util/Fst/Builder.cs | 4 +-
src/core/Util/Fst/FST.cs | 2 +-
src/core/Util/IOUtils.cs | 2 +-
src/core/Util/NamedSPILoader.cs | 2 +-
src/core/Util/SPIClassIterator.cs | 50 ++++++++++--------------
18 files changed, 59 insertions(+), 64 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Document/Field.cs
----------------------------------------------------------------------
diff --git a/src/core/Document/Field.cs b/src/core/Document/Field.cs
index 9cc069f..5ed5585 100644
--- a/src/core/Document/Field.cs
+++ b/src/core/Document/Field.cs
@@ -346,13 +346,13 @@ namespace Lucene.Net.Documents
}
}
- public object NumericValue
+ public long NumericValue
{
get
{
// .NET Port: No base type for all numeric types, so unless we want to rewrite this
// to be LongValue, IntValue, FloatValue, etc, this will have to do.
- return fieldsData;
+ return Convert.ToInt64(fieldsData);
}
}
@@ -412,7 +412,7 @@ namespace Lucene.Net.Documents
}
NumericTokenStream nts = (NumericTokenStream)internalTokenStream;
// initialize value in TokenStream
- Number val = (Number)fieldsData;
+ object val = fieldsData;
switch (numericType)
{
case FieldType.NumericType.INT:
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Document/FieldType.cs
----------------------------------------------------------------------
diff --git a/src/core/Document/FieldType.cs b/src/core/Document/FieldType.cs
index f9410ea..1b8c3c5 100644
--- a/src/core/Document/FieldType.cs
+++ b/src/core/Document/FieldType.cs
@@ -40,7 +40,7 @@ namespace Lucene.Net.Documents
private NumericType? numericType;
private bool frozen;
private int numericPrecisionStep = NumericUtils.PRECISION_STEP_DEFAULT;
- private FieldInfo.DocValuesType docValueType;
+ private FieldInfo.DocValuesType? docValueType;
public FieldType(FieldType refFieldType)
{
@@ -255,7 +255,7 @@ namespace Lucene.Net.Documents
return result.ToString();
}
- public FieldInfo.DocValuesType DocValueType
+ public FieldInfo.DocValuesType? DocValueType
{
get { return docValueType; }
set
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Index/DocValuesProcessor.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/DocValuesProcessor.cs b/src/core/Index/DocValuesProcessor.cs
index 4b90f37..dd707e6 100644
--- a/src/core/Index/DocValuesProcessor.cs
+++ b/src/core/Index/DocValuesProcessor.cs
@@ -31,7 +31,7 @@ namespace Lucene.Net.Index
public override void AddField(int docID, IIndexableField field, FieldInfo fieldInfo)
{
- FieldInfo.DocValuesType dvType = field.FieldTypeValue.DocValueType;
+ FieldInfo.DocValuesType? dvType = field.FieldTypeValue.DocValueType;
if (dvType != null)
{
fieldInfo.DocValuesTypeValue = dvType;
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Index/DocumentsWriterFlushQueue.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/DocumentsWriterFlushQueue.cs b/src/core/Index/DocumentsWriterFlushQueue.cs
index d7df5cb..83c9805 100644
--- a/src/core/Index/DocumentsWriterFlushQueue.cs
+++ b/src/core/Index/DocumentsWriterFlushQueue.cs
@@ -117,7 +117,7 @@ namespace Lucene.Net.Index
bool canPublish;
lock (this)
{
- head = queue.Peek();
+ head = queue.Count > 0 ? queue.Peek() : null;
canPublish = head != null && head.CanPublish; // do this synced
}
if (canPublish)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Index/FieldInfos.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/FieldInfos.cs b/src/core/Index/FieldInfos.cs
index be04140..9609ad4 100644
--- a/src/core/Index/FieldInfos.cs
+++ b/src/core/Index/FieldInfos.cs
@@ -62,17 +62,22 @@ namespace Lucene.Net.Index
foreach (FieldInfo info in infos)
{
- FieldInfo previous = byNumber[info.number] = info;
- if (previous != null)
+ FieldInfo previous;
+
+ if (byNumber.TryGetValue(info.number, out previous))
{
throw new ArgumentException("duplicate field numbers: " + previous.name + " and " + info.name + " have: " + info.number);
}
- previous = byName[info.name] = info;
- if (previous != null)
+
+ byNumber[info.number] = info;
+
+ if (byName.TryGetValue(info.name, out previous))
{
throw new ArgumentException("duplicate field names: " + previous.number + " and " + info.number + " have: " + info.name);
}
+ byName[info.name] = info;
+
hasVectors |= info.HasVectors;
hasProx |= info.IsIndexed && info.IndexOptionsValue >= Index.FieldInfo.IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
hasFreq |= info.IsIndexed && info.IndexOptionsValue != Index.FieldInfo.IndexOptions.DOCS_ONLY;
@@ -165,7 +170,7 @@ namespace Lucene.Net.Index
// We use this to enforce that a given field never
// changes DV type, even across segments / IndexWriter
// sessions:
- private readonly IDictionary<string, Index.FieldInfo.DocValuesType> docValuesType;
+ private readonly IDictionary<string, Index.FieldInfo.DocValuesType?> docValuesType;
// TODO: we should similarly catch an attempt to turn
// norms back on after they were already ommitted; today
@@ -176,16 +181,16 @@ namespace Lucene.Net.Index
{
this.nameToNumber = new HashMap<string, int>();
this.numberToName = new HashMap<int, string>();
- this.docValuesType = new HashMap<string, Index.FieldInfo.DocValuesType>();
+ this.docValuesType = new HashMap<string, Index.FieldInfo.DocValuesType?>();
}
- internal int AddOrGet(string fieldName, int preferredFieldNumber, Index.FieldInfo.DocValuesType dvType)
+ internal int AddOrGet(string fieldName, int preferredFieldNumber, Index.FieldInfo.DocValuesType? dvType)
{
lock (this)
{
if (dvType != null)
{
- Index.FieldInfo.DocValuesType currentDVType = docValuesType[fieldName];
+ Index.FieldInfo.DocValuesType? currentDVType = docValuesType[fieldName];
if (currentDVType == null)
{
docValuesType[fieldName] = dvType;
@@ -195,8 +200,8 @@ namespace Lucene.Net.Index
throw new ArgumentException("cannot change DocValues type from " + currentDVType + " to " + dvType + " for field \"" + fieldName + "\"");
}
}
- int fieldNumber = nameToNumber[fieldName];
- if (fieldNumber == null)
+ int fieldNumber;
+ if (!nameToNumber.TryGetValue(fieldName, out fieldNumber))
{
int preferredBoxed = preferredFieldNumber; // .NET port: no need to box here
@@ -281,7 +286,7 @@ namespace Lucene.Net.Index
}
private FieldInfo AddOrUpdateInternal(String name, int preferredFieldNumber, bool isIndexed,
- bool storeTermVector, bool omitNorms, bool storePayloads, Index.FieldInfo.IndexOptions indexOptions, Index.FieldInfo.DocValuesType docValues, Index.FieldInfo.DocValuesType? normType)
+ bool storeTermVector, bool omitNorms, bool storePayloads, Index.FieldInfo.IndexOptions indexOptions, Index.FieldInfo.DocValuesType? docValues, Index.FieldInfo.DocValuesType? normType)
{
FieldInfo fi = FieldInfo(name);
if (fi == null)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Index/IIndexableField.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/IIndexableField.cs b/src/core/Index/IIndexableField.cs
index 29ff853..f7f12f7 100644
--- a/src/core/Index/IIndexableField.cs
+++ b/src/core/Index/IIndexableField.cs
@@ -22,7 +22,7 @@ namespace Lucene.Net.Index
TextReader ReaderValue { get; }
- object NumericValue { get; }
+ long NumericValue { get; }
TokenStream TokenStream(Analyzer analyzer);
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Index/IIndexableFieldType.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/IIndexableFieldType.cs b/src/core/Index/IIndexableFieldType.cs
index c0d370c..3a0e57b 100644
--- a/src/core/Index/IIndexableFieldType.cs
+++ b/src/core/Index/IIndexableFieldType.cs
@@ -25,6 +25,6 @@ namespace Lucene.Net.Index
FieldInfo.IndexOptions IndexOptions { get; }
- FieldInfo.DocValuesType DocValueType { get; }
+ FieldInfo.DocValuesType? DocValueType { get; }
}
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Index/IndexReaderContext.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/IndexReaderContext.cs b/src/core/Index/IndexReaderContext.cs
index 3fcbba8..622a020 100644
--- a/src/core/Index/IndexReaderContext.cs
+++ b/src/core/Index/IndexReaderContext.cs
@@ -14,7 +14,7 @@ namespace Lucene.Net.Index
public IndexReaderContext(CompositeReaderContext parent, int ordInParent, int docBaseInParent)
{
- if (this.GetType() != typeof(CompositeReaderContext) || this.GetType() != typeof(AtomicReaderContext))
+ if (!(this is CompositeReaderContext || this is AtomicReaderContext))
throw new Exception("This class should never be extended by custom code!");
//if (!(this instanceof CompositeReaderContext || this instanceof AtomicReaderContext))
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Index/SegmentInfos.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/SegmentInfos.cs b/src/core/Index/SegmentInfos.cs
index caf74a3..72cb341 100644
--- a/src/core/Index/SegmentInfos.cs
+++ b/src/core/Index/SegmentInfos.cs
@@ -159,7 +159,7 @@ namespace Lucene.Net.Index
}
else if (fileName.StartsWith(IndexFileNames.SEGMENTS))
{
- return long.Parse(fileName.Substring(1 + IndexFileNames.SEGMENTS.Length));
+ return Number.Parse(fileName.Substring(1 + IndexFileNames.SEGMENTS.Length), Character.MAX_RADIX);
}
else
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Store/BufferedIndexInput.cs
----------------------------------------------------------------------
diff --git a/src/core/Store/BufferedIndexInput.cs b/src/core/Store/BufferedIndexInput.cs
index af155b1..6243a5f 100644
--- a/src/core/Store/BufferedIndexInput.cs
+++ b/src/core/Store/BufferedIndexInput.cs
@@ -123,7 +123,7 @@ namespace Lucene.Net.Store
// the buffer contains enough data to satisfy this request
if (len > 0)
// to allow b to be null if len is 0...
- Array.Copy(buffer, bufferPosition, b, offset, len);
+ Buffer.BlockCopy(buffer, bufferPosition, b, offset, len);
bufferPosition += len;
}
else
@@ -132,7 +132,7 @@ namespace Lucene.Net.Store
int available = bufferLength - bufferPosition;
if (available > 0)
{
- Array.Copy(buffer, bufferPosition, b, offset, available);
+ Buffer.BlockCopy(buffer, bufferPosition, b, offset, available);
offset += available;
len -= available;
bufferPosition += available;
@@ -147,12 +147,12 @@ namespace Lucene.Net.Store
if (bufferLength < len)
{
// Throw an exception when refill() could not read len bytes:
- Array.Copy(buffer, 0, b, offset, bufferLength);
+ Buffer.BlockCopy(buffer, 0, b, offset, bufferLength);
throw new System.IO.IOException("read past EOF");
}
else
{
- Array.Copy(buffer, 0, b, offset, len);
+ Buffer.BlockCopy(buffer, 0, b, offset, len);
bufferPosition = len;
}
}
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Store/BufferedIndexOutput.cs
----------------------------------------------------------------------
diff --git a/src/core/Store/BufferedIndexOutput.cs b/src/core/Store/BufferedIndexOutput.cs
index 79e8dc1..8c9c96f 100644
--- a/src/core/Store/BufferedIndexOutput.cs
+++ b/src/core/Store/BufferedIndexOutput.cs
@@ -70,7 +70,7 @@ namespace Lucene.Net.Store
if (bytesLeft >= length)
{
// we add the data to the end of the buffer
- Array.Copy(b, offset, buffer, bufferPosition, length);
+ Buffer.BlockCopy(b, offset, buffer, bufferPosition, length);
bufferPosition += length;
// if the buffer is full, flush it
if (bufferSize - bufferPosition == 0)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Store/DataOutput.cs
----------------------------------------------------------------------
diff --git a/src/core/Store/DataOutput.cs b/src/core/Store/DataOutput.cs
index 2368b6f..4310f93 100644
--- a/src/core/Store/DataOutput.cs
+++ b/src/core/Store/DataOutput.cs
@@ -32,7 +32,7 @@ namespace Lucene.Net.Store
public void WriteByte(sbyte b)
{
// helper method to account for java's byte being signed
- WriteByte((sbyte)b);
+ WriteByte((byte)b);
}
public virtual void WriteInt(int i)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Store/RAMOutputStream.cs
----------------------------------------------------------------------
diff --git a/src/core/Store/RAMOutputStream.cs b/src/core/Store/RAMOutputStream.cs
index 74103b3..54b81a7 100644
--- a/src/core/Store/RAMOutputStream.cs
+++ b/src/core/Store/RAMOutputStream.cs
@@ -162,7 +162,7 @@ namespace Lucene.Net.Store
int remainInBuffer = currentBuffer.Length - bufferPosition;
int bytesToCopy = len < remainInBuffer ? len : remainInBuffer;
- Array.Copy(b, offset, currentBuffer, bufferPosition, bytesToCopy);
+ Buffer.BlockCopy(b, offset, currentBuffer, bufferPosition, bytesToCopy);
offset += bytesToCopy;
len -= bytesToCopy;
bufferPosition += bytesToCopy;
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Util/Fst/Builder.cs
----------------------------------------------------------------------
diff --git a/src/core/Util/Fst/Builder.cs b/src/core/Util/Fst/Builder.cs
index 626b4ab..2fa93be 100644
--- a/src/core/Util/Fst/Builder.cs
+++ b/src/core/Util/Fst/Builder.cs
@@ -415,7 +415,7 @@ namespace Lucene.Net.Util.Fst
public UnCompiledNode(Builder<T> owner, int depth)
{
_owner = owner;
- Arcs = new FST<T>.Arc<T>[1] as Arc<T>[];
+ Arcs = new Arc<T>[1];
Arcs[0] = new Arc<T>();
Output = owner.NO_OUTPUT;
_depth = depth;
@@ -447,7 +447,7 @@ namespace Lucene.Net.Util.Fst
if (!(label >= 0)) throw new ArgumentException("label must be greater than or equal to zero");
// TODO: is debug.assert correct here? or is this validation? ...
- Debug.Assert(NumArcs == 0 || label > Arcs[NumArcs - 1].Label, "arc[-1].label=" + Arcs[NumArcs - 1].Label + " new label=" + label + " numArcs=" + NumArcs);
+ //Debug.Assert(NumArcs == 0 || label > Arcs[NumArcs - 1].Label, "arc[-1].label=" + Arcs[NumArcs - 1].Label + " new label=" + label + " numArcs=" + NumArcs);
if (NumArcs == Arcs.Length)
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Util/Fst/FST.cs
----------------------------------------------------------------------
diff --git a/src/core/Util/Fst/FST.cs b/src/core/Util/Fst/FST.cs
index 96f0cf7..c6cbcd6 100644
--- a/src/core/Util/Fst/FST.cs
+++ b/src/core/Util/Fst/FST.cs
@@ -224,7 +224,7 @@ namespace Lucene.Net.Util.Fst
internal void Save(DataOutput output)
{
- if (startNode != -1)
+ if (startNode == -1)
throw new InvalidOperationException("call finish first");
if (NodeAddress != null)
throw new InvalidOperationException("cannot save an FST pre-packed FST; it must first be packed");
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Util/IOUtils.cs
----------------------------------------------------------------------
diff --git a/src/core/Util/IOUtils.cs b/src/core/Util/IOUtils.cs
index ab2b960..16bce94 100644
--- a/src/core/Util/IOUtils.cs
+++ b/src/core/Util/IOUtils.cs
@@ -16,7 +16,7 @@ namespace Lucene.Net.Util
where E : Exception
{
// java version has a separate implementation here, but might as well re-use the other one until we can't
- CloseWhileHandlingException<E>(priorException, objects);
+ CloseWhileHandlingException<E>(priorException, (IEnumerable<IDisposable>)objects);
}
public static void CloseWhileHandlingException<E>(E priorException, IEnumerable<IDisposable> objects)
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Util/NamedSPILoader.cs
----------------------------------------------------------------------
diff --git a/src/core/Util/NamedSPILoader.cs b/src/core/Util/NamedSPILoader.cs
index 21ddce1..e40145f 100644
--- a/src/core/Util/NamedSPILoader.cs
+++ b/src/core/Util/NamedSPILoader.cs
@@ -24,7 +24,7 @@ namespace Lucene.Net.Util
public void Reload()
{
IDictionary<String, S> services = new Dictionary<String, S>(this.services);
- SPIClassIterator<S> loader = SPIClassIterator<S>.Get(clazz);
+ SPIClassIterator<S> loader = SPIClassIterator<S>.Get();
foreach (Type c in loader)
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/ec36d0d5/src/core/Util/SPIClassIterator.cs
----------------------------------------------------------------------
diff --git a/src/core/Util/SPIClassIterator.cs b/src/core/Util/SPIClassIterator.cs
index bbb7a4d..4601b44 100644
--- a/src/core/Util/SPIClassIterator.cs
+++ b/src/core/Util/SPIClassIterator.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Reflection;
using System.Text;
namespace Lucene.Net.Util
@@ -9,52 +10,41 @@ namespace Lucene.Net.Util
/// TODO: Not sure what to do here.
/// </summary>
/// <typeparam name="S"></typeparam>
- public class SPIClassIterator<S> : IEnumerable<Type>, IEnumerator<Type>
+ public class SPIClassIterator<S> : IEnumerable<Type>
{
- private static readonly string META_INF_SERVICES = "META-INF/services/";
+ private static List<Type> _types;
- private readonly Type clazz;
- private readonly IEnumerable<Uri> profilesEnum;
- private IEnumerator<string> linesIterator;
-
- public static SPIClassIterator<S> Get(Type clazz)
- {
- throw new NotImplementedException();
- }
-
- public Type Current
+ static SPIClassIterator()
{
- get { throw new NotImplementedException(); }
- }
+ _types = new List<Type>();
- public void Dispose()
- {
- throw new NotImplementedException();
+ foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
+ {
+ foreach (var type in assembly.GetTypes())
+ {
+ if (typeof(S).IsAssignableFrom(type) && !type.IsAbstract && !type.IsInterface && type.GetConstructor(Type.EmptyTypes) != null)
+ _types.Add(type);
+ }
+ }
}
- object System.Collections.IEnumerator.Current
- {
- get { throw new NotImplementedException(); }
- }
+ //private static readonly string META_INF_SERVICES = "META-INF/services/";
- public bool MoveNext()
- {
- throw new NotImplementedException();
- }
+
- public void Reset()
+ public static SPIClassIterator<S> Get()
{
- throw new NotImplementedException();
+ return new SPIClassIterator<S>();
}
-
+
public IEnumerator<Type> GetEnumerator()
{
- return this;
+ return _types.GetEnumerator();
}
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
- return this;
+ return GetEnumerator();
}
}
}