You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by ni...@apache.org on 2017/04/04 17:19:47 UTC
[41/62] [abbrv] [partial] lucenenet git commit: Renamed
Lucene.Net.Core folder Lucene.Net because the dotnet.exe pack command doesn't
allow creating a NuGet package with a different name than its folder. Working
around it with the script was much more co
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xFields.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xFields.cs b/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xFields.cs
deleted file mode 100644
index a7a52a5..0000000
--- a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xFields.cs
+++ /dev/null
@@ -1,1305 +0,0 @@
-using Lucene.Net.Index;
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-
-namespace Lucene.Net.Codecs.Lucene3x
-{
- /*
- * 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.
- */
-
- using IBits = Lucene.Net.Util.IBits;
- using BytesRef = Lucene.Net.Util.BytesRef;
- using Directory = Lucene.Net.Store.Directory;
- using DocsAndPositionsEnum = Lucene.Net.Index.DocsAndPositionsEnum;
- using DocsEnum = Lucene.Net.Index.DocsEnum;
- using FieldInfo = Lucene.Net.Index.FieldInfo;
- using FieldInfos = Lucene.Net.Index.FieldInfos;
- using IndexFileNames = Lucene.Net.Index.IndexFileNames;
- using IndexInput = Lucene.Net.Store.IndexInput;
- using IndexOptions = Lucene.Net.Index.IndexOptions;
- using IOContext = Lucene.Net.Store.IOContext;
- using IOUtils = Lucene.Net.Util.IOUtils;
- using SegmentInfo = Lucene.Net.Index.SegmentInfo;
- using StringHelper = Lucene.Net.Util.StringHelper;
- using Term = Lucene.Net.Index.Term;
- using Terms = Lucene.Net.Index.Terms;
- using TermsEnum = Lucene.Net.Index.TermsEnum;
- using UnicodeUtil = Lucene.Net.Util.UnicodeUtil;
-
- /// <summary>
- /// Exposes flex API on a pre-flex index, as a codec.
- /// @lucene.experimental </summary>
- /// @deprecated (4.0)
- [Obsolete("(4.0)")]
- internal class Lucene3xFields : FieldsProducer
- {
- private static bool DEBUG_SURROGATES = false;
-
- public TermInfosReader Tis { get; set; }
- public TermInfosReader TisNoIndex { get; private set; }
-
- public IndexInput FreqStream { get; private set; }
- public IndexInput ProxStream { get; private set; }
- private readonly FieldInfos fieldInfos;
- private readonly SegmentInfo si;
-
- // LUCENENET specific: Use StringComparer.Ordinal to get the same ordering as Java
- internal readonly SortedDictionary<string, FieldInfo> fields = new SortedDictionary<string, FieldInfo>(StringComparer.Ordinal);
- internal readonly IDictionary<string, Terms> preTerms = new Dictionary<string, Terms>();
- private readonly Directory dir;
- private readonly IOContext context;
- //private Directory cfsReader; // LUCENENET NOTE: cfsReader not used
-
- public Lucene3xFields(Directory dir, FieldInfos fieldInfos, SegmentInfo info, IOContext context, int indexDivisor)
- {
- si = info;
-
- // NOTE: we must always load terms index, even for
- // "sequential" scan during merging, because what is
- // sequential to merger may not be to TermInfosReader
- // since we do the surrogates dance:
- if (indexDivisor < 0)
- {
- indexDivisor = -indexDivisor;
- }
-
- bool success = false;
- try
- {
- var r = new TermInfosReader(dir, info.Name, fieldInfos, context, indexDivisor);
- if (indexDivisor == -1)
- {
- TisNoIndex = r;
- }
- else
- {
- TisNoIndex = null;
- Tis = r;
- }
- this.context = context;
- this.fieldInfos = fieldInfos;
-
- // 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 = dir.OpenInput(IndexFileNames.SegmentFileName(info.Name, "", Lucene3xPostingsFormat.FREQ_EXTENSION), context);
- bool anyProx = false;
- foreach (FieldInfo fi in fieldInfos)
- {
- if (fi.IsIndexed)
- {
- fields[fi.Name] = fi;
- preTerms[fi.Name] = new PreTerms(this, fi);
- if (fi.IndexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
- {
- anyProx = true;
- }
- }
- }
-
- if (anyProx)
- {
- ProxStream = dir.OpenInput(IndexFileNames.SegmentFileName(info.Name, "", Lucene3xPostingsFormat.PROX_EXTENSION), context);
- }
- else
- {
- ProxStream = null;
- }
- 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)
- {
- Dispose();
- }
- }
- this.dir = dir;
- }
-
- // If this returns, we do the surrogates dance so that the
- // terms are sorted by unicode sort order. this should be
- // true when segments are used for "normal" searching;
- // it's only false during testing, to create a pre-flex
- // index, using the test-only PreFlexRW.
- protected virtual bool SortTermsByUnicode
- {
- get { return true; }
- }
-
- public override IEnumerator<string> GetEnumerator()
- {
- return fields.Keys.GetEnumerator();
- }
-
- public override Terms GetTerms(string field)
- {
- Terms result;
- preTerms.TryGetValue(field, out result);
- return result;
- }
-
- public override int Count
- {
- get
- {
- Debug.Assert(preTerms.Count == fields.Count);
- return fields.Count;
- }
- }
-
- [Obsolete("iterate fields and add their Count instead.")]
- public override long UniqueTermCount
- {
- get
- {
- return TermsDict.Count;
- }
- }
-
- private TermInfosReader TermsDict
- {
- get
- {
- lock (this)
- {
- if (Tis != null)
- {
- return Tis;
- }
- else
- {
- return TisNoIndex;
- }
- }
- }
- }
-
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- IOUtils.Close(Tis, TisNoIndex, /*cfsReader,*/ FreqStream, ProxStream); // LUCENENET NOTE: cfsReader not used
- }
- }
-
- private class PreTerms : Terms
- {
- private readonly Lucene3xFields outerInstance;
-
- internal readonly FieldInfo fieldInfo;
-
- internal PreTerms(Lucene3xFields outerInstance, FieldInfo fieldInfo)
- {
- this.outerInstance = outerInstance;
- this.fieldInfo = fieldInfo;
- }
-
- public override TermsEnum GetIterator(TermsEnum reuse)
- {
- var termsEnum = new PreTermsEnum(outerInstance);
- termsEnum.Reset(fieldInfo);
- return termsEnum;
- }
-
- public override IComparer<BytesRef> Comparer
- {
- get
- {
- // Pre-flex indexes always sorted in UTF16 order, but
- // we remap on-the-fly to unicode order
- if (outerInstance.SortTermsByUnicode)
- {
- return BytesRef.UTF8SortedAsUnicodeComparer;
- }
- else
- {
- return BytesRef.UTF8SortedAsUTF16Comparer;
- }
- }
- }
-
- public override long Count
- {
- get { return -1; }
- }
-
- public override long SumTotalTermFreq
- {
- get
- {
- return -1;
- }
- }
-
- public override long SumDocFreq
- {
- get
- {
- return -1;
- }
- }
-
- public override int DocCount
- {
- get
- {
- return -1;
- }
- }
-
- public override bool HasFreqs
- {
- get { return fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS) >= 0; }
- }
-
- public override bool HasOffsets
- {
- get
- {
- // preflex doesn't support this
- Debug.Assert(fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) < 0);
- return false;
- }
- }
-
- public override bool HasPositions
- {
- get { return fieldInfo.IndexOptions.CompareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0; }
- }
-
- public override bool HasPayloads
- {
- get { return fieldInfo.HasPayloads; }
- }
- }
-
- private class PreTermsEnum : TermsEnum
- {
- private readonly Lucene3xFields outerInstance;
-
- public PreTermsEnum(Lucene3xFields outerInstance)
- {
- this.outerInstance = outerInstance;
- }
-
- private SegmentTermEnum termEnum;
- private FieldInfo fieldInfo;
- private string internedFieldName;
- private bool skipNext;
- private BytesRef current;
-
- private SegmentTermEnum seekTermEnum;
-
- private static readonly sbyte UTF8_NON_BMP_LEAD = unchecked((sbyte) 0xf0);
- private static readonly sbyte UTF8_HIGH_BMP_LEAD = unchecked((sbyte) 0xee);
-
- // Returns true if the unicode char is "after" the
- // surrogates in UTF16, ie >= U+E000 and <= U+FFFF:
- private static bool IsHighBMPChar(byte[] b, int idx)
- {
- return (((sbyte)b[idx]) & UTF8_HIGH_BMP_LEAD) == UTF8_HIGH_BMP_LEAD;
- }
-
- // Returns true if the unicode char in the UTF8 byte
- // sequence starting at idx encodes a char outside of
- // BMP (ie what would be a surrogate pair in UTF16):
- private static bool IsNonBMPChar(byte[] b, int idx)
- {
- return (((sbyte)b[idx]) & UTF8_NON_BMP_LEAD) == UTF8_NON_BMP_LEAD;
- }
-
- private readonly sbyte[] scratch = new sbyte[4];
- private readonly BytesRef prevTerm = new BytesRef();
- private readonly BytesRef scratchTerm = new BytesRef();
- private int newSuffixStart;
-
- // Swap in S, in place of E:
- private bool SeekToNonBMP(SegmentTermEnum te, BytesRef term, int pos)
- {
- int savLength = term.Length;
-
- Debug.Assert(term.Offset == 0);
-
- // The 3 bytes starting at downTo make up 1
- // unicode character:
- Debug.Assert(IsHighBMPChar(term.Bytes, pos));
-
- // NOTE: we cannot make this assert, because
- // AutomatonQuery legitimately sends us malformed UTF8
- // (eg the UTF8 bytes with just 0xee)
- // assert term.length >= pos + 3: "term.length=" + term.length + " pos+3=" + (pos+3) + " byte=" + Integer.toHexString(term.bytes[pos]) + " term=" + term.toString();
-
- // Save the bytes && length, since we need to
- // restore this if seek "back" finds no matching
- // terms
- if (term.Bytes.Length < 4 + pos)
- {
- term.Grow(4 + pos);
- }
-
- scratch[0] = (sbyte)term.Bytes[pos];
- scratch[1] = (sbyte)term.Bytes[pos + 1];
- scratch[2] = (sbyte)term.Bytes[pos + 2];
-
- term.Bytes[pos] = unchecked((byte)0xf0);
- term.Bytes[pos + 1] = unchecked((byte)0x90);
- term.Bytes[pos + 2] = unchecked((byte)0x80);
- term.Bytes[pos + 3] = unchecked((byte)0x80);
- term.Length = 4 + pos;
-
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" try seek term=" + UnicodeUtil.ToHexString(term.Utf8ToString()));
- }
-
- // Seek "back":
- outerInstance.TermsDict.SeekEnum(te, new Term(fieldInfo.Name, term), true);
-
- // Test if the term we seek'd to in fact found a
- // surrogate pair at the same position as the E:
- Term t2 = te.Term();
-
- // Cannot be null (or move to next field) because at
- // "worst" it'd seek to the same term we are on now,
- // unless we are being called from seek
- if (t2 == null || t2.Field != internedFieldName)
- {
- return false;
- }
-
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" got term=" + UnicodeUtil.ToHexString(t2.Text()));
- }
-
- // Now test if prefix is identical and we found
- // a non-BMP char at the same position:
- BytesRef b2 = t2.Bytes;
- Debug.Assert(b2.Offset == 0);
-
- bool matches;
- if (b2.Length >= term.Length && IsNonBMPChar(b2.Bytes, pos))
- {
- matches = true;
- for (int i = 0; i < pos; i++)
- {
- if (term.Bytes[i] != b2.Bytes[i])
- {
- matches = false;
- break;
- }
- }
- }
- else
- {
- matches = false;
- }
-
- // Restore term:
- term.Length = savLength;
- term.Bytes[pos] = (byte)scratch[0];
- term.Bytes[pos + 1] = (byte)scratch[1];
- term.Bytes[pos + 2] = (byte)scratch[2];
-
- return matches;
- }
-
- // Seek type 2 "continue" (back to the start of the
- // surrogates): scan the stripped suffix from the
- // prior term, backwards. If there was an E in that
- // part, then we try to seek back to S. If that
- // seek finds a matching term, we go there.
- private bool DoContinue()
- {
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" try cont");
- }
-
- int downTo = prevTerm.Length - 1;
-
- bool didSeek = false;
-
- int limit = Math.Min(newSuffixStart, scratchTerm.Length - 1);
-
- while (downTo > limit)
- {
- if (IsHighBMPChar(prevTerm.Bytes, downTo))
- {
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" found E pos=" + downTo + " vs len=" + prevTerm.Length);
- }
-
- if (SeekToNonBMP(seekTermEnum, prevTerm, downTo))
- {
- // TODO: more efficient seek?
- outerInstance.TermsDict.SeekEnum(termEnum, seekTermEnum.Term(), true);
- //newSuffixStart = downTo+4;
- newSuffixStart = downTo;
- scratchTerm.CopyBytes(termEnum.Term().Bytes);
- didSeek = true;
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" seek!");
- }
- break;
- }
- else
- {
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" no seek");
- }
- }
- }
-
- // Shorten prevTerm in place so that we don't redo
- // this loop if we come back here:
- if ((prevTerm.Bytes[downTo] & 0xc0) == 0xc0 || (prevTerm.Bytes[downTo] & 0x80) == 0)
- {
- prevTerm.Length = downTo;
- }
-
- downTo--;
- }
-
- return didSeek;
- }
-
- // Look for seek type 3 ("pop"): if the delta from
- // prev -> current was replacing an S with an E,
- // we must now seek to beyond that E. this seek
- // "finishes" the dance at this character
- // position.
- private bool DoPop()
- {
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" try pop");
- }
-
- Debug.Assert(newSuffixStart <= prevTerm.Length);
- Debug.Assert(newSuffixStart < scratchTerm.Length || newSuffixStart == 0);
-
- if (prevTerm.Length > newSuffixStart && IsNonBMPChar(prevTerm.Bytes, newSuffixStart) && IsHighBMPChar(scratchTerm.Bytes, newSuffixStart))
- {
- // Seek type 2 -- put 0xFF at this position:
- scratchTerm.Bytes[newSuffixStart] = unchecked((byte)0xff);
- scratchTerm.Length = newSuffixStart + 1;
-
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" seek to term=" + UnicodeUtil.ToHexString(scratchTerm.Utf8ToString()) + " " + scratchTerm.ToString());
- }
-
- // TODO: more efficient seek? can we simply swap
- // the enums?
- outerInstance.TermsDict.SeekEnum(termEnum, new Term(fieldInfo.Name, scratchTerm), true);
-
- Term t2 = termEnum.Term();
-
- // We could hit EOF or different field since this
- // was a seek "forward":
- if (t2 != null && t2.Field == internedFieldName)
- {
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" got term=" + UnicodeUtil.ToHexString(t2.Text()) + " " + t2.Bytes);
- }
-
- BytesRef b2 = t2.Bytes;
- Debug.Assert(b2.Offset == 0);
-
- // Set newSuffixStart -- we can't use
- // termEnum's since the above seek may have
- // done no scanning (eg, term was precisely
- // and index term, or, was in the term seek
- // cache):
- scratchTerm.CopyBytes(b2);
- SetNewSuffixStart(prevTerm, scratchTerm);
-
- return true;
- }
- else if (newSuffixStart != 0 || scratchTerm.Length != 0)
- {
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" got term=null (or next field)");
- }
- newSuffixStart = 0;
- scratchTerm.Length = 0;
- return true;
- }
- }
-
- return false;
- }
-
- // Pre-flex indices store terms in UTF16 sort order, but
- // certain queries require Unicode codepoint order; this
- // method carefully seeks around surrogates to handle
- // this impedance mismatch
-
- private void SurrogateDance()
- {
- if (!unicodeSortOrder)
- {
- return;
- }
-
- // We are invoked after TIS.next() (by UTF16 order) to
- // possibly seek to a different "next" (by unicode
- // order) term.
-
- // We scan only the "delta" from the last term to the
- // current term, in UTF8 bytes. We look at 1) the bytes
- // stripped from the prior term, and then 2) the bytes
- // appended to that prior term's prefix.
-
- // We don't care about specific UTF8 sequences, just
- // the "category" of the UTF16 character. Category S
- // is a high/low surrogate pair (it non-BMP).
- // Category E is any BMP char > UNI_SUR_LOW_END (and <
- // U+FFFF). Category A is the rest (any unicode char
- // <= UNI_SUR_HIGH_START).
-
- // The core issue is that pre-flex indices sort the
- // characters as ASE, while flex must sort as AES. So
- // when scanning, when we hit S, we must 1) seek
- // forward to E and enum the terms there, then 2) seek
- // back to S and enum all terms there, then 3) seek to
- // after E. Three different seek points (1, 2, 3).
-
- // We can easily detect S in UTF8: if a byte has
- // prefix 11110 (0xf0), then that byte and the
- // following 3 bytes encode a single unicode codepoint
- // in S. Similarly, we can detect E: if a byte has
- // prefix 1110111 (0xee), then that byte and the
- // following 2 bytes encode a single unicode codepoint
- // in E.
-
- // Note that this is really a recursive process --
- // maybe the char at pos 2 needs to dance, but any
- // point in its dance, suddenly pos 4 needs to dance
- // so you must finish pos 4 before returning to pos
- // 2. But then during pos 4's dance maybe pos 7 needs
- // to dance, etc. However, despite being recursive,
- // we don't need to hold any state because the state
- // can always be derived by looking at prior term &
- // current term.
-
- // TODO: can we avoid this copy?
- if (termEnum.Term() == null || termEnum.Term().Field != internedFieldName)
- {
- scratchTerm.Length = 0;
- }
- else
- {
- scratchTerm.CopyBytes(termEnum.Term().Bytes);
- }
-
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" dance");
- Console.WriteLine(" prev=" + UnicodeUtil.ToHexString(prevTerm.Utf8ToString()));
- Console.WriteLine(" " + prevTerm.ToString());
- Console.WriteLine(" term=" + UnicodeUtil.ToHexString(scratchTerm.Utf8ToString()));
- Console.WriteLine(" " + scratchTerm.ToString());
- }
-
- // this code assumes TermInfosReader/SegmentTermEnum
- // always use BytesRef.offset == 0
- Debug.Assert(prevTerm.Offset == 0);
- Debug.Assert(scratchTerm.Offset == 0);
-
- // Need to loop here because we may need to do multiple
- // pops, and possibly a continue in the end, ie:
- //
- // cont
- // pop, cont
- // pop, pop, cont
- // <nothing>
- //
-
- while (true)
- {
- if (DoContinue())
- {
- break;
- }
- else
- {
- if (!DoPop())
- {
- break;
- }
- }
- }
-
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" finish bmp ends");
- }
-
- DoPushes();
- }
-
- // Look for seek type 1 ("push"): if the newly added
- // suffix contains any S, we must try to seek to the
- // corresponding E. If we find a match, we go there;
- // else we keep looking for additional S's in the new
- // suffix. this "starts" the dance, at this character
- // position:
- private void DoPushes()
- {
- int upTo = newSuffixStart;
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" try push newSuffixStart=" + newSuffixStart + " scratchLen=" + scratchTerm.Length);
- }
-
- while (upTo < scratchTerm.Length)
- {
- if (IsNonBMPChar(scratchTerm.Bytes, upTo) && (upTo > newSuffixStart || (upTo >= prevTerm.Length || (!IsNonBMPChar(prevTerm.Bytes, upTo) && !IsHighBMPChar(prevTerm.Bytes, upTo)))))
- {
- // A non-BMP char (4 bytes UTF8) starts here:
- Debug.Assert(scratchTerm.Length >= upTo + 4);
-
- int savLength = scratchTerm.Length;
- scratch[0] = (sbyte)scratchTerm.Bytes[upTo];
- scratch[1] = (sbyte)scratchTerm.Bytes[upTo + 1];
- scratch[2] = (sbyte)scratchTerm.Bytes[upTo + 2];
-
- scratchTerm.Bytes[upTo] = (byte)UTF8_HIGH_BMP_LEAD;
- scratchTerm.Bytes[upTo + 1] = unchecked((byte)0x80);
- scratchTerm.Bytes[upTo + 2] = unchecked((byte)0x80);
- scratchTerm.Length = upTo + 3;
-
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" try seek 1 pos=" + upTo + " term=" + UnicodeUtil.ToHexString(scratchTerm.Utf8ToString()) + " " + scratchTerm.ToString() + " len=" + scratchTerm.Length);
- }
-
- // Seek "forward":
- // TODO: more efficient seek?
- outerInstance.TermsDict.SeekEnum(seekTermEnum, new Term(fieldInfo.Name, scratchTerm), true);
-
- scratchTerm.Bytes[upTo] = (byte)scratch[0];
- scratchTerm.Bytes[upTo + 1] = (byte)scratch[1];
- scratchTerm.Bytes[upTo + 2] = (byte)scratch[2];
- scratchTerm.Length = savLength;
-
- // Did we find a match?
- Term t2 = seekTermEnum.Term();
-
- if (DEBUG_SURROGATES)
- {
- if (t2 == null)
- {
- Console.WriteLine(" hit term=null");
- }
- else
- {
- Console.WriteLine(" hit term=" + UnicodeUtil.ToHexString(t2.Text()) + " " + (t2 == null ? null : t2.Bytes));
- }
- }
-
- // Since this was a seek "forward", we could hit
- // EOF or a different field:
- bool matches;
-
- if (t2 != null && t2.Field == internedFieldName)
- {
- BytesRef b2 = t2.Bytes;
- Debug.Assert(b2.Offset == 0);
- if (b2.Length >= upTo + 3 && IsHighBMPChar(b2.Bytes, upTo))
- {
- matches = true;
- for (int i = 0; i < upTo; i++)
- {
- if (scratchTerm.Bytes[i] != b2.Bytes[i])
- {
- matches = false;
- break;
- }
- }
- }
- else
- {
- matches = false;
- }
- }
- else
- {
- matches = false;
- }
-
- if (matches)
- {
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" matches!");
- }
-
- // OK seek "back"
- // TODO: more efficient seek?
- outerInstance.TermsDict.SeekEnum(termEnum, seekTermEnum.Term(), true);
-
- scratchTerm.CopyBytes(seekTermEnum.Term().Bytes);
-
- // +3 because we don't need to check the char
- // at upTo: we know it's > BMP
- upTo += 3;
-
- // NOTE: we keep iterating, now, since this
- // can easily "recurse". Ie, after seeking
- // forward at a certain char position, we may
- // find another surrogate in our [new] suffix
- // and must then do another seek (recurse)
- }
- else
- {
- upTo++;
- }
- }
- else
- {
- upTo++;
- }
- }
- }
-
- private bool unicodeSortOrder;
-
- internal virtual void Reset(FieldInfo fieldInfo)
- {
- //System.out.println("pff.reset te=" + termEnum);
- this.fieldInfo = fieldInfo;
-
- internedFieldName = StringHelper.Intern(fieldInfo.Name);
-
- Term term = new Term(internedFieldName);
- if (termEnum == null)
- {
- termEnum = outerInstance.TermsDict.Terms(term);
- seekTermEnum = outerInstance.TermsDict.Terms(term);
- //System.out.println(" term=" + termEnum.term());
- }
- else
- {
- outerInstance.TermsDict.SeekEnum(termEnum, term, true);
- }
- skipNext = true;
-
- unicodeSortOrder = outerInstance.SortTermsByUnicode;
-
- Term t = termEnum.Term();
- if (t != null && t.Field == internedFieldName)
- {
- newSuffixStart = 0;
- prevTerm.Length = 0;
- SurrogateDance();
- }
- }
-
- public override IComparer<BytesRef> Comparer
- {
- get
- {
- // Pre-flex indexes always sorted in UTF16 order, but
- // we remap on-the-fly to unicode order
- if (unicodeSortOrder)
- {
- return BytesRef.UTF8SortedAsUnicodeComparer;
- }
- else
- {
- return BytesRef.UTF8SortedAsUTF16Comparer;
- }
- }
- }
-
- public override void SeekExact(long ord)
- {
- throw new System.NotSupportedException();
- }
-
- public override long Ord
- {
- get { throw new System.NotSupportedException(); }
- }
-
- public override SeekStatus SeekCeil(BytesRef term)
- {
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine("TE.seek target=" + UnicodeUtil.ToHexString(term.Utf8ToString()));
- }
- skipNext = false;
- TermInfosReader tis = outerInstance.TermsDict;
- Term t0 = new Term(fieldInfo.Name, term);
-
- Debug.Assert(termEnum != null);
-
- tis.SeekEnum(termEnum, t0, false);
-
- Term t = termEnum.Term();
-
- if (t != null && t.Field == internedFieldName && term.BytesEquals(t.Bytes))
- {
- // If we found an exact match, no need to do the
- // surrogate dance
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" seek exact match");
- }
- current = t.Bytes;
- return SeekStatus.FOUND;
- }
- else if (t == null || t.Field != internedFieldName)
- {
- // TODO: maybe we can handle this like the next()
- // into null? set term as prevTerm then dance?
-
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" seek hit EOF");
- }
-
- // We hit EOF; try end-case surrogate dance: if we
- // find an E, try swapping in S, backwards:
- scratchTerm.CopyBytes(term);
-
- Debug.Assert(scratchTerm.Offset == 0);
-
- for (int i = scratchTerm.Length - 1; i >= 0; i--)
- {
- if (IsHighBMPChar(scratchTerm.Bytes, i))
- {
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" found E pos=" + i + "; try seek");
- }
-
- if (SeekToNonBMP(seekTermEnum, scratchTerm, i))
- {
- scratchTerm.CopyBytes(seekTermEnum.Term().Bytes);
- outerInstance.TermsDict.SeekEnum(termEnum, seekTermEnum.Term(), false);
-
- newSuffixStart = 1 + i;
-
- DoPushes();
-
- // Found a match
- // TODO: faster seek?
- current = termEnum.Term().Bytes;
- return SeekStatus.NOT_FOUND;
- }
- }
- }
-
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" seek END");
- }
-
- current = null;
- return SeekStatus.END;
- }
- else
- {
- // We found a non-exact but non-null term; this one
- // is fun -- just treat it like next, by pretending
- // requested term was prev:
- prevTerm.CopyBytes(term);
-
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" seek hit non-exact term=" + UnicodeUtil.ToHexString(t.Text()));
- }
-
- BytesRef br = t.Bytes;
- Debug.Assert(br.Offset == 0);
-
- SetNewSuffixStart(term, br);
-
- SurrogateDance();
-
- Term t2 = termEnum.Term();
- if (t2 == null || t2.Field != internedFieldName)
- {
- // PreFlex codec interns field names; verify:
- Debug.Assert(t2 == null || !t2.Field.Equals(internedFieldName, StringComparison.Ordinal));
- current = null;
- return SeekStatus.END;
- }
- else
- {
- current = t2.Bytes;
- Debug.Assert(!unicodeSortOrder || term.CompareTo(current) < 0, "term=" + UnicodeUtil.ToHexString(term.Utf8ToString()) + " vs current=" + UnicodeUtil.ToHexString(current.Utf8ToString()));
- return SeekStatus.NOT_FOUND;
- }
- }
- }
-
- private void SetNewSuffixStart(BytesRef br1, BytesRef br2)
- {
- int limit = Math.Min(br1.Length, br2.Length);
- int lastStart = 0;
- for (int i = 0; i < limit; i++)
- {
- if ((br1.Bytes[br1.Offset + i] & 0xc0) == 0xc0 || (br1.Bytes[br1.Offset + i] & 0x80) == 0)
- {
- lastStart = i;
- }
- if (br1.Bytes[br1.Offset + i] != br2.Bytes[br2.Offset + i])
- {
- newSuffixStart = lastStart;
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" set newSuffixStart=" + newSuffixStart);
- }
- return;
- }
- }
- newSuffixStart = limit;
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" set newSuffixStart=" + newSuffixStart);
- }
- }
-
- public override BytesRef Next()
- {
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine("TE.next()");
- }
- if (skipNext)
- {
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" skipNext=true");
- }
- skipNext = false;
- if (termEnum.Term() == null)
- {
- return null;
- // PreFlex codec interns field names:
- }
- else if (termEnum.Term().Field != internedFieldName)
- {
- return null;
- }
- else
- {
- return current = termEnum.Term().Bytes;
- }
- }
-
- // TODO: can we use STE's prevBuffer here?
- prevTerm.CopyBytes(termEnum.Term().Bytes);
-
- if (termEnum.Next() && termEnum.Term().Field == internedFieldName)
- {
- newSuffixStart = termEnum.newSuffixStart;
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" newSuffixStart=" + newSuffixStart);
- }
- SurrogateDance();
- Term t = termEnum.Term();
- if (t == null || t.Field != internedFieldName)
- {
- // PreFlex codec interns field names; verify:
- Debug.Assert(t == null || !t.Field.Equals(internedFieldName, StringComparison.Ordinal));
- current = null;
- }
- else
- {
- current = t.Bytes;
- }
- return current;
- }
- else
- {
- // this field is exhausted, but we have to give
- // surrogateDance a chance to seek back:
- if (DEBUG_SURROGATES)
- {
- Console.WriteLine(" force cont");
- }
- //newSuffixStart = prevTerm.length;
- newSuffixStart = 0;
- SurrogateDance();
-
- Term t = termEnum.Term();
- if (t == null || t.Field != internedFieldName)
- {
- // PreFlex codec interns field names; verify:
- Debug.Assert(t == null || !t.Field.Equals(internedFieldName, StringComparison.Ordinal));
- return null;
- }
- else
- {
- current = t.Bytes;
- return current;
- }
- }
- }
-
- public override BytesRef Term
- {
- get { return current; }
- }
-
- public override int DocFreq
- {
- get { return termEnum.DocFreq; }
- }
-
- public override long TotalTermFreq
- {
- get { return -1; }
- }
-
- public override DocsEnum Docs(IBits liveDocs, DocsEnum reuse, DocsFlags flags)
- {
- PreDocsEnum docsEnum;
- if (reuse == null || !(reuse is PreDocsEnum))
- {
- docsEnum = new PreDocsEnum(outerInstance);
- }
- else
- {
- docsEnum = (PreDocsEnum)reuse;
- if (docsEnum.FreqStream != outerInstance.FreqStream)
- {
- docsEnum = new PreDocsEnum(outerInstance);
- }
- }
- return docsEnum.Reset(termEnum, liveDocs);
- }
-
- public override DocsAndPositionsEnum DocsAndPositions(IBits liveDocs, DocsAndPositionsEnum reuse, DocsAndPositionsFlags flags)
- {
- PreDocsAndPositionsEnum docsPosEnum;
- if (fieldInfo.IndexOptions != IndexOptions.DOCS_AND_FREQS_AND_POSITIONS)
- {
- return null;
- }
- else if (reuse == null || !(reuse is PreDocsAndPositionsEnum))
- {
- docsPosEnum = new PreDocsAndPositionsEnum(outerInstance);
- }
- else
- {
- docsPosEnum = (PreDocsAndPositionsEnum)reuse;
- if (docsPosEnum.FreqStream != outerInstance.FreqStream)
- {
- docsPosEnum = new PreDocsAndPositionsEnum(outerInstance);
- }
- }
- return docsPosEnum.Reset(termEnum, liveDocs);
- }
- }
-
- private sealed class PreDocsEnum : DocsEnum
- {
- private readonly Lucene3xFields outerInstance;
-
- internal readonly SegmentTermDocs docs;
- private int docID = -1;
-
- internal PreDocsEnum(Lucene3xFields outerInstance)
- {
- this.outerInstance = outerInstance;
- docs = new SegmentTermDocs(outerInstance.FreqStream, outerInstance.TermsDict, outerInstance.fieldInfos);
- }
-
- internal IndexInput FreqStream
- {
- get
- {
- return outerInstance.FreqStream;
- }
- }
-
- public PreDocsEnum Reset(SegmentTermEnum termEnum, IBits liveDocs)
- {
- docs.LiveDocs = liveDocs;
- docs.Seek(termEnum);
- docs.freq = 1;
- docID = -1;
- return this;
- }
-
- public override int NextDoc()
- {
- if (docs.Next())
- {
- return docID = docs.Doc;
- }
- else
- {
- return docID = NO_MORE_DOCS;
- }
- }
-
- public override int Advance(int target)
- {
- if (docs.SkipTo(target))
- {
- return docID = docs.Doc;
- }
- else
- {
- return docID = NO_MORE_DOCS;
- }
- }
-
- public override int Freq
- {
- get { return docs.Freq; }
- }
-
- public override int DocID
- {
- get { return docID; }
- }
-
- public override long GetCost()
- {
- return docs.m_df;
- }
- }
-
- private sealed class PreDocsAndPositionsEnum : DocsAndPositionsEnum
- {
- private readonly Lucene3xFields outerInstance;
-
- private readonly SegmentTermPositions pos;
- private int docID = -1;
-
- internal PreDocsAndPositionsEnum(Lucene3xFields outerInstance)
- {
- this.outerInstance = outerInstance;
- pos = new SegmentTermPositions(outerInstance.FreqStream, outerInstance.ProxStream, outerInstance.TermsDict, outerInstance.fieldInfos);
- }
-
- internal IndexInput FreqStream
- {
- get
- {
- return outerInstance.FreqStream;
- }
- }
-
- public DocsAndPositionsEnum Reset(SegmentTermEnum termEnum, IBits liveDocs)
- {
- pos.LiveDocs = liveDocs;
- pos.Seek(termEnum);
- docID = -1;
- return this;
- }
-
- public override int NextDoc()
- {
- if (pos.Next())
- {
- return docID = pos.Doc;
- }
- else
- {
- return docID = NO_MORE_DOCS;
- }
- }
-
- public override int Advance(int target)
- {
- if (pos.SkipTo(target))
- {
- return docID = pos.Doc;
- }
- else
- {
- return docID = NO_MORE_DOCS;
- }
- }
-
- public override int Freq
- {
- get { return pos.Freq; }
- }
-
- public override int DocID
- {
- get { return docID; }
- }
-
- public override int NextPosition()
- {
- Debug.Assert(docID != NO_MORE_DOCS);
- return pos.NextPosition();
- }
-
- public override int StartOffset
- {
- get { return -1; }
- }
-
- public override int EndOffset
- {
- get { return -1; }
- }
-
- public override BytesRef GetPayload()
- {
- return pos.GetPayload();
- }
-
- public override long GetCost()
- {
- return pos.m_df;
- }
- }
-
- public override long RamBytesUsed()
- {
- if (Tis != null)
- {
- return Tis.RamBytesUsed();
- }
- else
- {
- // when there is no index, there is almost nothing loaded into RAM
- return 0L;
- }
- }
-
- public override void CheckIntegrity()
- {
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xNormsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xNormsFormat.cs b/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xNormsFormat.cs
deleted file mode 100644
index 21b2cbd..0000000
--- a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xNormsFormat.cs
+++ /dev/null
@@ -1,43 +0,0 @@
-using System;
-
-namespace Lucene.Net.Codecs.Lucene3x
-{
- /*
- * 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.
- */
-
- using SegmentReadState = Lucene.Net.Index.SegmentReadState;
- using SegmentWriteState = Lucene.Net.Index.SegmentWriteState;
-
- /// <summary>
- /// Lucene3x ReadOnly NormsFormat implementation </summary>
- /// @deprecated (4.0) this is only used to read indexes created
- /// before 4.0.
- /// @lucene.experimental
- [Obsolete("(4.0) this is only used to read indexes created before 4.0.")]
- internal class Lucene3xNormsFormat : NormsFormat
- {
- public override DocValuesConsumer NormsConsumer(SegmentWriteState state)
- {
- throw new System.NotSupportedException("this codec can only be used for reading");
- }
-
- public override DocValuesProducer NormsProducer(SegmentReadState state)
- {
- return new Lucene3xNormsProducer(state.Directory, state.SegmentInfo, state.FieldInfos, state.Context);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xNormsProducer.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xNormsProducer.cs b/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xNormsProducer.cs
deleted file mode 100644
index 00faced..0000000
--- a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xNormsProducer.cs
+++ /dev/null
@@ -1,291 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Globalization;
-using System.Linq;
-using Lucene.Net.Support;
-
-namespace Lucene.Net.Codecs.Lucene3x
-{
- /*
- * 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.
- */
-
- using BinaryDocValues = Lucene.Net.Index.BinaryDocValues;
- using IBits = Lucene.Net.Util.IBits;
- using Directory = Lucene.Net.Store.Directory;
- using FieldInfo = Lucene.Net.Index.FieldInfo;
- using FieldInfos = Lucene.Net.Index.FieldInfos;
- using IndexFileNames = Lucene.Net.Index.IndexFileNames;
- using IndexInput = Lucene.Net.Store.IndexInput;
- using IOContext = Lucene.Net.Store.IOContext;
- using IOUtils = Lucene.Net.Util.IOUtils;
- using NumericDocValues = Lucene.Net.Index.NumericDocValues;
- using RamUsageEstimator = Lucene.Net.Util.RamUsageEstimator;
- using SegmentInfo = Lucene.Net.Index.SegmentInfo;
- using SortedDocValues = Lucene.Net.Index.SortedDocValues;
- using SortedSetDocValues = Lucene.Net.Index.SortedSetDocValues;
- using StringHelper = Lucene.Net.Util.StringHelper;
-
- /// <summary>
- /// Reads Lucene 3.x norms format and exposes it via DocValues API
- /// @lucene.experimental </summary>
- /// @deprecated Only for reading existing 3.x indexes
- [Obsolete("Only for reading existing 3.x indexes")]
- internal class Lucene3xNormsProducer : DocValuesProducer
- {
- /// <summary>
- /// norms header placeholder </summary>
- internal static readonly sbyte[] NORMS_HEADER = { (sbyte)'N', (sbyte)'R', (sbyte)'M', -1 };
-
- /// <summary>
- /// Extension of norms file </summary>
- internal const string NORMS_EXTENSION = "nrm";
-
- /// <summary>
- /// Extension of separate norms file </summary>
- internal const string SEPARATE_NORMS_EXTENSION = "s";
-
- private readonly IDictionary<string, NormsDocValues> norms = new Dictionary<string, NormsDocValues>();
-
- // any .nrm or .sNN files we have open at any time.
- // TODO: just a list, and double-close() separate norms files?
- internal readonly ISet<IndexInput> openFiles = new IdentityHashSet<IndexInput>();
-
- // points to a singleNormFile
- internal IndexInput singleNormStream;
-
- internal readonly int maxdoc;
-
- private readonly AtomicInt64 ramBytesUsed;
-
- // note: just like segmentreader in 3.x, we open up all the files here (including separate norms) up front.
- // but we just don't do any seeks or reading yet.
- public Lucene3xNormsProducer(Directory dir, SegmentInfo info, FieldInfos fields, IOContext context)
- {
- Directory separateNormsDir = info.Dir; // separate norms are never inside CFS
- maxdoc = info.DocCount;
- string segmentName = info.Name;
- bool success = false;
- try
- {
- long nextNormSeek = NORMS_HEADER.Length; //skip header (header unused for now)
- foreach (FieldInfo fi in fields)
- {
- if (fi.HasNorms)
- {
- string fileName = GetNormFilename(info, fi.Number);
- Directory d = HasSeparateNorms(info, fi.Number) ? separateNormsDir : dir;
-
- // singleNormFile means multiple norms share this file
- bool singleNormFile = IndexFileNames.MatchesExtension(fileName, NORMS_EXTENSION);
- IndexInput normInput = null;
- long normSeek;
-
- if (singleNormFile)
- {
- normSeek = nextNormSeek;
- if (singleNormStream == null)
- {
- singleNormStream = d.OpenInput(fileName, context);
- openFiles.Add(singleNormStream);
- }
- // All norms in the .nrm file can share a single IndexInput since
- // they are only used in a synchronized context.
- // If this were to change in the future, a clone could be done here.
- normInput = singleNormStream;
- }
- else
- {
- normInput = d.OpenInput(fileName, context);
- openFiles.Add(normInput);
- // if the segment was created in 3.2 or after, we wrote the header for sure,
- // and don't need to do the sketchy file size check. otherwise, we check
- // if the size is exactly equal to maxDoc to detect a headerless file.
- // NOTE: remove this check in Lucene 5.0!
- string version = info.Version;
- bool isUnversioned = (version == null || StringHelper.VersionComparer.Compare(version, "3.2") < 0) && normInput.Length == maxdoc;
- if (isUnversioned)
- {
- normSeek = 0;
- }
- else
- {
- normSeek = NORMS_HEADER.Length;
- }
- }
- NormsDocValues norm = new NormsDocValues(this, normInput, normSeek);
- norms[fi.Name] = norm;
- nextNormSeek += maxdoc; // increment also if some norms are separate
- }
- }
- // TODO: change to a real check? see LUCENE-3619
- Debug.Assert(singleNormStream == null || nextNormSeek == singleNormStream.Length, singleNormStream != null ? "len: " + singleNormStream.Length + " expected: " + nextNormSeek : "null");
- success = true;
- }
- finally
- {
- if (!success)
- {
- IOUtils.CloseWhileHandlingException(openFiles);
- }
- }
- ramBytesUsed = new AtomicInt64();
- }
-
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- try
- {
- IOUtils.Close(openFiles.ToArray());
- }
- finally
- {
- norms.Clear();
- openFiles.Clear();
- }
- }
- }
-
- private static string GetNormFilename(SegmentInfo info, int number)
- {
- if (HasSeparateNorms(info, number))
- {
- long gen = Convert.ToInt64(info.GetAttribute(Lucene3xSegmentInfoFormat.NORMGEN_PREFIX + number), CultureInfo.InvariantCulture);
- return IndexFileNames.FileNameFromGeneration(info.Name, SEPARATE_NORMS_EXTENSION + number, gen);
- }
- else
- {
- // single file for all norms
- return IndexFileNames.SegmentFileName(info.Name, "", NORMS_EXTENSION);
- }
- }
-
- private static bool HasSeparateNorms(SegmentInfo info, int number)
- {
- string v = info.GetAttribute(Lucene3xSegmentInfoFormat.NORMGEN_PREFIX + number);
- if (v == null)
- {
- return false;
- }
- else
- {
- Debug.Assert(Convert.ToInt64(v, CultureInfo.InvariantCulture) != SegmentInfo.NO);
- return true;
- }
- }
-
- // holds a file+offset pointing to a norms, and lazy-loads it
- // to a singleton NumericDocValues instance
- private sealed class NormsDocValues
- {
- private readonly Lucene3xNormsProducer outerInstance;
-
- private readonly IndexInput file;
- private readonly long offset;
- private NumericDocValues instance;
-
- public NormsDocValues(Lucene3xNormsProducer outerInstance, IndexInput normInput, long normSeek)
- {
- this.outerInstance = outerInstance;
- this.file = normInput;
- this.offset = normSeek;
- }
-
- internal NumericDocValues Instance
- {
- get
- {
- lock (this)
- {
- if (instance == null)
- {
- var bytes = new byte[outerInstance.maxdoc];
- // some norms share fds
- lock (file)
- {
- file.Seek(offset);
- file.ReadBytes(bytes, 0, bytes.Length, false);
- }
- // we are done with this file
- if (file != outerInstance.singleNormStream)
- {
- outerInstance.openFiles.Remove(file);
- file.Dispose();
- }
- outerInstance.ramBytesUsed.AddAndGet(RamUsageEstimator.SizeOf(bytes));
- instance = new NumericDocValuesAnonymousInnerClassHelper(this, bytes);
- }
- return instance;
- }
- }
- }
-
- private class NumericDocValuesAnonymousInnerClassHelper : NumericDocValues
- {
- private readonly byte[] bytes;
-
- public NumericDocValuesAnonymousInnerClassHelper(NormsDocValues outerInstance, byte[] bytes)
- {
- this.bytes = bytes;
- }
-
- public override long Get(int docID)
- {
- return bytes[docID];
- }
- }
- }
-
- public override NumericDocValues GetNumeric(FieldInfo field)
- {
- var dv = norms[field.Name];
- Debug.Assert(dv != null);
- return dv.Instance;
- }
-
- public override BinaryDocValues GetBinary(FieldInfo field)
- {
- throw new InvalidOperationException();
- }
-
- public override SortedDocValues GetSorted(FieldInfo field)
- {
- throw new InvalidOperationException();
- }
-
- public override SortedSetDocValues GetSortedSet(FieldInfo field)
- {
- throw new InvalidOperationException();
- }
-
- public override IBits GetDocsWithField(FieldInfo field)
- {
- throw new InvalidOperationException();
- }
-
- public override long RamBytesUsed()
- {
- return ramBytesUsed.Get();
- }
-
- public override void CheckIntegrity()
- {
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xPostingsFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xPostingsFormat.cs b/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xPostingsFormat.cs
deleted file mode 100644
index c5e4c1b..0000000
--- a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xPostingsFormat.cs
+++ /dev/null
@@ -1,67 +0,0 @@
-using System;
-using SegmentReadState = Lucene.Net.Index.SegmentReadState;
-using SegmentWriteState = Lucene.Net.Index.SegmentWriteState;
-
-namespace Lucene.Net.Codecs.Lucene3x
-{
- /*
- * 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>
- /// Codec that reads the pre-flex-indexing postings
- /// format. It does not provide a writer because newly
- /// written segments should use the Codec configured on IndexWriter.
- /// </summary>
- /// @deprecated (4.0) this is only used to read indexes created
- /// before 4.0.
- /// @lucene.experimental
- [Obsolete("(4.0) this is only used to read indexes created")]
- [PostingsFormatName("Lucene3x")] // LUCENENET specific - using PostingsFormatName attribute to ensure the default name passed from subclasses is the same as this class name
- internal class Lucene3xPostingsFormat : PostingsFormat
- {
- /// <summary>
- /// Extension of terms file </summary>
- public const string TERMS_EXTENSION = "tis";
-
- /// <summary>
- /// Extension of terms index file </summary>
- public const string TERMS_INDEX_EXTENSION = "tii";
-
- /// <summary>
- /// Extension of freq postings file </summary>
- public const string FREQ_EXTENSION = "frq";
-
- /// <summary>
- /// Extension of prox postings file </summary>
- public const string PROX_EXTENSION = "prx";
-
- public Lucene3xPostingsFormat()
- : base()
- {
- }
-
- public override FieldsConsumer FieldsConsumer(SegmentWriteState state)
- {
- throw new System.NotSupportedException("this codec can only be used for reading");
- }
-
- public override FieldsProducer FieldsProducer(SegmentReadState state)
- {
- return new Lucene3xFields(state.Directory, state.FieldInfos, state.SegmentInfo, state.Context, state.TermsIndexDivisor);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoFormat.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoFormat.cs b/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoFormat.cs
deleted file mode 100644
index 86c55de..0000000
--- a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoFormat.cs
+++ /dev/null
@@ -1,105 +0,0 @@
-using System;
-using System.Globalization;
-
-namespace Lucene.Net.Codecs.Lucene3x
-{
- /*
- * 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.
- */
-
- using SegmentInfo = Lucene.Net.Index.SegmentInfo;
-
- /// <summary>
- /// Lucene3x ReadOnly SegmentInfoFormat implementation </summary>
- /// @deprecated (4.0) this is only used to read indexes created
- /// before 4.0.
- /// @lucene.experimental
- [Obsolete("(4.0) this is only used to read indexes created")]
- public class Lucene3xSegmentInfoFormat : SegmentInfoFormat
- {
- private readonly SegmentInfoReader reader = new Lucene3xSegmentInfoReader();
-
- /// <summary>
- /// this format adds optional per-segment String
- /// diagnostics storage, and switches userData to Map
- /// </summary>
- public static readonly int FORMAT_DIAGNOSTICS = -9;
-
- /// <summary>
- /// Each segment records whether it has term vectors </summary>
- public static readonly int FORMAT_HAS_VECTORS = -10;
-
- /// <summary>
- /// Each segment records the Lucene version that created it. </summary>
- public static readonly int FORMAT_3_1 = -11;
-
- /// <summary>
- /// Extension used for saving each SegmentInfo, once a 3.x
- /// index is first committed to with 4.0.
- /// </summary>
- public static readonly string UPGRADED_SI_EXTENSION = "si";
-
- public static readonly string UPGRADED_SI_CODEC_NAME = "Lucene3xSegmentInfo";
- public static readonly int UPGRADED_SI_VERSION_START = 0;
- public static readonly int UPGRADED_SI_VERSION_CURRENT = UPGRADED_SI_VERSION_START;
-
- public override SegmentInfoReader SegmentInfoReader
- {
- get
- {
- return reader;
- }
- }
-
- public override SegmentInfoWriter SegmentInfoWriter
- {
- get
- {
- throw new System.NotSupportedException("this codec can only be used for reading");
- }
- }
-
- // only for backwards compat
- public static readonly string DS_OFFSET_KEY = typeof(Lucene3xSegmentInfoFormat).Name + ".dsoffset";
-
- public static readonly string DS_NAME_KEY = typeof(Lucene3xSegmentInfoFormat).Name + ".dsname";
- public static readonly string DS_COMPOUND_KEY = typeof(Lucene3xSegmentInfoFormat).Name + ".dscompound";
- public static readonly string NORMGEN_KEY = typeof(Lucene3xSegmentInfoFormat).Name + ".normgen";
- public static readonly string NORMGEN_PREFIX = typeof(Lucene3xSegmentInfoFormat).Name + ".normfield";
-
- /// <returns> if this segment shares stored fields & vectors, this
- /// offset is where in that file this segment's docs begin </returns>
- public static int GetDocStoreOffset(SegmentInfo si)
- {
- string v = si.GetAttribute(DS_OFFSET_KEY);
- return v == null ? -1 : Convert.ToInt32(v, CultureInfo.InvariantCulture);
- }
-
- /// <returns> name used to derive fields/vectors file we share with other segments </returns>
- public static string GetDocStoreSegment(SegmentInfo si)
- {
- string v = si.GetAttribute(DS_NAME_KEY);
- return v == null ? si.Name : v;
- }
-
- /// <returns> whether doc store files are stored in compound file (*.cfx) </returns>
- public static bool GetDocStoreIsCompoundFile(SegmentInfo si)
- {
- string v = si.GetAttribute(DS_COMPOUND_KEY);
- return v == null ? false : Convert.ToBoolean(v, CultureInfo.InvariantCulture);
- }
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a5dc68d0/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs b/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs
deleted file mode 100644
index 9bf4ddc..0000000
--- a/src/Lucene.Net.Core/Codecs/Lucene3x/Lucene3xSegmentInfoReader.cs
+++ /dev/null
@@ -1,314 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Globalization;
-using CompoundFileDirectory = Lucene.Net.Store.CompoundFileDirectory;
-using Directory = Lucene.Net.Store.Directory;
-
-namespace Lucene.Net.Codecs.Lucene3x
-{
- /*
- * 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.
- */
-
- using IndexFileNames = Lucene.Net.Index.IndexFileNames;
- using IndexFormatTooNewException = Lucene.Net.Index.IndexFormatTooNewException;
- using IndexFormatTooOldException = Lucene.Net.Index.IndexFormatTooOldException;
- using IndexInput = Lucene.Net.Store.IndexInput;
- using IOContext = Lucene.Net.Store.IOContext;
- using IOUtils = Lucene.Net.Util.IOUtils;
- using SegmentCommitInfo = Lucene.Net.Index.SegmentCommitInfo;
- using SegmentInfo = Lucene.Net.Index.SegmentInfo;
- using SegmentInfos = Lucene.Net.Index.SegmentInfos;
-
- /// <summary>
- /// Lucene 3x implementation of <seealso cref="SegmentInfoReader"/>.
- /// @lucene.experimental </summary>
- /// @deprecated Only for reading existing 3.x indexes
- [Obsolete("Only for reading existing 3.x indexes")]
- public class Lucene3xSegmentInfoReader : SegmentInfoReader
- {
- public static void ReadLegacyInfos(SegmentInfos infos, Directory directory, IndexInput input, int format)
- {
- infos.Version = input.ReadInt64(); // read version
- infos.Counter = input.ReadInt32(); // read counter
- Lucene3xSegmentInfoReader reader = new Lucene3xSegmentInfoReader();
- for (int i = input.ReadInt32(); i > 0; i--) // read segmentInfos
- {
- SegmentCommitInfo siPerCommit = reader.ReadLegacySegmentInfo(directory, format, input);
- SegmentInfo si = siPerCommit.Info;
-
- if (si.Version == null)
- {
- // Could be a 3.0 - try to open the doc stores - if it fails, it's a
- // 2.x segment, and an IndexFormatTooOldException will be thrown,
- // which is what we want.
- Directory dir = directory;
- if (Lucene3xSegmentInfoFormat.GetDocStoreOffset(si) != -1)
- {
- if (Lucene3xSegmentInfoFormat.GetDocStoreIsCompoundFile(si))
- {
- dir = new CompoundFileDirectory(dir, IndexFileNames.SegmentFileName(Lucene3xSegmentInfoFormat.GetDocStoreSegment(si), "", Lucene3xCodec.COMPOUND_FILE_STORE_EXTENSION), IOContext.READ_ONCE, false);
- }
- }
- else if (si.UseCompoundFile)
- {
- dir = new CompoundFileDirectory(dir, IndexFileNames.SegmentFileName(si.Name, "", IndexFileNames.COMPOUND_FILE_EXTENSION), IOContext.READ_ONCE, false);
- }
-
- try
- {
- Lucene3xStoredFieldsReader.CheckCodeVersion(dir, Lucene3xSegmentInfoFormat.GetDocStoreSegment(si));
- }
- finally
- {
- // If we opened the directory, close it
- if (dir != directory)
- {
- dir.Dispose();
- }
- }
-
- // Above call succeeded, so it's a 3.0 segment. Upgrade it so the next
- // time the segment is read, its version won't be null and we won't
- // need to open FieldsReader every time for each such segment.
- si.Version = "3.0";
- }
- else if (si.Version.Equals("2.x", StringComparison.Ordinal))
- {
- // If it's a 3x index touched by 3.1+ code, then segments record their
- // version, whether they are 2.x ones or not. We detect that and throw
- // appropriate exception.
- throw new IndexFormatTooOldException("segment " + si.Name + " in resource " + input, si.Version);
- }
- infos.Add(siPerCommit);
- }
-
- infos.UserData = input.ReadStringStringMap();
- }
-
- public override SegmentInfo Read(Directory directory, string segmentName, IOContext context)
- {
- // NOTE: this is NOT how 3.x is really written...
- string fileName = IndexFileNames.SegmentFileName(segmentName, "", Lucene3xSegmentInfoFormat.UPGRADED_SI_EXTENSION);
-
- bool success = false;
-
- IndexInput input = directory.OpenInput(fileName, context);
-
- try
- {
- SegmentInfo si = ReadUpgradedSegmentInfo(segmentName, directory, input);
- success = true;
- return si;
- }
- finally
- {
- if (!success)
- {
- IOUtils.CloseWhileHandlingException(input);
- }
- else
- {
- input.Dispose();
- }
- }
- }
-
- private static void AddIfExists(Directory dir, ISet<string> files, string fileName)
- {
- if (dir.FileExists(fileName))
- {
- files.Add(fileName);
- }
- }
-
- /// <summary>
- /// reads from legacy 3.x segments_N </summary>
- private SegmentCommitInfo ReadLegacySegmentInfo(Directory dir, int format, IndexInput input)
- {
- // check that it is a format we can understand
- if (format > Lucene3xSegmentInfoFormat.FORMAT_DIAGNOSTICS)
- {
- throw new IndexFormatTooOldException(input, format, Lucene3xSegmentInfoFormat.FORMAT_DIAGNOSTICS, Lucene3xSegmentInfoFormat.FORMAT_3_1);
- }
- if (format < Lucene3xSegmentInfoFormat.FORMAT_3_1)
- {
- throw new IndexFormatTooNewException(input, format, Lucene3xSegmentInfoFormat.FORMAT_DIAGNOSTICS, Lucene3xSegmentInfoFormat.FORMAT_3_1);
- }
- string version;
- if (format <= Lucene3xSegmentInfoFormat.FORMAT_3_1)
- {
- version = input.ReadString();
- }
- else
- {
- version = null;
- }
-
- string name = input.ReadString();
-
- int docCount = input.ReadInt32();
- long delGen = input.ReadInt64();
-
- int docStoreOffset = input.ReadInt32();
- IDictionary<string, string> attributes = new Dictionary<string, string>();
-
- // parse the docstore stuff and shove it into attributes
- string docStoreSegment;
- bool docStoreIsCompoundFile;
- if (docStoreOffset != -1)
- {
- docStoreSegment = input.ReadString();
- docStoreIsCompoundFile = input.ReadByte() == SegmentInfo.YES;
- attributes[Lucene3xSegmentInfoFormat.DS_OFFSET_KEY] = Convert.ToString(docStoreOffset, CultureInfo.InvariantCulture);
- attributes[Lucene3xSegmentInfoFormat.DS_NAME_KEY] = docStoreSegment;
- attributes[Lucene3xSegmentInfoFormat.DS_COMPOUND_KEY] = Convert.ToString(docStoreIsCompoundFile, CultureInfo.InvariantCulture);
- }
- else
- {
- docStoreSegment = name;
- docStoreIsCompoundFile = false;
- }
-
- // pre-4.0 indexes write a byte if there is a single norms file
- byte b = input.ReadByte();
-
- //System.out.println("version=" + version + " name=" + name + " docCount=" + docCount + " delGen=" + delGen + " dso=" + docStoreOffset + " dss=" + docStoreSegment + " dssCFs=" + docStoreIsCompoundFile + " b=" + b + " format=" + format);
-
- Debug.Assert(1 == b, "expected 1 but was: " + b + " format: " + format);
- int numNormGen = input.ReadInt32();
- IDictionary<int, long> normGen;
- if (numNormGen == SegmentInfo.NO)
- {
- normGen = null;
- }
- else
- {
- normGen = new Dictionary<int, long>();
- for (int j = 0; j < numNormGen; j++)
- {
- normGen[j] = input.ReadInt64();
- }
- }
- bool isCompoundFile = input.ReadByte() == SegmentInfo.YES;
-
- int delCount = input.ReadInt32();
- Debug.Assert(delCount <= docCount);
-
- bool hasProx = input.ReadByte() == 1;
-
- IDictionary<string, string> diagnostics = input.ReadStringStringMap();
-
- if (format <= Lucene3xSegmentInfoFormat.FORMAT_HAS_VECTORS)
- {
- // NOTE: unused
- int hasVectors = input.ReadByte();
- }
-
- // Replicate logic from 3.x's SegmentInfo.files():
- ISet<string> files = new HashSet<string>();
- if (isCompoundFile)
- {
- files.Add(IndexFileNames.SegmentFileName(name, "", IndexFileNames.COMPOUND_FILE_EXTENSION));
- }
- else
- {
- AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xFieldInfosReader.FIELD_INFOS_EXTENSION));
- AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xPostingsFormat.FREQ_EXTENSION));
- AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xPostingsFormat.PROX_EXTENSION));
- AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xPostingsFormat.TERMS_EXTENSION));
- AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xPostingsFormat.TERMS_INDEX_EXTENSION));
- AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xNormsProducer.NORMS_EXTENSION));
- }
-
- if (docStoreOffset != -1)
- {
- if (docStoreIsCompoundFile)
- {
- files.Add(IndexFileNames.SegmentFileName(docStoreSegment, "", Lucene3xCodec.COMPOUND_FILE_STORE_EXTENSION));
- }
- else
- {
- files.Add(IndexFileNames.SegmentFileName(docStoreSegment, "", Lucene3xStoredFieldsReader.FIELDS_INDEX_EXTENSION));
- files.Add(IndexFileNames.SegmentFileName(docStoreSegment, "", Lucene3xStoredFieldsReader.FIELDS_EXTENSION));
- AddIfExists(dir, files, IndexFileNames.SegmentFileName(docStoreSegment, "", Lucene3xTermVectorsReader.VECTORS_INDEX_EXTENSION));
- AddIfExists(dir, files, IndexFileNames.SegmentFileName(docStoreSegment, "", Lucene3xTermVectorsReader.VECTORS_FIELDS_EXTENSION));
- AddIfExists(dir, files, IndexFileNames.SegmentFileName(docStoreSegment, "", Lucene3xTermVectorsReader.VECTORS_DOCUMENTS_EXTENSION));
- }
- }
- else if (!isCompoundFile)
- {
- files.Add(IndexFileNames.SegmentFileName(name, "", Lucene3xStoredFieldsReader.FIELDS_INDEX_EXTENSION));
- files.Add(IndexFileNames.SegmentFileName(name, "", Lucene3xStoredFieldsReader.FIELDS_EXTENSION));
- AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xTermVectorsReader.VECTORS_INDEX_EXTENSION));
- AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xTermVectorsReader.VECTORS_FIELDS_EXTENSION));
- AddIfExists(dir, files, IndexFileNames.SegmentFileName(name, "", Lucene3xTermVectorsReader.VECTORS_DOCUMENTS_EXTENSION));
- }
-
- // parse the normgen stuff and shove it into attributes
- if (normGen != null)
- {
- attributes[Lucene3xSegmentInfoFormat.NORMGEN_KEY] = Convert.ToString(numNormGen, CultureInfo.InvariantCulture);
- foreach (KeyValuePair<int, long> ent in normGen)
- {
- long gen = ent.Value;
- if (gen >= SegmentInfo.YES)
- {
- // Definitely a separate norm file, with generation:
- files.Add(IndexFileNames.FileNameFromGeneration(name, "s" + ent.Key, gen));
- attributes[Lucene3xSegmentInfoFormat.NORMGEN_PREFIX + ent.Key] = Convert.ToString(gen, CultureInfo.InvariantCulture);
- }
- else if (gen == SegmentInfo.NO)
- {
- // No separate norm
- }
- else
- {
- // We should have already hit indexformat too old exception
- Debug.Assert(false);
- }
- }
- }
-
- SegmentInfo info = new SegmentInfo(dir, version, name, docCount, isCompoundFile, null, diagnostics, Collections.UnmodifiableMap(attributes));
- info.SetFiles(files);
-
- SegmentCommitInfo infoPerCommit = new SegmentCommitInfo(info, delCount, delGen, -1);
- return infoPerCommit;
- }
-
- private SegmentInfo ReadUpgradedSegmentInfo(string name, Directory dir, IndexInput input)
- {
- CodecUtil.CheckHeader(input, Lucene3xSegmentInfoFormat.UPGRADED_SI_CODEC_NAME, Lucene3xSegmentInfoFormat.UPGRADED_SI_VERSION_START, Lucene3xSegmentInfoFormat.UPGRADED_SI_VERSION_CURRENT);
- string version = input.ReadString();
-
- int docCount = input.ReadInt32();
-
- IDictionary<string, string> attributes = input.ReadStringStringMap();
-
- bool isCompoundFile = input.ReadByte() == SegmentInfo.YES;
-
- IDictionary<string, string> diagnostics = input.ReadStringStringMap();
-
- ISet<string> files = input.ReadStringSet();
-
- SegmentInfo info = new SegmentInfo(dir, version, name, docCount, isCompoundFile, null, diagnostics, Collections.UnmodifiableMap(attributes));
- info.SetFiles(files);
- return info;
- }
- }
-}
\ No newline at end of file