You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by cc...@apache.org on 2013/04/03 19:39:57 UTC
[14/51] [partial] Mass convert mixed tabs to spaces
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/62f018ab/src/core/Index/DocumentsWriterThreadState.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/DocumentsWriterThreadState.cs b/src/core/Index/DocumentsWriterThreadState.cs
index e20fbee..255a2ae 100644
--- a/src/core/Index/DocumentsWriterThreadState.cs
+++ b/src/core/Index/DocumentsWriterThreadState.cs
@@ -19,38 +19,38 @@ using System;
namespace Lucene.Net.Index
{
-
- /// <summary>Used by DocumentsWriter to maintain per-thread state.
- /// We keep a separate Posting hash and other state for each
- /// thread and then merge postings hashes from all threads
- /// when writing the segment.
- /// </summary>
- sealed class DocumentsWriterThreadState
- {
-
- internal bool isIdle = true; // false if this is currently in use by a thread
- internal int numThreads = 1; // Number of threads that share this instance
- internal bool doFlushAfter; // true if we should flush after processing current doc
- internal DocConsumerPerThread consumer;
- internal DocumentsWriter.DocState docState;
-
- internal DocumentsWriter docWriter;
-
- public DocumentsWriterThreadState(DocumentsWriter docWriter)
- {
- this.docWriter = docWriter;
- docState = new DocumentsWriter.DocState();
- docState.maxFieldLength = docWriter.maxFieldLength;
- docState.infoStream = docWriter.infoStream;
- docState.similarity = docWriter.similarity;
- docState.docWriter = docWriter;
- consumer = docWriter.consumer.AddThread(this);
- }
-
- internal void DoAfterFlush()
- {
- numThreads = 0;
- doFlushAfter = false;
- }
- }
+
+ /// <summary>Used by DocumentsWriter to maintain per-thread state.
+ /// We keep a separate Posting hash and other state for each
+ /// thread and then merge postings hashes from all threads
+ /// when writing the segment.
+ /// </summary>
+ sealed class DocumentsWriterThreadState
+ {
+
+ internal bool isIdle = true; // false if this is currently in use by a thread
+ internal int numThreads = 1; // Number of threads that share this instance
+ internal bool doFlushAfter; // true if we should flush after processing current doc
+ internal DocConsumerPerThread consumer;
+ internal DocumentsWriter.DocState docState;
+
+ internal DocumentsWriter docWriter;
+
+ public DocumentsWriterThreadState(DocumentsWriter docWriter)
+ {
+ this.docWriter = docWriter;
+ docState = new DocumentsWriter.DocState();
+ docState.maxFieldLength = docWriter.maxFieldLength;
+ docState.infoStream = docWriter.infoStream;
+ docState.similarity = docWriter.similarity;
+ docState.docWriter = docWriter;
+ consumer = docWriter.consumer.AddThread(this);
+ }
+
+ internal void DoAfterFlush()
+ {
+ numThreads = 0;
+ doFlushAfter = false;
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/62f018ab/src/core/Index/FieldInfo.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/FieldInfo.cs b/src/core/Index/FieldInfo.cs
index bfca8af..d74ac4e 100644
--- a/src/core/Index/FieldInfo.cs
+++ b/src/core/Index/FieldInfo.cs
@@ -19,89 +19,89 @@ using System;
namespace Lucene.Net.Index
{
-
- public sealed class FieldInfo : System.ICloneable
- {
- internal System.String name;
- internal bool isIndexed;
- internal int number;
-
- // true if term vector for this field should be stored
- internal bool storeTermVector;
- internal bool storeOffsetWithTermVector;
- internal bool storePositionWithTermVector;
-
- internal bool omitNorms; // omit norms associated with indexed fields
- internal bool omitTermFreqAndPositions;
-
- internal bool storePayloads; // whether this field stores payloads together with term positions
-
- internal FieldInfo(System.String na, bool tk, int nu, bool storeTermVector, bool storePositionWithTermVector, bool storeOffsetWithTermVector, bool omitNorms, bool storePayloads, bool omitTermFreqAndPositions)
- {
- name = na;
- isIndexed = tk;
- number = nu;
- if (isIndexed)
- {
- this.storeTermVector = storeTermVector;
- this.storeOffsetWithTermVector = storeOffsetWithTermVector;
- this.storePositionWithTermVector = storePositionWithTermVector;
- this.storePayloads = storePayloads;
- this.omitNorms = omitNorms;
- this.omitTermFreqAndPositions = omitTermFreqAndPositions;
- }
- else
- {
- // for non-indexed fields, leave defaults
- this.storeTermVector = false;
- this.storeOffsetWithTermVector = false;
- this.storePositionWithTermVector = false;
- this.storePayloads = false;
- this.omitNorms = true;
- this.omitTermFreqAndPositions = false;
- }
- }
-
- public System.Object Clone()
- {
- return new FieldInfo(name, isIndexed, number, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
- }
-
- internal void Update(bool isIndexed, bool storeTermVector, bool storePositionWithTermVector, bool storeOffsetWithTermVector, bool omitNorms, bool storePayloads, bool omitTermFreqAndPositions)
- {
- if (this.isIndexed != isIndexed)
- {
- this.isIndexed = true; // once indexed, always index
- }
- if (isIndexed)
- {
- // if updated field data is not for indexing, leave the updates out
- if (this.storeTermVector != storeTermVector)
- {
- this.storeTermVector = true; // once vector, always vector
- }
- if (this.storePositionWithTermVector != storePositionWithTermVector)
- {
- this.storePositionWithTermVector = true; // once vector, always vector
- }
- if (this.storeOffsetWithTermVector != storeOffsetWithTermVector)
- {
- this.storeOffsetWithTermVector = true; // once vector, always vector
- }
- if (this.storePayloads != storePayloads)
- {
- this.storePayloads = true;
- }
- if (this.omitNorms != omitNorms)
- {
- this.omitNorms = false; // once norms are stored, always store
- }
- if (this.omitTermFreqAndPositions != omitTermFreqAndPositions)
- {
- this.omitTermFreqAndPositions = true; // if one require omitTermFreqAndPositions at least once, it remains off for life
- }
- }
- }
+
+ public sealed class FieldInfo : System.ICloneable
+ {
+ internal System.String name;
+ internal bool isIndexed;
+ internal int number;
+
+ // true if term vector for this field should be stored
+ internal bool storeTermVector;
+ internal bool storeOffsetWithTermVector;
+ internal bool storePositionWithTermVector;
+
+ internal bool omitNorms; // omit norms associated with indexed fields
+ internal bool omitTermFreqAndPositions;
+
+ internal bool storePayloads; // whether this field stores payloads together with term positions
+
+ internal FieldInfo(System.String na, bool tk, int nu, bool storeTermVector, bool storePositionWithTermVector, bool storeOffsetWithTermVector, bool omitNorms, bool storePayloads, bool omitTermFreqAndPositions)
+ {
+ name = na;
+ isIndexed = tk;
+ number = nu;
+ if (isIndexed)
+ {
+ this.storeTermVector = storeTermVector;
+ this.storeOffsetWithTermVector = storeOffsetWithTermVector;
+ this.storePositionWithTermVector = storePositionWithTermVector;
+ this.storePayloads = storePayloads;
+ this.omitNorms = omitNorms;
+ this.omitTermFreqAndPositions = omitTermFreqAndPositions;
+ }
+ else
+ {
+ // for non-indexed fields, leave defaults
+ this.storeTermVector = false;
+ this.storeOffsetWithTermVector = false;
+ this.storePositionWithTermVector = false;
+ this.storePayloads = false;
+ this.omitNorms = true;
+ this.omitTermFreqAndPositions = false;
+ }
+ }
+
+ public System.Object Clone()
+ {
+ return new FieldInfo(name, isIndexed, number, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
+ }
+
+ internal void Update(bool isIndexed, bool storeTermVector, bool storePositionWithTermVector, bool storeOffsetWithTermVector, bool omitNorms, bool storePayloads, bool omitTermFreqAndPositions)
+ {
+ if (this.isIndexed != isIndexed)
+ {
+ this.isIndexed = true; // once indexed, always index
+ }
+ if (isIndexed)
+ {
+ // if updated field data is not for indexing, leave the updates out
+ if (this.storeTermVector != storeTermVector)
+ {
+ this.storeTermVector = true; // once vector, always vector
+ }
+ if (this.storePositionWithTermVector != storePositionWithTermVector)
+ {
+ this.storePositionWithTermVector = true; // once vector, always vector
+ }
+ if (this.storeOffsetWithTermVector != storeOffsetWithTermVector)
+ {
+ this.storeOffsetWithTermVector = true; // once vector, always vector
+ }
+ if (this.storePayloads != storePayloads)
+ {
+ this.storePayloads = true;
+ }
+ if (this.omitNorms != omitNorms)
+ {
+ this.omitNorms = false; // once norms are stored, always store
+ }
+ if (this.omitTermFreqAndPositions != omitTermFreqAndPositions)
+ {
+ this.omitTermFreqAndPositions = true; // if one require omitTermFreqAndPositions at least once, it remains off for life
+ }
+ }
+ }
public bool storePayloads_ForNUnit
{
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/62f018ab/src/core/Index/FieldInfos.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/FieldInfos.cs b/src/core/Index/FieldInfos.cs
index 8c9cae6..7ff523d 100644
--- a/src/core/Index/FieldInfos.cs
+++ b/src/core/Index/FieldInfos.cs
@@ -26,102 +26,102 @@ using StringHelper = Lucene.Net.Util.StringHelper;
namespace Lucene.Net.Index
{
-
- /// <summary>Access to the Fieldable Info file that describes document fields and whether or
- /// not they are indexed. Each segment has a separate Fieldable Info file. Objects
- /// of this class are thread-safe for multiple readers, but only one thread can
- /// be adding documents at a time, with no other reader or writer threads
- /// accessing this object.
- /// </summary>
- public sealed class FieldInfos : ICloneable
- {
-
- // Used internally (ie not written to *.fnm files) for pre-2.9 files
- public const int FORMAT_PRE = - 1;
-
- // First used in 2.9; prior to 2.9 there was no format header
- public const int FORMAT_START = - 2;
-
- internal static readonly int CURRENT_FORMAT = FORMAT_START;
-
- internal const byte IS_INDEXED = (0x1);
- internal const byte STORE_TERMVECTOR = (0x2);
- internal const byte STORE_POSITIONS_WITH_TERMVECTOR =(0x4);
- internal const byte STORE_OFFSET_WITH_TERMVECTOR = (0x8);
- internal const byte OMIT_NORMS = (0x10);
- internal const byte STORE_PAYLOADS = (0x20);
- internal const byte OMIT_TERM_FREQ_AND_POSITIONS = (0x40);
+
+ /// <summary>Access to the Fieldable Info file that describes document fields and whether or
+ /// not they are indexed. Each segment has a separate Fieldable Info file. Objects
+ /// of this class are thread-safe for multiple readers, but only one thread can
+ /// be adding documents at a time, with no other reader or writer threads
+ /// accessing this object.
+ /// </summary>
+ public sealed class FieldInfos : ICloneable
+ {
+
+ // Used internally (ie not written to *.fnm files) for pre-2.9 files
+ public const int FORMAT_PRE = - 1;
+
+ // First used in 2.9; prior to 2.9 there was no format header
+ public const int FORMAT_START = - 2;
+
+ internal static readonly int CURRENT_FORMAT = FORMAT_START;
+
+ internal const byte IS_INDEXED = (0x1);
+ internal const byte STORE_TERMVECTOR = (0x2);
+ internal const byte STORE_POSITIONS_WITH_TERMVECTOR =(0x4);
+ internal const byte STORE_OFFSET_WITH_TERMVECTOR = (0x8);
+ internal const byte OMIT_NORMS = (0x10);
+ internal const byte STORE_PAYLOADS = (0x20);
+ internal const byte OMIT_TERM_FREQ_AND_POSITIONS = (0x40);
private readonly System.Collections.Generic.List<FieldInfo> byNumber = new System.Collections.Generic.List<FieldInfo>();
private readonly HashMap<string, FieldInfo> byName = new HashMap<string, FieldInfo>();
- private int format;
-
- public /*internal*/ FieldInfos()
- {
- }
-
- /// <summary> Construct a FieldInfos object using the directory and the name of the file
- /// IndexInput
- /// </summary>
- /// <param name="d">The directory to open the IndexInput from
- /// </param>
- /// <param name="name">The name of the file to open the IndexInput from in the Directory
- /// </param>
- /// <throws> IOException </throws>
- public /*internal*/ FieldInfos(Directory d, String name)
- {
- IndexInput input = d.OpenInput(name);
- try
- {
- try
- {
- Read(input, name);
- }
- catch (System.IO.IOException)
- {
- if (format == FORMAT_PRE)
- {
- // LUCENE-1623: FORMAT_PRE (before there was a
- // format) may be 2.3.2 (pre-utf8) or 2.4.x (utf8)
- // encoding; retry with input set to pre-utf8
- input.Seek(0);
- input.SetModifiedUTF8StringsMode();
- byNumber.Clear();
- byName.Clear();
+ private int format;
+
+ public /*internal*/ FieldInfos()
+ {
+ }
+
+ /// <summary> Construct a FieldInfos object using the directory and the name of the file
+ /// IndexInput
+ /// </summary>
+ /// <param name="d">The directory to open the IndexInput from
+ /// </param>
+ /// <param name="name">The name of the file to open the IndexInput from in the Directory
+ /// </param>
+ /// <throws> IOException </throws>
+ public /*internal*/ FieldInfos(Directory d, String name)
+ {
+ IndexInput input = d.OpenInput(name);
+ try
+ {
+ try
+ {
+ Read(input, name);
+ }
+ catch (System.IO.IOException)
+ {
+ if (format == FORMAT_PRE)
+ {
+ // LUCENE-1623: FORMAT_PRE (before there was a
+ // format) may be 2.3.2 (pre-utf8) or 2.4.x (utf8)
+ // encoding; retry with input set to pre-utf8
+ input.Seek(0);
+ input.SetModifiedUTF8StringsMode();
+ byNumber.Clear();
+ byName.Clear();
- bool rethrow = false;
- try
- {
- Read(input, name);
- }
- catch (Exception)
+ bool rethrow = false;
+ try
+ {
+ Read(input, name);
+ }
+ catch (Exception)
{
// Ignore any new exception & set to throw original IOE
- rethrow = true;
- }
+ rethrow = true;
+ }
if(rethrow)
{
// Preserve stack trace
throw;
}
- }
- else
- {
- // The IOException cannot be caused by
- // LUCENE-1623, so re-throw it
- throw;
- }
- }
- }
- finally
- {
- input.Close();
- }
- }
-
- /// <summary> Returns a deep clone of this FieldInfos instance.</summary>
- public Object Clone()
- {
+ }
+ else
+ {
+ // The IOException cannot be caused by
+ // LUCENE-1623, so re-throw it
+ throw;
+ }
+ }
+ }
+ finally
+ {
+ input.Close();
+ }
+ }
+
+ /// <summary> Returns a deep clone of this FieldInfos instance.</summary>
+ public Object Clone()
+ {
lock (this)
{
var fis = new FieldInfos();
@@ -134,358 +134,358 @@ namespace Lucene.Net.Index
}
return fis;
}
- }
-
- /// <summary>Adds field info for a Document. </summary>
- public void Add(Document doc)
- {
- lock (this)
- {
- System.Collections.Generic.IList<IFieldable> fields = doc.GetFields();
+ }
+
+ /// <summary>Adds field info for a Document. </summary>
+ public void Add(Document doc)
+ {
+ lock (this)
+ {
+ System.Collections.Generic.IList<IFieldable> fields = doc.GetFields();
foreach(IFieldable field in fields)
{
Add(field.Name, field.IsIndexed, field.IsTermVectorStored,
field.IsStorePositionWithTermVector, field.IsStoreOffsetWithTermVector, field.OmitNorms,
false, field.OmitTermFreqAndPositions);
}
- }
- }
-
- /// <summary>Returns true if any fields do not omitTermFreqAndPositions </summary>
- internal bool HasProx()
- {
- int numFields = byNumber.Count;
- for (int i = 0; i < numFields; i++)
- {
- FieldInfo fi = FieldInfo(i);
- if (fi.isIndexed && !fi.omitTermFreqAndPositions)
- {
- return true;
- }
- }
- return false;
- }
-
- /// <summary> Add fields that are indexed. Whether they have termvectors has to be specified.
- ///
- /// </summary>
- /// <param name="names">The names of the fields
- /// </param>
- /// <param name="storeTermVectors">Whether the fields store term vectors or not
- /// </param>
- /// <param name="storePositionWithTermVector">true if positions should be stored.
- /// </param>
- /// <param name="storeOffsetWithTermVector">true if offsets should be stored
- /// </param>
- public void AddIndexed(System.Collections.Generic.ICollection<string> names, bool storeTermVectors, bool storePositionWithTermVector, bool storeOffsetWithTermVector)
- {
- lock (this)
- {
- foreach(string name in names)
- {
- Add(name, true, storeTermVectors, storePositionWithTermVector, storeOffsetWithTermVector);
- }
- }
- }
-
- /// <summary> Assumes the fields are not storing term vectors.
- ///
- /// </summary>
- /// <param name="names">The names of the fields
- /// </param>
- /// <param name="isIndexed">Whether the fields are indexed or not
- ///
- /// </param>
- /// <seealso cref="Add(String, bool)">
- /// </seealso>
+ }
+ }
+
+ /// <summary>Returns true if any fields do not omitTermFreqAndPositions </summary>
+ internal bool HasProx()
+ {
+ int numFields = byNumber.Count;
+ for (int i = 0; i < numFields; i++)
+ {
+ FieldInfo fi = FieldInfo(i);
+ if (fi.isIndexed && !fi.omitTermFreqAndPositions)
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /// <summary> Add fields that are indexed. Whether they have termvectors has to be specified.
+ ///
+ /// </summary>
+ /// <param name="names">The names of the fields
+ /// </param>
+ /// <param name="storeTermVectors">Whether the fields store term vectors or not
+ /// </param>
+ /// <param name="storePositionWithTermVector">true if positions should be stored.
+ /// </param>
+ /// <param name="storeOffsetWithTermVector">true if offsets should be stored
+ /// </param>
+ public void AddIndexed(System.Collections.Generic.ICollection<string> names, bool storeTermVectors, bool storePositionWithTermVector, bool storeOffsetWithTermVector)
+ {
+ lock (this)
+ {
+ foreach(string name in names)
+ {
+ Add(name, true, storeTermVectors, storePositionWithTermVector, storeOffsetWithTermVector);
+ }
+ }
+ }
+
+ /// <summary> Assumes the fields are not storing term vectors.
+ ///
+ /// </summary>
+ /// <param name="names">The names of the fields
+ /// </param>
+ /// <param name="isIndexed">Whether the fields are indexed or not
+ ///
+ /// </param>
+ /// <seealso cref="Add(String, bool)">
+ /// </seealso>
public void Add(System.Collections.Generic.ICollection<string> names, bool isIndexed)
- {
- lock (this)
- {
- foreach(string name in names)
- {
- Add(name, isIndexed);
- }
- }
- }
-
- /// <summary> Calls 5 parameter add with false for all TermVector parameters.
- ///
- /// </summary>
- /// <param name="name">The name of the Fieldable
- /// </param>
- /// <param name="isIndexed">true if the field is indexed
- /// </param>
+ {
+ lock (this)
+ {
+ foreach(string name in names)
+ {
+ Add(name, isIndexed);
+ }
+ }
+ }
+
+ /// <summary> Calls 5 parameter add with false for all TermVector parameters.
+ ///
+ /// </summary>
+ /// <param name="name">The name of the Fieldable
+ /// </param>
+ /// <param name="isIndexed">true if the field is indexed
+ /// </param>
/// <seealso cref="Add(String, bool, bool, bool, bool)">
- /// </seealso>
- public void Add(String name, bool isIndexed)
- {
- lock (this)
- {
- Add(name, isIndexed, false, false, false, false);
- }
- }
-
- /// <summary> Calls 5 parameter add with false for term vector positions and offsets.
- ///
- /// </summary>
- /// <param name="name">The name of the field
- /// </param>
- /// <param name="isIndexed"> true if the field is indexed
- /// </param>
- /// <param name="storeTermVector">true if the term vector should be stored
- /// </param>
- public void Add(System.String name, bool isIndexed, bool storeTermVector)
- {
- lock (this)
- {
- Add(name, isIndexed, storeTermVector, false, false, false);
- }
- }
-
- /// <summary>If the field is not yet known, adds it. If it is known, checks to make
- /// sure that the isIndexed flag is the same as was given previously for this
- /// field. If not - marks it as being indexed. Same goes for the TermVector
- /// parameters.
- ///
- /// </summary>
- /// <param name="name">The name of the field
- /// </param>
- /// <param name="isIndexed">true if the field is indexed
- /// </param>
- /// <param name="storeTermVector">true if the term vector should be stored
- /// </param>
- /// <param name="storePositionWithTermVector">true if the term vector with positions should be stored
- /// </param>
- /// <param name="storeOffsetWithTermVector">true if the term vector with offsets should be stored
- /// </param>
- public void Add(System.String name, bool isIndexed, bool storeTermVector, bool storePositionWithTermVector, bool storeOffsetWithTermVector)
- {
- lock (this)
- {
-
- Add(name, isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, false);
- }
- }
-
- /// <summary>If the field is not yet known, adds it. If it is known, checks to make
- /// sure that the isIndexed flag is the same as was given previously for this
- /// field. If not - marks it as being indexed. Same goes for the TermVector
- /// parameters.
- ///
- /// </summary>
- /// <param name="name">The name of the field
- /// </param>
- /// <param name="isIndexed">true if the field is indexed
- /// </param>
- /// <param name="storeTermVector">true if the term vector should be stored
- /// </param>
- /// <param name="storePositionWithTermVector">true if the term vector with positions should be stored
- /// </param>
- /// <param name="storeOffsetWithTermVector">true if the term vector with offsets should be stored
- /// </param>
- /// <param name="omitNorms">true if the norms for the indexed field should be omitted
- /// </param>
- public void Add(System.String name, bool isIndexed, bool storeTermVector, bool storePositionWithTermVector, bool storeOffsetWithTermVector, bool omitNorms)
- {
- lock (this)
- {
- Add(name, isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, false, false);
- }
- }
-
- /// <summary>If the field is not yet known, adds it. If it is known, checks to make
- /// sure that the isIndexed flag is the same as was given previously for this
- /// field. If not - marks it as being indexed. Same goes for the TermVector
- /// parameters.
- ///
- /// </summary>
- /// <param name="name">The name of the field
- /// </param>
- /// <param name="isIndexed">true if the field is indexed
- /// </param>
- /// <param name="storeTermVector">true if the term vector should be stored
- /// </param>
- /// <param name="storePositionWithTermVector">true if the term vector with positions should be stored
- /// </param>
- /// <param name="storeOffsetWithTermVector">true if the term vector with offsets should be stored
- /// </param>
- /// <param name="omitNorms">true if the norms for the indexed field should be omitted
- /// </param>
- /// <param name="storePayloads">true if payloads should be stored for this field
- /// </param>
- /// <param name="omitTermFreqAndPositions">true if term freqs should be omitted for this field
- /// </param>
- public FieldInfo Add(System.String name, bool isIndexed, bool storeTermVector, bool storePositionWithTermVector, bool storeOffsetWithTermVector, bool omitNorms, bool storePayloads, bool omitTermFreqAndPositions)
- {
- lock (this)
- {
- FieldInfo fi = FieldInfo(name);
- if (fi == null)
- {
- return AddInternal(name, isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
- }
- else
- {
- fi.Update(isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
- }
- return fi;
- }
- }
-
- private FieldInfo AddInternal(String name, bool isIndexed, bool storeTermVector, bool storePositionWithTermVector, bool storeOffsetWithTermVector, bool omitNorms, bool storePayloads, bool omitTermFreqAndPositions)
- {
- name = StringHelper.Intern(name);
- var fi = new FieldInfo(name, isIndexed, byNumber.Count, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
- byNumber.Add(fi);
- byName[name] = fi;
- return fi;
- }
-
- public int FieldNumber(System.String fieldName)
- {
- FieldInfo fi = FieldInfo(fieldName);
- return (fi != null)?fi.number:- 1;
- }
-
- public FieldInfo FieldInfo(System.String fieldName)
- {
- return byName[fieldName];
- }
-
- /// <summary> Return the fieldName identified by its number.
- ///
- /// </summary>
- /// <param name="fieldNumber">
- /// </param>
- /// <returns> the fieldName or an empty string when the field
- /// with the given number doesn't exist.
- /// </returns>
- public System.String FieldName(int fieldNumber)
- {
- FieldInfo fi = FieldInfo(fieldNumber);
- return (fi != null) ? fi.name : "";
- }
-
- /// <summary> Return the fieldinfo object referenced by the fieldNumber.</summary>
- /// <param name="fieldNumber">
- /// </param>
- /// <returns> the FieldInfo object or null when the given fieldNumber
- /// doesn't exist.
- /// </returns>
- public FieldInfo FieldInfo(int fieldNumber)
- {
- return (fieldNumber >= 0) ? byNumber[fieldNumber] : null;
- }
-
- public int Size()
- {
- return byNumber.Count;
- }
-
- public bool HasVectors()
- {
- bool hasVectors = false;
- for (int i = 0; i < Size(); i++)
- {
- if (FieldInfo(i).storeTermVector)
- {
- hasVectors = true;
- break;
- }
- }
- return hasVectors;
- }
-
- public void Write(Directory d, System.String name)
- {
- IndexOutput output = d.CreateOutput(name);
- try
- {
- Write(output);
- }
- finally
- {
- output.Close();
- }
- }
-
- public void Write(IndexOutput output)
- {
- output.WriteVInt(CURRENT_FORMAT);
- output.WriteVInt(Size());
- for (int i = 0; i < Size(); i++)
- {
- FieldInfo fi = FieldInfo(i);
- var bits = (byte) (0x0);
- if (fi.isIndexed)
- bits |= IS_INDEXED;
- if (fi.storeTermVector)
- bits |= STORE_TERMVECTOR;
- if (fi.storePositionWithTermVector)
- bits |= STORE_POSITIONS_WITH_TERMVECTOR;
- if (fi.storeOffsetWithTermVector)
- bits |= STORE_OFFSET_WITH_TERMVECTOR;
- if (fi.omitNorms)
- bits |= OMIT_NORMS;
- if (fi.storePayloads)
- bits |= STORE_PAYLOADS;
- if (fi.omitTermFreqAndPositions)
- bits |= OMIT_TERM_FREQ_AND_POSITIONS;
-
- output.WriteString(fi.name);
- output.WriteByte(bits);
- }
- }
-
- private void Read(IndexInput input, String fileName)
- {
- int firstInt = input.ReadVInt();
-
- if (firstInt < 0)
- {
- // This is a real format
- format = firstInt;
- }
- else
- {
- format = FORMAT_PRE;
- }
-
- if (format != FORMAT_PRE & format != FORMAT_START)
- {
- throw new CorruptIndexException("unrecognized format " + format + " in file \"" + fileName + "\"");
- }
-
- int size;
- if (format == FORMAT_PRE)
- {
- size = firstInt;
- }
- else
- {
- size = input.ReadVInt(); //read in the size
- }
-
- for (int i = 0; i < size; i++)
- {
- String name = StringHelper.Intern(input.ReadString());
- byte bits = input.ReadByte();
- bool isIndexed = (bits & IS_INDEXED) != 0;
- bool storeTermVector = (bits & STORE_TERMVECTOR) != 0;
- bool storePositionsWithTermVector = (bits & STORE_POSITIONS_WITH_TERMVECTOR) != 0;
- bool storeOffsetWithTermVector = (bits & STORE_OFFSET_WITH_TERMVECTOR) != 0;
- bool omitNorms = (bits & OMIT_NORMS) != 0;
- bool storePayloads = (bits & STORE_PAYLOADS) != 0;
- bool omitTermFreqAndPositions = (bits & OMIT_TERM_FREQ_AND_POSITIONS) != 0;
-
- AddInternal(name, isIndexed, storeTermVector, storePositionsWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
- }
-
- if (input.FilePointer != input.Length())
- {
- throw new CorruptIndexException("did not read all bytes from file \"" + fileName + "\": read " + input.FilePointer + " vs size " + input.Length());
- }
- }
- }
+ /// </seealso>
+ public void Add(String name, bool isIndexed)
+ {
+ lock (this)
+ {
+ Add(name, isIndexed, false, false, false, false);
+ }
+ }
+
+ /// <summary> Calls 5 parameter add with false for term vector positions and offsets.
+ ///
+ /// </summary>
+ /// <param name="name">The name of the field
+ /// </param>
+ /// <param name="isIndexed"> true if the field is indexed
+ /// </param>
+ /// <param name="storeTermVector">true if the term vector should be stored
+ /// </param>
+ public void Add(System.String name, bool isIndexed, bool storeTermVector)
+ {
+ lock (this)
+ {
+ Add(name, isIndexed, storeTermVector, false, false, false);
+ }
+ }
+
+ /// <summary>If the field is not yet known, adds it. If it is known, checks to make
+ /// sure that the isIndexed flag is the same as was given previously for this
+ /// field. If not - marks it as being indexed. Same goes for the TermVector
+ /// parameters.
+ ///
+ /// </summary>
+ /// <param name="name">The name of the field
+ /// </param>
+ /// <param name="isIndexed">true if the field is indexed
+ /// </param>
+ /// <param name="storeTermVector">true if the term vector should be stored
+ /// </param>
+ /// <param name="storePositionWithTermVector">true if the term vector with positions should be stored
+ /// </param>
+ /// <param name="storeOffsetWithTermVector">true if the term vector with offsets should be stored
+ /// </param>
+ public void Add(System.String name, bool isIndexed, bool storeTermVector, bool storePositionWithTermVector, bool storeOffsetWithTermVector)
+ {
+ lock (this)
+ {
+
+ Add(name, isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, false);
+ }
+ }
+
+ /// <summary>If the field is not yet known, adds it. If it is known, checks to make
+ /// sure that the isIndexed flag is the same as was given previously for this
+ /// field. If not - marks it as being indexed. Same goes for the TermVector
+ /// parameters.
+ ///
+ /// </summary>
+ /// <param name="name">The name of the field
+ /// </param>
+ /// <param name="isIndexed">true if the field is indexed
+ /// </param>
+ /// <param name="storeTermVector">true if the term vector should be stored
+ /// </param>
+ /// <param name="storePositionWithTermVector">true if the term vector with positions should be stored
+ /// </param>
+ /// <param name="storeOffsetWithTermVector">true if the term vector with offsets should be stored
+ /// </param>
+ /// <param name="omitNorms">true if the norms for the indexed field should be omitted
+ /// </param>
+ public void Add(System.String name, bool isIndexed, bool storeTermVector, bool storePositionWithTermVector, bool storeOffsetWithTermVector, bool omitNorms)
+ {
+ lock (this)
+ {
+ Add(name, isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, false, false);
+ }
+ }
+
+ /// <summary>If the field is not yet known, adds it. If it is known, checks to make
+ /// sure that the isIndexed flag is the same as was given previously for this
+ /// field. If not - marks it as being indexed. Same goes for the TermVector
+ /// parameters.
+ ///
+ /// </summary>
+ /// <param name="name">The name of the field
+ /// </param>
+ /// <param name="isIndexed">true if the field is indexed
+ /// </param>
+ /// <param name="storeTermVector">true if the term vector should be stored
+ /// </param>
+ /// <param name="storePositionWithTermVector">true if the term vector with positions should be stored
+ /// </param>
+ /// <param name="storeOffsetWithTermVector">true if the term vector with offsets should be stored
+ /// </param>
+ /// <param name="omitNorms">true if the norms for the indexed field should be omitted
+ /// </param>
+ /// <param name="storePayloads">true if payloads should be stored for this field
+ /// </param>
+ /// <param name="omitTermFreqAndPositions">true if term freqs should be omitted for this field
+ /// </param>
+ public FieldInfo Add(System.String name, bool isIndexed, bool storeTermVector, bool storePositionWithTermVector, bool storeOffsetWithTermVector, bool omitNorms, bool storePayloads, bool omitTermFreqAndPositions)
+ {
+ lock (this)
+ {
+ FieldInfo fi = FieldInfo(name);
+ if (fi == null)
+ {
+ return AddInternal(name, isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
+ }
+ else
+ {
+ fi.Update(isIndexed, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
+ }
+ return fi;
+ }
+ }
+
+ private FieldInfo AddInternal(String name, bool isIndexed, bool storeTermVector, bool storePositionWithTermVector, bool storeOffsetWithTermVector, bool omitNorms, bool storePayloads, bool omitTermFreqAndPositions)
+ {
+ name = StringHelper.Intern(name);
+ var fi = new FieldInfo(name, isIndexed, byNumber.Count, storeTermVector, storePositionWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
+ byNumber.Add(fi);
+ byName[name] = fi;
+ return fi;
+ }
+
+ public int FieldNumber(System.String fieldName)
+ {
+ FieldInfo fi = FieldInfo(fieldName);
+ return (fi != null)?fi.number:- 1;
+ }
+
+ public FieldInfo FieldInfo(System.String fieldName)
+ {
+ return byName[fieldName];
+ }
+
+ /// <summary> Return the fieldName identified by its number.
+ ///
+ /// </summary>
+ /// <param name="fieldNumber">
+ /// </param>
+ /// <returns> the fieldName or an empty string when the field
+ /// with the given number doesn't exist.
+ /// </returns>
+ public System.String FieldName(int fieldNumber)
+ {
+ FieldInfo fi = FieldInfo(fieldNumber);
+ return (fi != null) ? fi.name : "";
+ }
+
+ /// <summary> Return the fieldinfo object referenced by the fieldNumber.</summary>
+ /// <param name="fieldNumber">
+ /// </param>
+ /// <returns> the FieldInfo object or null when the given fieldNumber
+ /// doesn't exist.
+ /// </returns>
+ public FieldInfo FieldInfo(int fieldNumber)
+ {
+ return (fieldNumber >= 0) ? byNumber[fieldNumber] : null;
+ }
+
+ public int Size()
+ {
+ return byNumber.Count;
+ }
+
+ public bool HasVectors()
+ {
+ bool hasVectors = false;
+ for (int i = 0; i < Size(); i++)
+ {
+ if (FieldInfo(i).storeTermVector)
+ {
+ hasVectors = true;
+ break;
+ }
+ }
+ return hasVectors;
+ }
+
+ public void Write(Directory d, System.String name)
+ {
+ IndexOutput output = d.CreateOutput(name);
+ try
+ {
+ Write(output);
+ }
+ finally
+ {
+ output.Close();
+ }
+ }
+
+ public void Write(IndexOutput output)
+ {
+ output.WriteVInt(CURRENT_FORMAT);
+ output.WriteVInt(Size());
+ for (int i = 0; i < Size(); i++)
+ {
+ FieldInfo fi = FieldInfo(i);
+ var bits = (byte) (0x0);
+ if (fi.isIndexed)
+ bits |= IS_INDEXED;
+ if (fi.storeTermVector)
+ bits |= STORE_TERMVECTOR;
+ if (fi.storePositionWithTermVector)
+ bits |= STORE_POSITIONS_WITH_TERMVECTOR;
+ if (fi.storeOffsetWithTermVector)
+ bits |= STORE_OFFSET_WITH_TERMVECTOR;
+ if (fi.omitNorms)
+ bits |= OMIT_NORMS;
+ if (fi.storePayloads)
+ bits |= STORE_PAYLOADS;
+ if (fi.omitTermFreqAndPositions)
+ bits |= OMIT_TERM_FREQ_AND_POSITIONS;
+
+ output.WriteString(fi.name);
+ output.WriteByte(bits);
+ }
+ }
+
+ private void Read(IndexInput input, String fileName)
+ {
+ int firstInt = input.ReadVInt();
+
+ if (firstInt < 0)
+ {
+ // This is a real format
+ format = firstInt;
+ }
+ else
+ {
+ format = FORMAT_PRE;
+ }
+
+ if (format != FORMAT_PRE & format != FORMAT_START)
+ {
+ throw new CorruptIndexException("unrecognized format " + format + " in file \"" + fileName + "\"");
+ }
+
+ int size;
+ if (format == FORMAT_PRE)
+ {
+ size = firstInt;
+ }
+ else
+ {
+ size = input.ReadVInt(); //read in the size
+ }
+
+ for (int i = 0; i < size; i++)
+ {
+ String name = StringHelper.Intern(input.ReadString());
+ byte bits = input.ReadByte();
+ bool isIndexed = (bits & IS_INDEXED) != 0;
+ bool storeTermVector = (bits & STORE_TERMVECTOR) != 0;
+ bool storePositionsWithTermVector = (bits & STORE_POSITIONS_WITH_TERMVECTOR) != 0;
+ bool storeOffsetWithTermVector = (bits & STORE_OFFSET_WITH_TERMVECTOR) != 0;
+ bool omitNorms = (bits & OMIT_NORMS) != 0;
+ bool storePayloads = (bits & STORE_PAYLOADS) != 0;
+ bool omitTermFreqAndPositions = (bits & OMIT_TERM_FREQ_AND_POSITIONS) != 0;
+
+ AddInternal(name, isIndexed, storeTermVector, storePositionsWithTermVector, storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
+ }
+
+ if (input.FilePointer != input.Length())
+ {
+ throw new CorruptIndexException("did not read all bytes from file \"" + fileName + "\": read " + input.FilePointer + " vs size " + input.Length());
+ }
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/62f018ab/src/core/Index/FieldInvertState.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/FieldInvertState.cs b/src/core/Index/FieldInvertState.cs
index 96d6c83..24d63d7 100644
--- a/src/core/Index/FieldInvertState.cs
+++ b/src/core/Index/FieldInvertState.cs
@@ -21,90 +21,90 @@ using AttributeSource = Lucene.Net.Util.AttributeSource;
namespace Lucene.Net.Index
{
-
- /// <summary> This class tracks the number and position / offset parameters of terms
- /// being added to the index. The information collected in this class is
- /// also used to calculate the normalization factor for a field.
- ///
- /// <p/><b>WARNING</b>: This API is new and experimental, and may suddenly
- /// change.<p/>
- /// </summary>
- public sealed class FieldInvertState
- {
- internal int position;
- internal int length;
- internal int numOverlap;
- internal int offset;
- internal float boost;
- internal AttributeSource attributeSource;
-
- public FieldInvertState()
- {
- }
-
- public FieldInvertState(int position, int length, int numOverlap, int offset, float boost)
- {
- this.position = position;
- this.length = length;
- this.numOverlap = numOverlap;
- this.offset = offset;
- this.boost = boost;
- }
-
- /// <summary> Re-initialize the state, using this boost value.</summary>
- /// <param name="docBoost">boost value to use.
- /// </param>
- internal void Reset(float docBoost)
- {
- position = 0;
- length = 0;
- numOverlap = 0;
- offset = 0;
- boost = docBoost;
- attributeSource = null;
- }
+
+ /// <summary> This class tracks the number and position / offset parameters of terms
+ /// being added to the index. The information collected in this class is
+ /// also used to calculate the normalization factor for a field.
+ ///
+ /// <p/><b>WARNING</b>: This API is new and experimental, and may suddenly
+ /// change.<p/>
+ /// </summary>
+ public sealed class FieldInvertState
+ {
+ internal int position;
+ internal int length;
+ internal int numOverlap;
+ internal int offset;
+ internal float boost;
+ internal AttributeSource attributeSource;
+
+ public FieldInvertState()
+ {
+ }
+
+ public FieldInvertState(int position, int length, int numOverlap, int offset, float boost)
+ {
+ this.position = position;
+ this.length = length;
+ this.numOverlap = numOverlap;
+ this.offset = offset;
+ this.boost = boost;
+ }
+
+ /// <summary> Re-initialize the state, using this boost value.</summary>
+ /// <param name="docBoost">boost value to use.
+ /// </param>
+ internal void Reset(float docBoost)
+ {
+ position = 0;
+ length = 0;
+ numOverlap = 0;
+ offset = 0;
+ boost = docBoost;
+ attributeSource = null;
+ }
- /// <summary> Get the last processed term position.</summary>
- /// <value> the position </value>
- public int Position
- {
- get { return position; }
- }
+ /// <summary> Get the last processed term position.</summary>
+ /// <value> the position </value>
+ public int Position
+ {
+ get { return position; }
+ }
- /// <summary> Get total number of terms in this field.</summary>
- /// <value> the length </value>
- public int Length
- {
- get { return length; }
- }
+ /// <summary> Get total number of terms in this field.</summary>
+ /// <value> the length </value>
+ public int Length
+ {
+ get { return length; }
+ }
- /// <summary> Get the number of terms with <c>positionIncrement == 0</c>.</summary>
- /// <value> the numOverlap </value>
- public int NumOverlap
- {
- get { return numOverlap; }
- }
+ /// <summary> Get the number of terms with <c>positionIncrement == 0</c>.</summary>
+ /// <value> the numOverlap </value>
+ public int NumOverlap
+ {
+ get { return numOverlap; }
+ }
- /// <summary> Get end offset of the last processed term.</summary>
- /// <value> the offset </value>
- public int Offset
- {
- get { return offset; }
- }
+ /// <summary> Get end offset of the last processed term.</summary>
+ /// <value> the offset </value>
+ public int Offset
+ {
+ get { return offset; }
+ }
- /// <summary> Get boost value. This is the cumulative product of
- /// document boost and field boost for all field instances
- /// sharing the same field name.
- /// </summary>
- /// <value> the boost </value>
- public float Boost
- {
- get { return boost; }
- }
+ /// <summary> Get boost value. This is the cumulative product of
+ /// document boost and field boost for all field instances
+ /// sharing the same field name.
+ /// </summary>
+ /// <value> the boost </value>
+ public float Boost
+ {
+ get { return boost; }
+ }
- public AttributeSource AttributeSource
- {
- get { return attributeSource; }
- }
- }
+ public AttributeSource AttributeSource
+ {
+ get { return attributeSource; }
+ }
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/62f018ab/src/core/Index/FieldSortedTermVectorMapper.cs
----------------------------------------------------------------------
diff --git a/src/core/Index/FieldSortedTermVectorMapper.cs b/src/core/Index/FieldSortedTermVectorMapper.cs
index 6c1915e..4d193f5 100644
--- a/src/core/Index/FieldSortedTermVectorMapper.cs
+++ b/src/core/Index/FieldSortedTermVectorMapper.cs
@@ -20,59 +20,59 @@ using Lucene.Net.Support;
namespace Lucene.Net.Index
{
-
- /// <summary> For each Field, store a sorted collection of <see cref="TermVectorEntry" />s
- /// <p/>
- /// This is not thread-safe.
- /// </summary>
- public class FieldSortedTermVectorMapper:TermVectorMapper
- {
+
+ /// <summary> For each Field, store a sorted collection of <see cref="TermVectorEntry" />s
+ /// <p/>
+ /// This is not thread-safe.
+ /// </summary>
+ public class FieldSortedTermVectorMapper:TermVectorMapper
+ {
private readonly IDictionary<string, SortedSet<TermVectorEntry>> fieldToTerms = new HashMap<string, SortedSet<TermVectorEntry>>();
- private SortedSet<TermVectorEntry> currentSet;
- private System.String currentField;
+ private SortedSet<TermVectorEntry> currentSet;
+ private System.String currentField;
private readonly IComparer<TermVectorEntry> comparator;
-
- /// <summary> </summary>
- /// <param name="comparator">A Comparator for sorting <see cref="TermVectorEntry" />s
- /// </param>
+
+ /// <summary> </summary>
+ /// <param name="comparator">A Comparator for sorting <see cref="TermVectorEntry" />s
+ /// </param>
public FieldSortedTermVectorMapper(IComparer<TermVectorEntry> comparator)
: this(false, false, comparator)
- {
- }
+ {
+ }
public FieldSortedTermVectorMapper(bool ignoringPositions, bool ignoringOffsets, IComparer<TermVectorEntry> comparator)
: base(ignoringPositions, ignoringOffsets)
- {
- this.comparator = comparator;
- }
-
- public override void Map(System.String term, int frequency, TermVectorOffsetInfo[] offsets, int[] positions)
- {
- var entry = new TermVectorEntry(currentField, term, frequency, offsets, positions);
- currentSet.Add(entry);
- }
-
- public override void SetExpectations(System.String field, int numTerms, bool storeOffsets, bool storePositions)
- {
- currentSet = new SortedSet<TermVectorEntry>(comparator);
- currentField = field;
- fieldToTerms[field] = currentSet;
- }
+ {
+ this.comparator = comparator;
+ }
+
+ public override void Map(System.String term, int frequency, TermVectorOffsetInfo[] offsets, int[] positions)
+ {
+ var entry = new TermVectorEntry(currentField, term, frequency, offsets, positions);
+ currentSet.Add(entry);
+ }
+
+ public override void SetExpectations(System.String field, int numTerms, bool storeOffsets, bool storePositions)
+ {
+ currentSet = new SortedSet<TermVectorEntry>(comparator);
+ currentField = field;
+ fieldToTerms[field] = currentSet;
+ }
- /// <summary> Get the mapping between fields and terms, sorted by the comparator
- ///
- /// </summary>
- /// <value> A map between field names and <see cref="System.Collections.Generic.SortedDictionary{Object,Object}" />s per field. SortedSet entries are <see cref="TermVectorEntry" /> </value>
- public virtual IDictionary<string, SortedSet<TermVectorEntry>> FieldToTerms
- {
- get { return fieldToTerms; }
- }
+ /// <summary> Get the mapping between fields and terms, sorted by the comparator
+ ///
+ /// </summary>
+ /// <value> A map between field names and <see cref="System.Collections.Generic.SortedDictionary{Object,Object}" />s per field. SortedSet entries are <see cref="TermVectorEntry" /> </value>
+ public virtual IDictionary<string, SortedSet<TermVectorEntry>> FieldToTerms
+ {
+ get { return fieldToTerms; }
+ }
- public virtual IComparer<TermVectorEntry> Comparator
- {
- get { return comparator; }
- }
- }
+ public virtual IComparer<TermVectorEntry> Comparator
+ {
+ get { return comparator; }
+ }
+ }
}
\ No newline at end of file