You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ar...@apache.org on 2007/05/01 20:45:35 UTC
svn commit: r534192 [10/19] - in /incubator/lucene.net/trunk/C#: ./ src/
src/Demo/ src/Demo/DeleteFiles/ src/Demo/DemoLib/ src/Demo/DemoLib/HTML/
src/Demo/IndexFiles/ src/Demo/IndexHtml/ src/Demo/SearchFiles/
src/Lucene.Net/ src/Lucene.Net/Analysis/ sr...
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/SegmentReader.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentReader.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentReader.cs Tue May 1 11:45:26 2007
@@ -17,7 +17,7 @@
using System;
using Document = Lucene.Net.Documents.Document;
-using Field = Lucene.Net.Documents.Field;
+using FieldSelector = Lucene.Net.Documents.FieldSelector;
using DefaultSimilarity = Lucene.Net.Search.DefaultSimilarity;
using Directory = Lucene.Net.Store.Directory;
using IndexInput = Lucene.Net.Store.IndexInput;
@@ -27,597 +27,708 @@
namespace Lucene.Net.Index
{
- /// <version> $Id: SegmentReader.java 329523 2005-10-30 05:37:11Z yonik $
- /// </version>
- public class SegmentReader : IndexReader
- {
- private System.String segment;
-
- internal FieldInfos fieldInfos;
- private FieldsReader fieldsReader;
-
- internal TermInfosReader tis;
- internal TermVectorsReader termVectorsReaderOrig = null;
- internal System.LocalDataStoreSlot termVectorsLocal = System.Threading.Thread.AllocateDataSlot();
-
- internal BitVector deletedDocs = null;
- private bool deletedDocsDirty = false;
- private bool normsDirty = false;
- private bool undeleteAll = false;
-
- internal IndexInput freqStream;
- internal IndexInput proxStream;
-
- // Compound File Reader when based on a compound file segment
- internal CompoundFileReader cfsReader = null;
-
- public FieldInfos FieldInfos
- {
- get { return fieldInfos; }
- }
+ /// <version> $Id: SegmentReader.java 496851 2007-01-16 20:24:52Z mikemccand $
+ /// </version>
+ public class SegmentReader : IndexReader
+ {
+ private System.String segment;
+ private SegmentInfo si;
+
+ internal FieldInfos fieldInfos;
+ private FieldsReader fieldsReader;
+
+ internal TermInfosReader tis;
+ internal TermVectorsReader termVectorsReaderOrig = null;
+ internal System.LocalDataStoreSlot termVectorsLocal = System.Threading.Thread.AllocateDataSlot();
+
+ internal BitVector deletedDocs = null;
+ private bool deletedDocsDirty = false;
+ private bool normsDirty = false;
+ private bool undeleteAll = false;
+
+ private bool rollbackDeletedDocsDirty = false;
+ private bool rollbackNormsDirty = false;
+ private bool rollbackUndeleteAll = false;
+
+ internal IndexInput freqStream;
+ internal IndexInput proxStream;
+
+ // Compound File Reader when based on a compound file segment
+ internal CompoundFileReader cfsReader = null;
+
+ public FieldInfos FieldInfos
+ {
+ get { return fieldInfos; }
+ }
- private class Norm
- {
- private void InitBlock(SegmentReader enclosingInstance)
- {
- this.enclosingInstance = enclosingInstance;
- }
- private SegmentReader enclosingInstance;
- public SegmentReader Enclosing_Instance
- {
- get
- {
- return enclosingInstance;
- }
+ private class Norm
+ {
+ private void InitBlock(SegmentReader enclosingInstance)
+ {
+ this.enclosingInstance = enclosingInstance;
+ }
+ private SegmentReader enclosingInstance;
+ public SegmentReader Enclosing_Instance
+ {
+ get
+ {
+ return enclosingInstance;
+ }
- }
- public Norm(SegmentReader enclosingInstance, IndexInput in_Renamed, int number)
- {
- InitBlock(enclosingInstance);
- this.in_Renamed = in_Renamed;
- this.number = number;
- }
-
- public IndexInput in_Renamed;
- public byte[] bytes;
- public bool dirty;
- public int number;
-
- public void ReWrite()
- {
- // NOTE: norms are re-written in regular directory, not cfs
- IndexOutput out_Renamed = Enclosing_Instance.Directory().CreateOutput(Enclosing_Instance.segment + ".tmp");
- try
- {
- out_Renamed.WriteBytes(bytes, Enclosing_Instance.MaxDoc());
- }
- finally
- {
- out_Renamed.Close();
- }
- System.String fileName;
- if (Enclosing_Instance.cfsReader == null)
- fileName = Enclosing_Instance.segment + ".f" + number;
- else
- {
- // use a different file name if we have compound format
- fileName = Enclosing_Instance.segment + ".s" + number;
- }
- Enclosing_Instance.Directory().RenameFile(Enclosing_Instance.segment + ".tmp", fileName);
- this.dirty = false;
- }
- }
-
- private System.Collections.Hashtable norms = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable());
-
- /// <summary>The class which implements SegmentReader. </summary>
- private static System.Type IMPL;
-
- public SegmentReader() : base(null)
- {
- }
-
- public static SegmentReader Get(SegmentInfo si)
- {
- return Get(si.dir, si, null, false, false);
- }
-
- public static SegmentReader Get(SegmentInfos sis, SegmentInfo si, bool closeDir)
- {
- return Get(si.dir, si, sis, closeDir, true);
- }
-
- public static SegmentReader Get(Directory dir, SegmentInfo si, SegmentInfos sis, bool closeDir, bool ownDir)
- {
- SegmentReader instance;
- try
- {
- instance = (SegmentReader) System.Activator.CreateInstance(IMPL);
- }
- catch (System.Exception e)
- {
- throw new System.SystemException("cannot load SegmentReader class: " + e, e);
- }
- instance.Init(dir, sis, closeDir, ownDir);
- instance.Initialize(si);
- return instance;
- }
-
- private void Initialize(SegmentInfo si)
- {
- segment = si.name;
-
- // Use compound file directory for some files, if it exists
- Directory cfsDir = Directory();
- if (Directory().FileExists(segment + ".cfs"))
- {
- cfsReader = new CompoundFileReader(Directory(), segment + ".cfs");
- cfsDir = cfsReader;
- }
-
- // No compound file exists - use the multi-file format
- fieldInfos = new FieldInfos(cfsDir, segment + ".fnm");
- fieldsReader = new FieldsReader(cfsDir, segment, fieldInfos);
-
- tis = new TermInfosReader(cfsDir, segment, fieldInfos);
-
- // NOTE: the bitvector is stored using the regular directory, not cfs
- if (HasDeletions(si))
- deletedDocs = new BitVector(Directory(), segment + ".del");
-
- // make sure that all index files have been read or are kept open
- // so that if an index update removes them we'll still have them
- freqStream = cfsDir.OpenInput(segment + ".frq");
- proxStream = cfsDir.OpenInput(segment + ".prx");
- OpenNorms(cfsDir);
-
- if (fieldInfos.HasVectors())
- {
- // open term vector files only as needed
- termVectorsReaderOrig = new TermVectorsReader(cfsDir, segment, fieldInfos);
- }
- }
-
- /* Leaving this here will cause a memory leak under .NET 1.1
- ~SegmentReader()
- {
- // patch for pre-1.4.2 JVMs, whose ThreadLocals leak
- //System.Threading.Thread.SetData(termVectorsLocal, null);
- }
- */
-
- protected internal override void DoCommit()
- {
- if (deletedDocsDirty)
- {
- // re-write deleted
- deletedDocs.Write(Directory(), segment + ".tmp");
- Directory().RenameFile(segment + ".tmp", segment + ".del");
- }
- if (undeleteAll && Directory().FileExists(segment + ".del"))
- {
- Directory().DeleteFile(segment + ".del");
- }
- if (normsDirty)
- {
- // re-write norms
- System.Collections.IEnumerator values = norms.Values.GetEnumerator();
- while (values.MoveNext())
- {
- Norm norm = (Norm) values.Current;
- if (norm.dirty)
- {
- norm.ReWrite();
- }
- }
- }
- deletedDocsDirty = false;
- normsDirty = false;
- undeleteAll = false;
- }
-
- protected internal override void DoClose()
- {
- fieldsReader.Close();
- tis.Close();
-
- if (freqStream != null)
- freqStream.Close();
- if (proxStream != null)
- proxStream.Close();
-
- CloseNorms();
-
- if (termVectorsReaderOrig != null)
- termVectorsReaderOrig.Close();
-
- if (cfsReader != null)
- cfsReader.Close();
- }
-
- internal static bool HasDeletions(SegmentInfo si)
- {
- return si.dir.FileExists(si.name + ".del");
- }
-
- public override bool HasDeletions()
- {
- return deletedDocs != null;
- }
-
-
- internal static bool UsesCompoundFile(SegmentInfo si)
- {
- return si.dir.FileExists(si.name + ".cfs");
- }
-
- internal static bool HasSeparateNorms(SegmentInfo si)
- {
- System.String[] result = si.dir.List();
- System.String pattern = si.name + ".s";
- int patternLength = pattern.Length;
- for (int i = 0; i < result.Length; i++)
- {
- if (result[i].StartsWith(pattern) && System.Char.IsDigit(result[i][patternLength]))
- return true;
- }
- return false;
- }
-
- protected internal override void DoDelete(int docNum)
- {
- if (deletedDocs == null)
- deletedDocs = new BitVector(MaxDoc());
- deletedDocsDirty = true;
- undeleteAll = false;
- deletedDocs.Set(docNum);
- }
-
- protected internal override void DoUndeleteAll()
- {
- deletedDocs = null;
- deletedDocsDirty = false;
- undeleteAll = true;
- }
-
- internal virtual System.Collections.ArrayList Files()
- {
- System.Collections.ArrayList files = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(16));
-
- for (int i = 0; i < IndexFileNames.INDEX_EXTENSIONS.Length; i++)
- {
- System.String name = segment + "." + IndexFileNames.INDEX_EXTENSIONS[i];
- if (Directory().FileExists(name))
- files.Add(name);
- }
-
- for (int i = 0; i < fieldInfos.Size(); i++)
- {
- FieldInfo fi = fieldInfos.FieldInfo(i);
- if (fi.isIndexed && !fi.omitNorms)
- {
- System.String name;
- if (cfsReader == null)
- name = segment + ".f" + i;
- else
- name = segment + ".s" + i;
- if (Directory().FileExists(name))
- files.Add(name);
- }
- }
- return files;
- }
-
- public override TermEnum Terms()
- {
- return tis.Terms();
- }
-
- public override TermEnum Terms(Term t)
- {
- return tis.Terms(t);
- }
-
- public override Document Document(int n)
- {
- lock (this)
- {
- if (IsDeleted(n))
- throw new System.ArgumentException("attempt to access a deleted document");
- return fieldsReader.Doc(n);
- }
- }
-
- public override bool IsDeleted(int n)
- {
- lock (this)
- {
- return (deletedDocs != null && deletedDocs.Get(n));
- }
- }
-
- public override TermDocs TermDocs()
- {
- return new SegmentTermDocs(this);
- }
-
- public override TermPositions TermPositions()
- {
- return new SegmentTermPositions(this);
- }
-
- public override int DocFreq(Term t)
- {
- TermInfo ti = tis.Get(t);
- if (ti != null)
- return ti.docFreq;
- else
- return 0;
- }
-
- public override int NumDocs()
- {
- int n = MaxDoc();
- if (deletedDocs != null)
- n -= deletedDocs.Count();
- return n;
- }
-
- public override int MaxDoc()
- {
- return fieldsReader.Size();
- }
-
- /// <seealso cref="IndexReader.GetFieldNames(IndexReader.FieldOption fldOption)">
- /// </seealso>
- public override System.Collections.ICollection GetFieldNames(IndexReader.FieldOption fieldOption)
- {
- System.Collections.Hashtable fieldSet = new System.Collections.Hashtable();
- for (int i = 0; i < fieldInfos.Size(); i++)
- {
- FieldInfo fi = fieldInfos.FieldInfo(i);
- if (fieldOption == IndexReader.FieldOption.ALL)
- {
- fieldSet.Add(fi.name, fi.name);
- }
- else if (!fi.isIndexed && fieldOption == IndexReader.FieldOption.UNINDEXED)
- {
- fieldSet.Add(fi.name, fi.name);
- }
- else if (fi.isIndexed && fieldOption == IndexReader.FieldOption.INDEXED)
- {
- fieldSet.Add(fi.name, fi.name);
- }
- else if (fi.isIndexed && fi.storeTermVector == false && fieldOption == IndexReader.FieldOption.INDEXED_NO_TERMVECTOR)
- {
- fieldSet.Add(fi.name, fi.name);
- }
- else if (fi.storeTermVector == true && fi.storePositionWithTermVector == false && fi.storeOffsetWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR)
- {
- fieldSet.Add(fi.name, fi.name);
- }
- else if (fi.isIndexed && fi.storeTermVector && fieldOption == IndexReader.FieldOption.INDEXED_WITH_TERMVECTOR)
- {
- fieldSet.Add(fi.name, fi.name);
- }
- else if (fi.storePositionWithTermVector && fi.storeOffsetWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_POSITION)
- {
- fieldSet.Add(fi.name, fi.name);
- }
- else if (fi.storeOffsetWithTermVector && fi.storePositionWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_OFFSET)
- {
- fieldSet.Add(fi.name, fi.name);
- }
- else if ((fi.storeOffsetWithTermVector && fi.storePositionWithTermVector) && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_POSITION_OFFSET)
- {
- fieldSet.Add(fi.name, fi.name);
- }
- }
- return fieldSet;
- }
-
-
- public override bool HasNorms(System.String field)
- {
- lock (this)
- {
- return norms.ContainsKey(field);
- }
- }
-
- internal static byte[] CreateFakeNorms(int size)
- {
- byte[] ones = new byte[size];
- byte val = DefaultSimilarity.EncodeNorm(1.0f);
- for (int index = 0; index < size; index++)
- ones[index] = val;
-
- return ones;
- }
+ }
+ public Norm(SegmentReader enclosingInstance, IndexInput in_Renamed, int number, long normSeek)
+ {
+ InitBlock(enclosingInstance);
+ this.in_Renamed = in_Renamed;
+ this.number = number;
+ this.normSeek = normSeek;
+ }
+
+ internal IndexInput in_Renamed;
+ internal byte[] bytes;
+ internal bool dirty;
+ internal int number;
+ internal long normSeek;
+ internal bool rollbackDirty;
+
+ internal void ReWrite(SegmentInfo si)
+ {
+ // NOTE: norms are re-written in regular directory, not cfs
+
+ System.String oldFileName = si.GetNormFileName(this.number);
+ if (oldFileName != null && !oldFileName.EndsWith("." + IndexFileNames.NORMS_EXTENSION))
+ {
+ // Mark this file for deletion. Note that we don't
+ // actually try to delete it until the new segments files is
+ // successfully written:
+ Enclosing_Instance.deleter.AddPendingFile(oldFileName);
+ }
+
+ si.AdvanceNormGen(this.number);
+ IndexOutput out_Renamed = Enclosing_Instance.Directory().CreateOutput(si.GetNormFileName(this.number));
+ try
+ {
+ out_Renamed.WriteBytes(bytes, Enclosing_Instance.MaxDoc());
+ }
+ finally
+ {
+ out_Renamed.Close();
+ }
+ this.dirty = false;
+ }
+ }
+
+ private System.Collections.Hashtable norms = System.Collections.Hashtable.Synchronized(new System.Collections.Hashtable());
+
+ /// <summary>The class which implements SegmentReader. </summary>
+ private static System.Type IMPL;
+
+ public SegmentReader() : base(null)
+ {
+ }
+
+ public static SegmentReader Get(SegmentInfo si)
+ {
+ return Get(si.dir, si, null, false, false);
+ }
+
+ public static SegmentReader Get(SegmentInfos sis, SegmentInfo si, bool closeDir)
+ {
+ return Get(si.dir, si, sis, closeDir, true);
+ }
- private byte[] ones;
- private byte[] FakeNorms()
- {
- if (ones == null)
- ones = CreateFakeNorms(MaxDoc());
- return ones;
- }
-
- // can return null if norms aren't stored
- protected internal virtual byte[] GetNorms(System.String field)
- {
- lock (this)
- {
- Norm norm = (Norm) norms[field];
- if (norm == null)
- return null; // not indexed, or norms not stored
+ public static SegmentReader Get(Directory dir, SegmentInfo si, SegmentInfos sis, bool closeDir, bool ownDir)
+ {
+ SegmentReader instance;
+ try
+ {
+ instance = (SegmentReader) System.Activator.CreateInstance(IMPL);
+ }
+ catch (System.Exception e)
+ {
+ throw new System.SystemException("cannot load SegmentReader class: " + e, e);
+ }
+ instance.Init(dir, sis, closeDir, ownDir);
+ instance.Initialize(si);
+ return instance;
+ }
+
+ private void Initialize(SegmentInfo si)
+ {
+ segment = si.name;
+ this.si = si;
+
+ bool success = false;
+
+ try
+ {
+ // Use compound file directory for some files, if it exists
+ Directory cfsDir = Directory();
+ if (si.GetUseCompoundFile())
+ {
+ cfsReader = new CompoundFileReader(Directory(), segment + ".cfs");
+ cfsDir = cfsReader;
+ }
- if (norm.bytes == null)
- {
- // value not yet read
- byte[] bytes = new byte[MaxDoc()];
- Norms(field, bytes, 0);
- norm.bytes = bytes; // cache it
- }
- return norm.bytes;
- }
- }
-
- // returns fake norms if norms aren't available
- public override byte[] Norms(System.String field)
- {
- lock (this)
- {
- byte[] bytes = GetNorms(field);
- if (bytes == null)
- bytes = FakeNorms();
- return bytes;
- }
- }
-
- protected internal override void DoSetNorm(int doc, System.String field, byte value_Renamed)
- {
- Norm norm = (Norm) norms[field];
- if (norm == null)
- // not an indexed field
- return ;
- norm.dirty = true; // mark it dirty
- normsDirty = true;
-
- Norms(field)[doc] = value_Renamed; // set the value
- }
-
- /// <summary>Read norms into a pre-allocated array. </summary>
- public override void Norms(System.String field, byte[] bytes, int offset)
- {
- lock (this)
- {
+ // No compound file exists - use the multi-file format
+ fieldInfos = new FieldInfos(cfsDir, segment + ".fnm");
+ fieldsReader = new FieldsReader(cfsDir, segment, fieldInfos);
- Norm norm = (Norm) norms[field];
- if (norm == null)
- {
- Array.Copy(FakeNorms(), 0, bytes, offset, MaxDoc());
- return ;
- }
+ // Verify two sources of "maxDoc" agree:
+ if (fieldsReader.Size() != si.docCount)
+ {
+ throw new System.SystemException("doc counts differ for segment " + si.name + ": fieldsReader shows " + fieldsReader.Size() + " but segmentInfo shows " + si.docCount);
+ }
- if (norm.bytes != null)
- {
- // can copy from cache
- Array.Copy(norm.bytes, 0, bytes, offset, MaxDoc());
- return ;
- }
+ tis = new TermInfosReader(cfsDir, segment, fieldInfos);
- IndexInput normStream = (IndexInput) norm.in_Renamed.Clone();
- try
- {
- // read from disk
- normStream.Seek(0);
- normStream.ReadBytes(bytes, offset, MaxDoc());
- }
- finally
- {
- normStream.Close();
- }
- }
- }
+ // NOTE: the bitvector is stored using the regular directory, not cfs
+ if (HasDeletions(si))
+ {
+ deletedDocs = new BitVector(Directory(), si.GetDelFileName());
+
+ // Verify # deletes does not exceed maxDoc for this segment:
+ if (deletedDocs.Count() > MaxDoc())
+ {
+ throw new System.SystemException("number of deletes (" + deletedDocs.Count() + ") exceeds max doc (" + MaxDoc() + ") for segment " + si.name);
+ }
+ }
+
+ // make sure that all index files have been read or are kept open
+ // so that if an index update removes them we'll still have them
+ freqStream = cfsDir.OpenInput(segment + ".frq");
+ proxStream = cfsDir.OpenInput(segment + ".prx");
+ OpenNorms(cfsDir);
+
+ if (fieldInfos.HasVectors())
+ {
+ // open term vector files only as needed
+ termVectorsReaderOrig = new TermVectorsReader(cfsDir, segment, fieldInfos);
+ }
+ success = true;
+ }
+ finally
+ {
+
+ // With lock-less commits, it's entirely possible (and
+ // fine) to hit a FileNotFound exception above. In
+ // this case, we want to explicitly close any subset
+ // of things that were opened so that we don't have to
+ // wait for a GC to do so.
+ if (!success)
+ {
+ DoClose();
+ }
+ }
+ }
+ protected internal override void DoCommit()
+ {
+ if (deletedDocsDirty)
+ {
+ // re-write deleted
+ System.String oldDelFileName = si.GetDelFileName();
+ if (oldDelFileName != null)
+ {
+ // Mark this file for deletion. Note that we don't
+ // actually try to delete it until the new segments files is
+ // successfully written:
+ deleter.AddPendingFile(oldDelFileName);
+ }
+
+ si.AdvanceDelGen();
+
+ // We can write directly to the actual name (vs to a
+ // .tmp & renaming it) because the file is not live
+ // until segments file is written:
+ deletedDocs.Write(Directory(), si.GetDelFileName());
+ }
+ if (undeleteAll && si.HasDeletions())
+ {
+ System.String oldDelFileName = si.GetDelFileName();
+ if (oldDelFileName != null)
+ {
+ // Mark this file for deletion. Note that we don't
+ // actually try to delete it until the new segments files is
+ // successfully written:
+ deleter.AddPendingFile(oldDelFileName);
+ }
+ si.ClearDelGen();
+ }
+ if (normsDirty)
+ {
+ // re-write norms
+ si.SetNumFields(fieldInfos.Size());
+ System.Collections.IEnumerator values = norms.Values.GetEnumerator();
+ while (values.MoveNext())
+ {
+ Norm norm = (Norm) values.Current;
+ if (norm.dirty)
+ {
+ norm.ReWrite(si);
+ }
+ }
+ }
+ deletedDocsDirty = false;
+ normsDirty = false;
+ undeleteAll = false;
+ }
- private void OpenNorms(Directory cfsDir)
- {
- for (int i = 0; i < fieldInfos.Size(); i++)
- {
- FieldInfo fi = fieldInfos.FieldInfo(i);
- if (fi.isIndexed && !fi.omitNorms)
- {
- // look first if there are separate norms in compound format
- System.String fileName = segment + ".s" + fi.number;
- Directory d = Directory();
- if (!d.FileExists(fileName))
- {
- fileName = segment + ".f" + fi.number;
- d = cfsDir;
- }
- norms[fi.name] = new Norm(this, d.OpenInput(fileName), fi.number);
- }
- }
- }
+ protected internal override void DoClose()
+ {
+ if (fieldsReader != null)
+ {
+ fieldsReader.Close();
+ }
+ if (tis != null)
+ {
+ tis.Close();
+ }
+
+ if (freqStream != null)
+ freqStream.Close();
+ if (proxStream != null)
+ proxStream.Close();
+
+ CloseNorms();
+
+ if (termVectorsReaderOrig != null)
+ termVectorsReaderOrig.Close();
+
+ if (cfsReader != null)
+ cfsReader.Close();
+ }
- private void CloseNorms()
- {
- lock (norms.SyncRoot)
- {
- System.Collections.IEnumerator enumerator = norms.Values.GetEnumerator();
- while (enumerator.MoveNext())
- {
- Norm norm = (Norm) enumerator.Current;
- norm.in_Renamed.Close();
- }
- }
- }
+ internal static bool HasDeletions(SegmentInfo si)
+ {
+ return si.HasDeletions();
+ }
+
+ public override bool HasDeletions()
+ {
+ return deletedDocs != null;
+ }
+
+ internal static bool UsesCompoundFile(SegmentInfo si)
+ {
+ return si.GetUseCompoundFile();
+ }
+
+ internal static bool HasSeparateNorms(SegmentInfo si)
+ {
+ return si.HasSeparateNorms();
+ }
+
+ protected internal override void DoDelete(int docNum)
+ {
+ if (deletedDocs == null)
+ deletedDocs = new BitVector(MaxDoc());
+ deletedDocsDirty = true;
+ undeleteAll = false;
+ deletedDocs.Set(docNum);
+ }
- /// <summary> Create a clone from the initial TermVectorsReader and store it in the ThreadLocal.</summary>
- /// <returns> TermVectorsReader
- /// </returns>
- private TermVectorsReader GetTermVectorsReader()
- {
- TermVectorsReader tvReader = (TermVectorsReader) System.Threading.Thread.GetData(termVectorsLocal);
- if (tvReader == null)
- {
- tvReader = (TermVectorsReader) termVectorsReaderOrig.Clone();
- System.Threading.Thread.SetData(termVectorsLocal, tvReader);
- }
- return tvReader;
- }
-
- /// <summary>Return a term frequency vector for the specified document and field. The
- /// vector returned contains term numbers and frequencies for all terms in
- /// the specified field of this document, if the field had storeTermVector
- /// flag set. If the flag was not set, the method returns null.
- /// </summary>
- /// <throws> IOException </throws>
- public override TermFreqVector GetTermFreqVector(int docNumber, System.String field)
- {
- // Check if this field is invalid or has no stored term vector
- FieldInfo fi = fieldInfos.FieldInfo(field);
- if (fi == null || !fi.storeTermVector || termVectorsReaderOrig == null)
- return null;
-
- TermVectorsReader termVectorsReader = GetTermVectorsReader();
- if (termVectorsReader == null)
- return null;
-
- return termVectorsReader.Get(docNumber, field);
- }
-
-
- /// <summary>Return an array of term frequency vectors for the specified document.
- /// The array contains a vector for each vectorized field in the document.
- /// Each vector vector contains term numbers and frequencies for all terms
- /// in a given vectorized field.
- /// If no such fields existed, the method returns null.
- /// </summary>
- /// <throws> IOException </throws>
- public override TermFreqVector[] GetTermFreqVectors(int docNumber)
- {
- if (termVectorsReaderOrig == null)
- return null;
-
- TermVectorsReader termVectorsReader = GetTermVectorsReader();
- if (termVectorsReader == null)
- return null;
+ protected internal override void DoUndeleteAll()
+ {
+ deletedDocs = null;
+ deletedDocsDirty = false;
+ undeleteAll = true;
+ }
+
+ internal virtual System.Collections.ArrayList Files()
+ {
+ System.Collections.ArrayList files = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(16));
- return termVectorsReader.Get(docNumber);
- }
-
- static SegmentReader()
- {
- {
- try
- {
- System.String name = SupportClass.AppSettings.Get("Lucene.Net.SegmentReader.class", typeof(SegmentReader).FullName);
- IMPL = System.Type.GetType(name);
- }
- catch (System.Security.SecurityException)
+ if (si.GetUseCompoundFile())
+ {
+ System.String name = segment + ".cfs";
+ if (Directory().FileExists(name))
+ {
+ files.Add(name);
+ }
+ }
+ else
+ {
+ for (int i = 0; i < IndexFileNames.INDEX_EXTENSIONS.Length; i++)
+ {
+ System.String name = segment + "." + IndexFileNames.INDEX_EXTENSIONS[i];
+ if (Directory().FileExists(name))
+ files.Add(name);
+ }
+ }
+
+ if (si.HasDeletions())
+ {
+ files.Add(si.GetDelFileName());
+ }
+
+ bool addedNrm = false;
+ for (int i = 0; i < fieldInfos.Size(); i++)
+ {
+ System.String name = si.GetNormFileName(i);
+ if (name != null && Directory().FileExists(name))
+ {
+ if (name.EndsWith("." + IndexFileNames.NORMS_EXTENSION))
+ {
+ if (addedNrm)
+ continue; // add .nrm just once
+ addedNrm = true;
+ }
+ files.Add(name);
+ }
+ }
+ return files;
+ }
+
+ public override TermEnum Terms()
+ {
+ return tis.Terms();
+ }
+
+ public override TermEnum Terms(Term t)
+ {
+ return tis.Terms(t);
+ }
+
+ public override Document Document(int n, FieldSelector fieldSelector)
+ {
+ lock (this)
+ {
+ if (IsDeleted(n))
+ throw new System.ArgumentException("attempt to access a deleted document");
+ return fieldsReader.Doc(n, fieldSelector);
+ }
+ }
+
+ public override bool IsDeleted(int n)
+ {
+ lock (this)
+ {
+ return (deletedDocs != null && deletedDocs.Get(n));
+ }
+ }
+
+ public override TermDocs TermDocs()
+ {
+ return new SegmentTermDocs(this);
+ }
+
+ public override TermPositions TermPositions()
+ {
+ return new SegmentTermPositions(this);
+ }
+
+ public override int DocFreq(Term t)
+ {
+ TermInfo ti = tis.Get(t);
+ if (ti != null)
+ return ti.docFreq;
+ else
+ return 0;
+ }
+
+ public override int NumDocs()
+ {
+ int n = MaxDoc();
+ if (deletedDocs != null)
+ n -= deletedDocs.Count();
+ return n;
+ }
+
+ public override int MaxDoc()
+ {
+ return si.docCount;
+ }
+
+ /// <seealso cref="fldOption)">
+ /// </seealso>
+ public override System.Collections.ICollection GetFieldNames(IndexReader.FieldOption fieldOption)
+ {
+
+ System.Collections.Hashtable fieldSet = new System.Collections.Hashtable();
+ for (int i = 0; i < fieldInfos.Size(); i++)
+ {
+ FieldInfo fi = fieldInfos.FieldInfo(i);
+ if (fieldOption == IndexReader.FieldOption.ALL)
+ {
+ fieldSet.Add(fi.name, fi.name);
+ }
+ else if (!fi.isIndexed && fieldOption == IndexReader.FieldOption.UNINDEXED)
+ {
+ fieldSet.Add(fi.name, fi.name);
+ }
+ else if (fi.isIndexed && fieldOption == IndexReader.FieldOption.INDEXED)
+ {
+ fieldSet.Add(fi.name, fi.name);
+ }
+ else if (fi.isIndexed && fi.storeTermVector == false && fieldOption == IndexReader.FieldOption.INDEXED_NO_TERMVECTOR)
+ {
+ fieldSet.Add(fi.name, fi.name);
+ }
+ else if (fi.storeTermVector == true && fi.storePositionWithTermVector == false && fi.storeOffsetWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR)
+ {
+ fieldSet.Add(fi.name, fi.name);
+ }
+ else if (fi.isIndexed && fi.storeTermVector && fieldOption == IndexReader.FieldOption.INDEXED_WITH_TERMVECTOR)
+ {
+ fieldSet.Add(fi.name, fi.name);
+ }
+ else if (fi.storePositionWithTermVector && fi.storeOffsetWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_POSITION)
+ {
+ fieldSet.Add(fi.name, fi.name);
+ }
+ else if (fi.storeOffsetWithTermVector && fi.storePositionWithTermVector == false && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_OFFSET)
+ {
+ fieldSet.Add(fi.name, fi.name);
+ }
+ else if ((fi.storeOffsetWithTermVector && fi.storePositionWithTermVector) && fieldOption == IndexReader.FieldOption.TERMVECTOR_WITH_POSITION_OFFSET)
+ {
+ fieldSet.Add(fi.name, fi.name);
+ }
+ }
+ return fieldSet;
+ }
+
+
+ public override bool HasNorms(System.String field)
+ {
+ lock (this)
+ {
+ return norms.ContainsKey(field);
+ }
+ }
+
+ internal static byte[] CreateFakeNorms(int size)
+ {
+ byte[] ones = new byte[size];
+ byte val = DefaultSimilarity.EncodeNorm(1.0f);
+ for (int index = 0; index < size; index++)
+ ones[index] = val;
+ return ones;
+ }
+
+ private byte[] ones;
+ private byte[] FakeNorms()
+ {
+ if (ones == null)
+ ones = CreateFakeNorms(MaxDoc());
+ return ones;
+ }
+
+ // can return null if norms aren't stored
+ protected internal virtual byte[] GetNorms(System.String field)
+ {
+ lock (this)
+ {
+ Norm norm = (Norm) norms[field];
+ if (norm == null)
+ return null; // not indexed, or norms not stored
+ if (norm.bytes == null)
+ {
+ // value not yet read
+ byte[] bytes = new byte[MaxDoc()];
+ Norms(field, bytes, 0);
+ norm.bytes = bytes; // cache it
+ }
+ return norm.bytes;
+ }
+ }
+
+ // returns fake norms if norms aren't available
+ public override byte[] Norms(System.String field)
+ {
+ lock (this)
+ {
+ byte[] bytes = GetNorms(field);
+ if (bytes == null)
+ bytes = FakeNorms();
+ return bytes;
+ }
+ }
+
+ protected internal override void DoSetNorm(int doc, System.String field, byte value_Renamed)
+ {
+ Norm norm = (Norm) norms[field];
+ if (norm == null)
+ // not an indexed field
+ return ;
+ norm.dirty = true; // mark it dirty
+ normsDirty = true;
+
+ Norms(field)[doc] = value_Renamed; // set the value
+ }
+
+ /// <summary>Read norms into a pre-allocated array. </summary>
+ public override void Norms(System.String field, byte[] bytes, int offset)
+ {
+ lock (this)
+ {
+
+ Norm norm = (Norm) norms[field];
+ if (norm == null)
+ {
+ Array.Copy(FakeNorms(), 0, bytes, offset, MaxDoc());
+ return ;
+ }
+
+ if (norm.bytes != null)
+ {
+ // can copy from cache
+ Array.Copy(norm.bytes, 0, bytes, offset, MaxDoc());
+ return ;
+ }
+
+ IndexInput normStream = (IndexInput) norm.in_Renamed.Clone();
+ try
+ {
+ // read from disk
+ normStream.Seek(norm.normSeek);
+ normStream.ReadBytes(bytes, offset, MaxDoc());
+ }
+ finally
+ {
+ normStream.Close();
+ }
+ }
+ }
+
+
+ private void OpenNorms(Directory cfsDir)
+ {
+ long nextNormSeek = SegmentMerger.NORMS_HEADER.Length; //skip header (header unused for now)
+ int maxDoc = MaxDoc();
+ for (int i = 0; i < fieldInfos.Size(); i++)
+ {
+ FieldInfo fi = fieldInfos.FieldInfo(i);
+ if (fi.isIndexed && !fi.omitNorms)
+ {
+ Directory d = Directory();
+ System.String fileName = si.GetNormFileName(fi.number);
+ if (!si.HasSeparateNorms(fi.number))
+ {
+ d = cfsDir;
+ }
+ long normSeek = (fileName.EndsWith("." + IndexFileNames.NORMS_EXTENSION)?nextNormSeek:0);
+ norms[fi.name] = new Norm(this, d.OpenInput(fileName), fi.number, normSeek);
+ nextNormSeek += maxDoc; // increment also if some norms are separate
+ }
+ }
+ }
+
+ private void CloseNorms()
+ {
+ lock (norms.SyncRoot)
+ {
+ System.Collections.IEnumerator enumerator = norms.Values.GetEnumerator();
+ while (enumerator.MoveNext())
+ {
+ Norm norm = (Norm) enumerator.Current;
+ norm.in_Renamed.Close();
+ }
+ }
+ }
+
+ /// <summary> Create a clone from the initial TermVectorsReader and store it in the ThreadLocal.</summary>
+ /// <returns> TermVectorsReader
+ /// </returns>
+ private TermVectorsReader GetTermVectorsReader()
+ {
+ TermVectorsReader tvReader = (TermVectorsReader) System.Threading.Thread.GetData(termVectorsLocal);
+ if (tvReader == null)
+ {
+ tvReader = (TermVectorsReader) termVectorsReaderOrig.Clone();
+ System.Threading.Thread.SetData(termVectorsLocal, tvReader);
+ }
+ return tvReader;
+ }
+
+ /// <summary>Return a term frequency vector for the specified document and field. The
+ /// vector returned contains term numbers and frequencies for all terms in
+ /// the specified field of this document, if the field had storeTermVector
+ /// flag set. If the flag was not set, the method returns null.
+ /// </summary>
+ /// <throws> IOException </throws>
+ public override TermFreqVector GetTermFreqVector(int docNumber, System.String field)
+ {
+ // Check if this field is invalid or has no stored term vector
+ FieldInfo fi = fieldInfos.FieldInfo(field);
+ if (fi == null || !fi.storeTermVector || termVectorsReaderOrig == null)
+ return null;
+
+ TermVectorsReader termVectorsReader = GetTermVectorsReader();
+ if (termVectorsReader == null)
+ return null;
+
+ return termVectorsReader.Get(docNumber, field);
+ }
+
+
+ /// <summary>Return an array of term frequency vectors for the specified document.
+ /// The array contains a vector for each vectorized field in the document.
+ /// Each vector vector contains term numbers and frequencies for all terms
+ /// in a given vectorized field.
+ /// If no such fields existed, the method returns null.
+ /// </summary>
+ /// <throws> IOException </throws>
+ public override TermFreqVector[] GetTermFreqVectors(int docNumber)
+ {
+ if (termVectorsReaderOrig == null)
+ return null;
+
+ TermVectorsReader termVectorsReader = GetTermVectorsReader();
+ if (termVectorsReader == null)
+ return null;
+
+ return termVectorsReader.Get(docNumber);
+ }
+
+ /// <summary> Return the name of the segment this reader is reading.</summary>
+ internal virtual System.String GetSegmentName()
+ {
+ return segment;
+ }
+
+ internal virtual void SetSegmentInfo(SegmentInfo info)
+ {
+ si = info;
+ }
+
+ internal override void StartCommit()
+ {
+ base.StartCommit();
+ rollbackDeletedDocsDirty = deletedDocsDirty;
+ rollbackNormsDirty = normsDirty;
+ rollbackUndeleteAll = undeleteAll;
+ System.Collections.IEnumerator values = norms.Values.GetEnumerator();
+ while (values.MoveNext())
+ {
+ Norm norm = (Norm) values.Current;
+ norm.rollbackDirty = norm.dirty;
+ }
+ }
+
+ internal override void RollbackCommit()
+ {
+ base.RollbackCommit();
+ deletedDocsDirty = rollbackDeletedDocsDirty;
+ normsDirty = rollbackNormsDirty;
+ undeleteAll = rollbackUndeleteAll;
+ System.Collections.IEnumerator values = norms.Values.GetEnumerator();
+ while (values.MoveNext())
+ {
+ Norm norm = (Norm) values.Current;
+ norm.dirty = norm.rollbackDirty;
+ }
+ }
+ static SegmentReader()
+ {
+ {
+ try
+ {
+ System.String name = SupportClass.AppSettings.Get("Lucene.Net.SegmentReader.class", typeof(SegmentReader).FullName);
+ IMPL = System.Type.GetType(name);
+ }
+ catch (System.Security.SecurityException se)
{
try
{
@@ -629,10 +740,10 @@
}
}
catch (System.Exception e)
- {
- throw new System.SystemException("cannot load SegmentReader class: " + e, e);
- }
- }
- }
- }
+ {
+ throw new System.SystemException("cannot load SegmentReader class: " + e, e);
+ }
+ }
+ }
+ }
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentTermDocs.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/SegmentTermDocs.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentTermDocs.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentTermDocs.cs Tue May 1 11:45:26 2007
@@ -16,8 +16,8 @@
*/
using System;
-using IndexInput = Lucene.Net.Store.IndexInput;
using BitVector = Lucene.Net.Util.BitVector;
+using IndexInput = Lucene.Net.Store.IndexInput;
namespace Lucene.Net.Index
{
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentTermPositionVector.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/SegmentTermPositionVector.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentTermPositionVector.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentTermPositionVector.cs Tue May 1 11:45:26 2007
@@ -26,7 +26,7 @@
protected internal TermVectorOffsetInfo[][] offsets;
public static readonly int[] EMPTY_TERM_POS = new int[0];
- public SegmentTermPositionVector(System.String field, System.String[] terms, int[] termFreqs, int[][] positions, TermVectorOffsetInfo[][] offsets):base(field, terms, termFreqs)
+ public SegmentTermPositionVector(System.String field, System.String[] terms, int[] termFreqs, int[][] positions, TermVectorOffsetInfo[][] offsets) : base(field, terms, termFreqs)
{
this.offsets = offsets;
this.positions = positions;
@@ -39,7 +39,7 @@
/// </param>
/// <returns> An array of TermVectorOffsetInfo objects or the empty list
/// </returns>
- /// <seealso cref="Lucene.Net.analysis.Token">
+ /// <seealso cref="Lucene.Net.Analysis.Token">
/// </seealso>
public virtual TermVectorOffsetInfo[] GetOffsets(int index)
{
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentTermPositions.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/SegmentTermPositions.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentTermPositions.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentTermPositions.cs Tue May 1 11:45:26 2007
@@ -1,23 +1,20 @@
-/*
- * 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.
- */
-
+/// <summary> 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.
+/// </summary>
using System;
using IndexInput = Lucene.Net.Store.IndexInput;
-
namespace Lucene.Net.Index
{
@@ -27,6 +24,11 @@
private int proxCount;
private int position;
+ // these variables are being used to remember information
+ // for a lazy skip
+ private long lazySkipPointer = 0;
+ private int lazySkipDocCount = 0;
+
internal SegmentTermPositions(SegmentReader p) : base(p)
{
this.proxStream = (IndexInput) parent.proxStream.Clone();
@@ -36,7 +38,9 @@
{
base.Seek(ti);
if (ti != null)
- proxStream.Seek(ti.proxPointer);
+ lazySkipPointer = ti.proxPointer;
+
+ lazySkipDocCount = 0;
proxCount = 0;
}
@@ -48,22 +52,23 @@
public int NextPosition()
{
+ // perform lazy skips if neccessary
+ LazySkip();
proxCount--;
return position += proxStream.ReadVInt();
}
protected internal override void SkippingDoc()
{
- for (int f = freq; f > 0; f--)
- // skip all positions
- proxStream.ReadVInt();
+ // we remember to skip the remaining positions of the current
+ // document lazily
+ lazySkipDocCount += freq;
}
public override bool Next()
{
- for (int f = proxCount; f > 0; f--)
- // skip unread positions
- proxStream.ReadVInt();
+ // we remember to skip a document lazily
+ lazySkipDocCount += proxCount;
if (base.Next())
{
@@ -84,8 +89,42 @@
/// <summary>Called by super.skipTo(). </summary>
protected internal override void SkipProx(long proxPointer)
{
- proxStream.Seek(proxPointer);
+ // we save the pointer, we might have to skip there lazily
+ lazySkipPointer = proxPointer;
+ lazySkipDocCount = 0;
proxCount = 0;
+ }
+
+ private void SkipPositions(int n)
+ {
+ for (int f = n; f > 0; f--)
+ // skip unread positions
+ proxStream.ReadVInt();
+ }
+
+ // It is not always neccessary to move the prox pointer
+ // to a new document after the freq pointer has been moved.
+ // Consider for example a phrase query with two terms:
+ // the freq pointer for term 1 has to move to document x
+ // to answer the question if the term occurs in that document. But
+ // only if term 2 also matches document x, the positions have to be
+ // read to figure out if term 1 and term 2 appear next
+ // to each other in document x and thus satisfy the query.
+ // So we move the prox pointer lazily to the document
+ // as soon as positions are requested.
+ private void LazySkip()
+ {
+ if (lazySkipPointer != 0)
+ {
+ proxStream.Seek(lazySkipPointer);
+ lazySkipPointer = 0;
+ }
+
+ if (lazySkipDocCount != 0)
+ {
+ SkipPositions(lazySkipDocCount);
+ lazySkipDocCount = 0;
+ }
}
}
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentTermVector.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/SegmentTermVector.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentTermVector.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/SegmentTermVector.cs Tue May 1 11:45:26 2007
@@ -81,7 +81,7 @@
if (terms == null)
return - 1;
int res = System.Array.BinarySearch(terms, termText);
- return res >= 0?res:- 1;
+ return res >= 0 ? res : - 1;
}
public virtual int[] IndexesOf(System.String[] termNumbers, int start, int len)
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/Term.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/Term.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/Term.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/Term.cs Tue May 1 11:45:26 2007
@@ -31,7 +31,7 @@
public sealed class Term : System.IComparable
{
internal System.String field;
- public /*internal*/ System.String text;
+ public System.String text;
/// <summary>Constructs a Term with the given field and text. </summary>
public Term(System.String fld, System.String txt) : this(fld, txt, true)
@@ -75,7 +75,7 @@
/// <summary>Compares two terms, returning true iff they have the same
/// field and text.
/// </summary>
- public override bool Equals(System.Object o)
+ public override bool Equals(System.Object o)
{
if (o == null)
return false;
@@ -120,30 +120,14 @@
return field + ":" + text;
}
- private Term(System.Runtime.Serialization.SerializationInfo in_Renamed, System.Runtime.Serialization.StreamingContext context)
- {
- System.Type thisType = this.GetType();
- System.Reflection.MemberInfo[] mi = System.Runtime.Serialization.FormatterServices.GetSerializableMembers(thisType, context);
- for (int i = 0 ; i < mi.Length; i++)
- {
- System.Reflection.FieldInfo fi = (System.Reflection.FieldInfo) mi[i];
- fi.SetValue(this, in_Renamed.GetValue(fi.Name, fi.FieldType));
- }
- field = String.Intern(field);
- }
-
- public Term()
- {
- }
-
- public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
- {
- System.Type thisType = this.GetType();
- System.Reflection.MemberInfo[] mi = System.Runtime.Serialization.FormatterServices.GetSerializableMembers(thisType, context);
- for (int i = 0 ; i < mi.Length; i++)
- {
- info.AddValue(mi[i].Name, ((System.Reflection.FieldInfo) mi[i]).GetValue(this));
- }
- }
- }
+ public void GetObjectData(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context)
+ {
+ System.Type thisType = this.GetType();
+ System.Reflection.MemberInfo[] mi = System.Runtime.Serialization.FormatterServices.GetSerializableMembers(thisType, context);
+ for (int i = 0 ; i < mi.Length; i++)
+ {
+ info.AddValue(mi[i].Name, ((System.Reflection.FieldInfo) mi[i]).GetValue(this));
+ }
+ }
+ }
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermBuffer.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/TermBuffer.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermBuffer.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermBuffer.cs Tue May 1 11:45:26 2007
@@ -33,7 +33,7 @@
public int CompareTo(TermBuffer other)
{
if (field == other.field)
- // fields are interned
+ // fields are interned
return CompareChars(text, textLength, other.text, other.textLength);
else
return String.CompareOrdinal(field, other.field);
@@ -87,12 +87,12 @@
// copy text into the buffer
SetTextLength(term.Text().Length);
- System.String sourceString = term.Text();
- int sourceEnd = term.Text().Length;
- for (int i = 0; i < sourceEnd; i++)
- {
- text[i] = (char) sourceString[i];
- }
+ System.String sourceString = term.Text();
+ int sourceEnd = term.Text().Length;
+ for (int i = 0; i < sourceEnd; i++)
+ {
+ text[i] = (char) sourceString[i];
+ }
this.field = term.Field();
this.term = term;
@@ -117,7 +117,7 @@
public Term ToTerm()
{
if (field == null)
- // unset
+ // unset
return null;
if (term == null)
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermDocs.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/TermDocs.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermDocs.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermDocs.cs Tue May 1 11:45:26 2007
@@ -26,7 +26,7 @@
/// the number of times the term occurred in each document. <p> The pairs are
/// ordered by document number.
/// </summary>
- /// <seealso cref="IndexReader.TermDocs()">
+ /// <seealso cref="IndexReader#TermDocs()">
/// </seealso>
public interface TermDocs
@@ -42,12 +42,12 @@
void Seek(TermEnum termEnum);
/// <summary>Returns the current document number. <p> This is invalid until {@link
- /// #Next()} is called for the first time.
+ /// #next()} is called for the first time.
/// </summary>
int Doc();
/// <summary>Returns the frequency of the term within the current document. <p> This
- /// is invalid until {@link #Next()} is called for the first time.
+ /// is invalid until {@link #next()} is called for the first time.
/// </summary>
int Freq();
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermInfo.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/TermInfo.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermInfo.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermInfo.cs Tue May 1 11:45:26 2007
@@ -25,17 +25,17 @@
public sealed class TermInfo
{
/// <summary>The number of documents which contain the term. </summary>
- public /*internal*/ int docFreq = 0;
+ public int docFreq = 0;
- public /*internal*/ long freqPointer = 0;
- public /*internal*/ long proxPointer = 0;
+ public long freqPointer = 0;
+ public long proxPointer = 0;
internal int skipOffset;
internal TermInfo()
{
}
- public /*internal*/ TermInfo(int df, long fp, long pp)
+ public TermInfo(int df, long fp, long pp)
{
docFreq = df;
freqPointer = fp;
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermInfosReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/TermInfosReader.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermInfosReader.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermInfosReader.cs Tue May 1 11:45:26 2007
@@ -42,7 +42,7 @@
private SegmentTermEnum indexEnum;
- public /*internal*/ TermInfosReader(Directory dir, System.String seg, FieldInfos fis)
+ public TermInfosReader(Directory dir, System.String seg, FieldInfos fis)
{
directory = dir;
segment = seg;
@@ -54,20 +54,12 @@
indexEnum = new SegmentTermEnum(directory.OpenInput(segment + ".tii"), fieldInfos, true);
}
- /* Leaving this here will cause a memory leak under .NET 1.1
- ~TermInfosReader()
- {
- // patch for pre-1.4.2 JVMs, whose ThreadLocals leak
- //System.Threading.Thread.SetData(enumerators, null);
- }
- */
-
public int GetSkipInterval()
{
return origEnum.skipInterval;
}
- public /*internal*/ void Close()
+ public void Close()
{
if (origEnum != null)
origEnum.Close();
@@ -148,7 +140,7 @@
}
/// <summary>Returns the TermInfo for a Term in the set, or null. </summary>
- public /*internal*/ TermInfo Get(Term term)
+ public TermInfo Get(Term term)
{
if (size == 0)
return null;
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermInfosWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/TermInfosWriter.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermInfosWriter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermInfosWriter.cs Tue May 1 11:45:26 2007
@@ -16,8 +16,8 @@
*/
using System;
-using Directory = Lucene.Net.Store.Directory;
using IndexOutput = Lucene.Net.Store.IndexOutput;
+using Directory = Lucene.Net.Store.Directory;
using StringHelper = Lucene.Net.Util.StringHelper;
namespace Lucene.Net.Index
@@ -66,7 +66,7 @@
private TermInfosWriter other = null;
- public /*internal*/ TermInfosWriter(Directory directory, System.String segment, FieldInfos fis, int interval)
+ public TermInfosWriter(Directory directory, System.String segment, FieldInfos fis, int interval)
{
Initialize(directory, segment, fis, interval, false);
other = new TermInfosWriter(directory, segment, fis, interval, true);
@@ -94,12 +94,12 @@
/// Term must be lexicographically greater than all previous Terms added.
/// TermInfo pointers must be positive and greater than all previous.
/// </summary>
- public /*internal*/ void Add(Term term, TermInfo ti)
+ public void Add(Term term, TermInfo ti)
{
- if (!isIndex && term.CompareTo(lastTerm) <= 0)
- {
- throw new System.IO.IOException("term out of order (\"" + term + "\".compareTo(\"" + lastTerm + "\") <= 0)");
- }
+ if (!isIndex && term.CompareTo(lastTerm) <= 0)
+ {
+ throw new System.IO.IOException("term out of order (\"" + term + "\".compareTo(\"" + lastTerm + "\") <= 0)");
+ }
if (ti.freqPointer < lastTi.freqPointer)
throw new System.IO.IOException("freqPointer out of order (" + ti.freqPointer + " < " + lastTi.freqPointer + ")");
if (ti.proxPointer < lastTi.proxPointer)
@@ -145,7 +145,7 @@
/// <summary>Called to complete TermInfos creation. </summary>
- public /*internal*/ void Close()
+ public void Close()
{
output.Seek(4); // write size after format
output.WriteLong(size);
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermPositionVector.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/TermPositionVector.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermPositionVector.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermPositionVector.cs Tue May 1 11:45:26 2007
@@ -38,7 +38,7 @@
/// May return null if offsets have not been stored.
///
/// </summary>
- /// <seealso cref="Lucene.Net.analysis.Token">
+ /// <seealso cref="Lucene.Net.Analysis.Token">
///
/// </seealso>
/// <param name="index">The position in the array to get the offsets from
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermPositions.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/TermPositions.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermPositions.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermPositions.cs Tue May 1 11:45:26 2007
@@ -26,15 +26,15 @@
/// positions of each occurrence of a term in a document.
///
/// </summary>
- /// <seealso cref="IndexReader.TermPositions()">
+ /// <seealso cref="IndexReader#TermPositions()">
/// </seealso>
public interface TermPositions : TermDocs
{
/// <summary>Returns next position in the current document. It is an error to call
/// this more than {@link #Freq()} times
- /// without calling {@link #Next()}<p> This is
- /// invalid until {@link #Next()} is called for
+ /// without calling {@link #next()}<p> This is
+ /// invalid until {@link #next()} is called for
/// the first time.
/// </summary>
int NextPosition();
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermVectorsReader.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/TermVectorsReader.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermVectorsReader.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermVectorsReader.cs Tue May 1 11:45:26 2007
@@ -22,7 +22,7 @@
namespace Lucene.Net.Index
{
- /// <version> $Id: TermVectorsReader.java 170226 2005-05-15 15:04:39Z bmesser $
+ /// <version> $Id: TermVectorsReader.java 472959 2006-11-09 16:21:50Z yonik $
/// </version>
public class TermVectorsReader : System.ICloneable
{
@@ -36,7 +36,7 @@
private int tvdFormat;
private int tvfFormat;
- public /*internal*/ TermVectorsReader(Directory d, System.String segment, FieldInfos fieldInfos)
+ public TermVectorsReader(Directory d, System.String segment, FieldInfos fieldInfos)
{
if (d.FileExists(segment + TermVectorsWriter.TVX_EXTENSION))
{
@@ -119,7 +119,7 @@
/// <returns> The TermFreqVector for the document and field or null if there is no termVector for this field.
/// </returns>
/// <throws> IOException if there is an error reading the term vector files </throws>
- public /*internal*/ virtual TermFreqVector Get(int docNum, System.String field)
+ public virtual TermFreqVector Get(int docNum, System.String field)
{
// Check if no term vectors are available for this segment at all
int fieldNumber = fieldInfos.FieldNumber(field);
@@ -166,7 +166,7 @@
}
else
{
- //System.out.println("Field not found");
+ //System.out.println("Fieldable not found");
}
}
else
@@ -184,7 +184,7 @@
/// <returns> All term frequency vectors
/// </returns>
/// <throws> IOException if there is an error reading the term vector files </throws>
- public /*internal*/ virtual TermFreqVector[] Get(int docNum)
+ public virtual TermFreqVector[] Get(int docNum)
{
TermFreqVector[] result = null;
// Check if no term vectors are available for this segment at all
@@ -309,7 +309,7 @@
buffer = new char[totalLength];
if (start > 0)
- // just copy if necessary
+ // just copy if necessary
Array.Copy(previousBuffer, 0, buffer, 0, start);
}
Modified: incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermVectorsWriter.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/trunk/C%23/src/Lucene.Net/Index/TermVectorsWriter.cs?view=diff&rev=534192&r1=534191&r2=534192
==============================================================================
--- incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermVectorsWriter.cs (original)
+++ incubator/lucene.net/trunk/C#/src/Lucene.Net/Index/TermVectorsWriter.cs Tue May 1 11:45:26 2007
@@ -46,7 +46,7 @@
/// </CODE>
///
/// </summary>
- /// <version> $Id: TermVectorsWriter.java 150689 2004-11-29 21:42:02Z bmesser $
+ /// <version> $Id: TermVectorsWriter.java 472959 2006-11-09 16:21:50Z yonik $
///
/// </version>
public sealed class TermVectorsWriter
@@ -69,19 +69,20 @@
private TVField currentField = null;
private long currentDocPointer = - 1;
-
- public static System.String TvxExtension
- {
- get { return TVX_EXTENSION; }
- }
- public static System.String TvdExtension
- {
- get { return TVD_EXTENSION; }
- }
- public static System.String TvfExtension
- {
- get { return TVF_EXTENSION; }
- }
+
+ // Those three get'ers are helper for Lucene.Net only
+ public static System.String TvxExtension
+ {
+ get { return TVX_EXTENSION; }
+ }
+ public static System.String TvdExtension
+ {
+ get { return TVD_EXTENSION; }
+ }
+ public static System.String TvfExtension
+ {
+ get { return TVF_EXTENSION; }
+ }
public TermVectorsWriter(Directory directory, System.String segment, FieldInfos fieldInfos)
{
@@ -168,7 +169,7 @@
return currentField != null;
}
- /// <summary>Add term to the field's term vector. Field must already be open.
+ /// <summary>Add term to the field's term vector. Fieldable must already be open.
/// Terms should be added in
/// increasing order of terms, one call per unique termNum. ProxPointer
/// is a pointer into the TermPosition file (prx). Freq is the number of
@@ -204,7 +205,7 @@
/// term vectors, add value for tvx.
///
/// </summary>
- /// <param name="vectors">
+ /// <param name="">vectors
/// </param>
/// <throws> IOException </throws>
public void AddAllDocVectors(TermFreqVector[] vectors)
@@ -256,7 +257,7 @@
}
/// <summary>Close all streams. </summary>
- public /*internal*/ void Close()
+ public void Close()
{
try
{
@@ -310,7 +311,7 @@
{
// remember where this field is written
currentField.tvfPointer = tvf.GetFilePointer();
- //System.out.println("Field Pointer: " + currentField.tvfPointer);
+ //System.out.println("Fieldable Pointer: " + currentField.tvfPointer);
int size = terms.Count;
tvf.WriteVInt(size);