You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by sy...@apache.org on 2014/11/09 11:20:57 UTC

lucenenet git commit: More fixes

Repository: lucenenet
Updated Branches:
  refs/heads/master cd3ee1366 -> a15933529


More fixes


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/a1593352
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/a1593352
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/a1593352

Branch: refs/heads/master
Commit: a159335299230c1902aa8465e215cd0f92b53387
Parents: cd3ee13
Author: Itamar Syn-Hershko <it...@code972.com>
Authored: Sun Nov 9 12:20:49 2014 +0200
Committer: Itamar Syn-Hershko <it...@code972.com>
Committed: Sun Nov 9 12:20:49 2014 +0200

----------------------------------------------------------------------
 src/Lucene.Net.Core/Util/BytesRef.cs            | 14 ++++----
 .../Suggest/Analyzing/FreeTextSuggester.cs      | 13 +++----
 .../Suggest/Fst/WFSTCompletionLookup.cs         | 32 ++++++++---------
 .../Suggest/Jaspell/JaspellLookup.cs            | 38 ++++++++++----------
 4 files changed, 49 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1593352/src/Lucene.Net.Core/Util/BytesRef.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Util/BytesRef.cs b/src/Lucene.Net.Core/Util/BytesRef.cs
index 54761e9..f79331f 100644
--- a/src/Lucene.Net.Core/Util/BytesRef.cs
+++ b/src/Lucene.Net.Core/Util/BytesRef.cs
@@ -433,31 +433,31 @@ namespace Lucene.Net.Util
             {
                 if (Bytes == null)
                 {
-                    throw new Exception("bytes is null");
+                    throw new InvalidOperationException("bytes is null");
                 }
                 if (Length < 0)
                 {
-                    throw new Exception("length is negative: " + Length);
+                    throw new InvalidOperationException("length is negative: " + Length);
                 }
                 if (Length > Bytes.Length)
                 {
-                    throw new Exception("length is out of bounds: " + Length + ",bytes.length=" + Bytes.Length);
+                    throw new InvalidOperationException("length is out of bounds: " + Length + ",bytes.length=" + Bytes.Length);
                 }
                 if (Offset < 0)
                 {
-                    throw new Exception("offset is negative: " + Offset);
+                    throw new InvalidOperationException("offset is negative: " + Offset);
                 }
                 if (Offset > Bytes.Length)
                 {
-                    throw new Exception("offset out of bounds: " + Offset + ",bytes.length=" + Bytes.Length);
+                    throw new InvalidOperationException("offset out of bounds: " + Offset + ",bytes.length=" + Bytes.Length);
                 }
                 if (Offset + Length < 0)
                 {
-                    throw new Exception("offset+length is negative: offset=" + Offset + ",length=" + Length);
+                    throw new InvalidOperationException("offset+length is negative: offset=" + Offset + ",length=" + Length);
                 }
                 if (Offset + Length > Bytes.Length)
                 {
-                    throw new Exception("offset+length out of bounds: offset=" + Offset + ",length=" + Length + ",bytes.length=" + Bytes.Length);
+                    throw new InvalidOperationException("offset+length out of bounds: offset=" + Offset + ",length=" + Length + ",bytes.length=" + Bytes.Length);
                 }
                 return true;
             }

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1593352/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs b/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs
index 7a7aa40..e5a7288 100644
--- a/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs
+++ b/src/Lucene.Net.Suggest/Suggest/Analyzing/FreeTextSuggester.cs
@@ -782,7 +782,8 @@ namespace Lucene.Net.Search.Suggest.Analyzing
 		  private HashSet<BytesRef> seen;
 		  private BytesRef finalLastToken;
 
-		  public TopNSearcherAnonymousInnerClassHelper<T1>(FreeTextSuggester outerInstance, FST<T1> fst, int num, UnknownType size, UnknownType weightComparator, HashSet<BytesRef> seen, BytesRef finalLastToken) : base(org.apache.lucene.search.suggest.fst, num, size, weightComparator)
+		  public TopNSearcherAnonymousInnerClassHelper(FreeTextSuggester outerInstance, FST<long?> fst, int num, UnknownType size, UnknownType weightComparator, HashSet<BytesRef> seen, BytesRef finalLastToken)
+              : base(fst, num, size, weightComparator)
 		  {
 			  this.outerInstance = outerInstance;
 			  this.seen = seen;
@@ -809,8 +810,8 @@ namespace Lucene.Net.Search.Suggest.Analyzing
 		  protected override bool AcceptResult(IntsRef input, long? output)
 		  {
 			Util.Fst.Util.ToBytesRef(input, scratchBytes);
-			finalLastToken.Grow(finalLastToken.length + scratchBytes.length);
-			int lenSav = finalLastToken.length;
+			finalLastToken.Grow(finalLastToken.Length + scratchBytes.Length);
+			int lenSav = finalLastToken.Length;
 			finalLastToken.Append(scratchBytes);
 			//System.out.println("    accept? input='" + scratchBytes.utf8ToString() + "'; lastToken='" + finalLastToken.utf8ToString() + "'; return " + (seen.contains(finalLastToken) == false));
 			bool ret = seen.Contains(finalLastToken) == false;
@@ -871,9 +872,9 @@ namespace Lucene.Net.Search.Suggest.Analyzing
 
 		fst.GetFirstArc(arc);
 
-		sbyte[] bytes = scratch.Bytes;
-		int pos = scratch.Offset;
-		int end = pos + scratch.Length;
+		var bytes = scratch.Bytes;
+		var pos = scratch.Offset;
+		var end = pos + scratch.Length;
 		while (pos < end)
 		{
 		  if (fst.FindTargetArc(bytes[pos++] & 0xff, arc, arc, bytesReader) == null)

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1593352/src/Lucene.Net.Suggest/Suggest/Fst/WFSTCompletionLookup.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Suggest/Suggest/Fst/WFSTCompletionLookup.cs b/src/Lucene.Net.Suggest/Suggest/Fst/WFSTCompletionLookup.cs
index 2ad8e76..67d4ac8 100644
--- a/src/Lucene.Net.Suggest/Suggest/Fst/WFSTCompletionLookup.cs
+++ b/src/Lucene.Net.Suggest/Suggest/Fst/WFSTCompletionLookup.cs
@@ -87,12 +87,12 @@ namespace Lucene.Net.Search.Suggest.Fst
                 throw new ArgumentException("this suggester doesn't support contexts");
             }
             count = 0;
-            BytesRef scratch = new BytesRef();
+            var scratch = new BytesRef();
             InputIterator iter = new WFSTInputIterator(this, iterator);
-            IntsRef scratchInts = new IntsRef();
+            var scratchInts = new IntsRef();
             BytesRef previous = null;
-            PositiveIntOutputs outputs = PositiveIntOutputs.Singleton;
-            Builder<long?> builder = new Builder<long?>(FST.INPUT_TYPE.BYTE1, outputs);
+            var outputs = PositiveIntOutputs.Singleton;
+            var builder = new Builder<long?>(FST.INPUT_TYPE.BYTE1, outputs);
             while ((scratch = iter.Next()) != null)
             {
                 long cost = iter.Weight;
@@ -106,7 +106,7 @@ namespace Lucene.Net.Search.Suggest.Fst
                     continue; // for duplicate suggestions, the best weight is actually
                     // added
                 }
-                Util.ToIntsRef(scratch, scratchInts);
+                Lucene.Net.Util.Fst.Util.ToIntsRef(scratch, scratchInts);
                 builder.Add(scratchInts, cost);
                 previous.CopyBytes(scratch);
                 count++;
@@ -132,7 +132,7 @@ namespace Lucene.Net.Search.Suggest.Fst
 		return true;
 	  }
 
-        public override IList<LookupResult> Lookup(string key, HashSet<BytesRef> contexts, bool onlyMorePopular, int num)
+        public override IList<LookupResult> DoLookup(string key, HashSet<BytesRef> contexts, bool onlyMorePopular, int num)
         {
             if (contexts != null)
             {
@@ -147,12 +147,12 @@ namespace Lucene.Net.Search.Suggest.Fst
 
             if (fst == null)
             {
-                return Collections.emptyList();
+                return Collections.EmptyList<LookupResult>();
             }
 
             BytesRef scratch = new BytesRef(key);
             int prefixLength = scratch.Length;
-            Arc<long?> arc = new Arc<long?>();
+            FST.Arc<long?> arc = new FST.Arc<long?>();
 
             // match the prefix portion exactly
             long? prefixOutput = null;
@@ -167,7 +167,7 @@ namespace Lucene.Net.Search.Suggest.Fst
 
             if (prefixOutput == null)
             {
-                return Collections.emptyList();
+                return Collections.EmptyList();
             }
 
             IList<LookupResult> results = new List<LookupResult>(num);
@@ -176,7 +176,7 @@ namespace Lucene.Net.Search.Suggest.Fst
             {
                 spare.grow(scratch.length);
                 UnicodeUtil.UTF8toUTF16(scratch, spare);
-                results.Add(new LookupResult(spare.ToString(), decodeWeight(prefixOutput + arc.nextFinalOutput)));
+                results.Add(new LookupResult(spare.ToString(), decodeWeight(prefixOutput + arc.NextFinalOutput)));
                 if (--num == 0)
                 {
                     return results; // that was quick
@@ -184,11 +184,11 @@ namespace Lucene.Net.Search.Suggest.Fst
             }
 
             // complete top-N
-            TopResults<long?> completions = null;
+            Util.Fst.Util.TopResults<long?> completions = null;
             try
             {
                 completions = Util.ShortestPaths(fst, arc, prefixOutput, weightComparator, num, !exactFirst);
-                Debug.Assert(completions.isComplete);
+                Debug.Assert(completions.IsComplete);
             }
             catch (IOException bogus)
             {
@@ -196,7 +196,7 @@ namespace Lucene.Net.Search.Suggest.Fst
             }
 
             BytesRef suffix = new BytesRef(8);
-            foreach (Result<long?> completion in completions)
+            foreach (Util.Fst.Util.Result<long?> completion in completions)
             {
                 scratch.length = prefixLength;
                 // append suffix
@@ -209,9 +209,9 @@ namespace Lucene.Net.Search.Suggest.Fst
             return results;
         }
 
-        private long? LookupPrefix(BytesRef scratch, Arc<long?> arc) //Bogus
+        private long? LookupPrefix(BytesRef scratch, FST.Arc<long?> arc) //Bogus
         {
-            Debug.Assert(0 == (long)fst.outputs.NoOutput);
+            Debug.Assert(0 == (long)fst.Outputs.NoOutput);
             long output = 0;
             var bytesReader = fst.BytesReader;
 
@@ -307,7 +307,7 @@ namespace Lucene.Net.Search.Suggest.Fst
                 writer.Write(buffer, 0, output.Position);
             }
 
-            protected internal override long decode(BytesRef scratch, ByteArrayDataInput tmpInput)
+            protected internal override long Decode(BytesRef scratch, ByteArrayDataInput tmpInput)
             {
                 scratch.Length -= 4; // int
                 // skip suggestion:

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/a1593352/src/Lucene.Net.Suggest/Suggest/Jaspell/JaspellLookup.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Suggest/Suggest/Jaspell/JaspellLookup.cs b/src/Lucene.Net.Suggest/Suggest/Jaspell/JaspellLookup.cs
index 7b5a2d2..2151862 100644
--- a/src/Lucene.Net.Suggest/Suggest/Jaspell/JaspellLookup.cs
+++ b/src/Lucene.Net.Suggest/Suggest/Jaspell/JaspellLookup.cs
@@ -1,5 +1,6 @@
 using System;
 using System.Collections.Generic;
+using Lucene.Net.Store;
 using Lucene.Net.Util;
 
 namespace Lucene.Net.Search.Suggest.Jaspell
@@ -61,11 +62,10 @@ namespace Lucene.Net.Search.Suggest.Jaspell
                 throw new System.ArgumentException("this suggester doesn't support contexts");
             }
             count = 0;
-            trie = new JaspellTernarySearchTrie();
-            trie.MatchAlmostDiff = editDistance;
+            trie = new JaspellTernarySearchTrie { MatchAlmostDiff = editDistance };
             BytesRef spare;
 
-            CharsRef charsSpare = new CharsRef();
+            var charsSpare = new CharsRef();
 
             while ((spare = tfit.Next()) != null)
             {
@@ -104,7 +104,7 @@ namespace Lucene.Net.Search.Suggest.Jaspell
             return trie.Get(key);
         }
 
-        public override IList<LookupResult> Lookup(string key, HashSet<BytesRef> contexts, bool onlyMorePopular, int num)
+        public override IList<LookupResult> DoLookup(string key, HashSet<BytesRef> contexts, bool onlyMorePopular, int num)
         {
             if (contexts != null)
             {
@@ -132,8 +132,8 @@ namespace Lucene.Net.Search.Suggest.Jaspell
                 LookupPriorityQueue queue = new LookupPriorityQueue(num);
                 foreach (string s in list)
                 {
-                    long freq = (long)((Number)trie.Get(s));
-                    queue.InsertWithOverflow(new LookupResult(new CharsRef(s), freq));
+                    long freq = (long)(trie.Get(s));
+                    queue.InsertWithOverflow(new LookupResult(s, freq));
                 }
                 foreach (LookupResult lr in queue.Results)
                 {
@@ -145,8 +145,8 @@ namespace Lucene.Net.Search.Suggest.Jaspell
                 for (int i = 0; i < maxCnt; i++)
                 {
                     string s = list[i];
-                    long freq = (long)((Number)trie.Get(s));
-                    res.Add(new LookupResult(new CharsRef(s), freq));
+                    long freq = (long)(trie.Get(s));
+                    res.Add(new LookupResult(s, freq));
                 }
             }
             return res;
@@ -159,27 +159,27 @@ namespace Lucene.Net.Search.Suggest.Jaspell
 
         private void ReadRecursively(DataInput @in, JaspellTernarySearchTrie.TSTNode node)
         {
-            node.splitchar = @in.ReadString().charAt(0);
-            sbyte mask = @in.ReadByte();
+            node.splitchar = @in.ReadString()[0];
+            sbyte mask = (sbyte)@in.ReadByte();
             if ((mask & HAS_VALUE) != 0)
             {
-                node.data = Convert.ToInt64(@in.readLong());
+                node.data = Convert.ToInt64(@in.ReadLong());
             }
             if ((mask & LO_KID) != 0)
             {
-                JaspellTernarySearchTrie.TSTNode kid = new JaspellTernarySearchTrie.TSTNode(trie, '\0', node);
+                var kid = new JaspellTernarySearchTrie.TSTNode(trie, '\0', node);
                 node.relatives[JaspellTernarySearchTrie.TSTNode.LOKID] = kid;
                 ReadRecursively(@in, kid);
             }
             if ((mask & EQ_KID) != 0)
             {
-                JaspellTernarySearchTrie.TSTNode kid = new JaspellTernarySearchTrie.TSTNode(trie, '\0', node);
+                var kid = new JaspellTernarySearchTrie.TSTNode(trie, '\0', node);
                 node.relatives[JaspellTernarySearchTrie.TSTNode.EQKID] = kid;
                 ReadRecursively(@in, kid);
             }
             if ((mask & HI_KID) != 0)
             {
-                JaspellTernarySearchTrie.TSTNode kid = new JaspellTernarySearchTrie.TSTNode(trie, '\0', node);
+                var kid = new JaspellTernarySearchTrie.TSTNode(trie, '\0', node);
                 node.relatives[JaspellTernarySearchTrie.TSTNode.HIKID] = kid;
                 ReadRecursively(@in, kid);
             }
@@ -191,7 +191,7 @@ namespace Lucene.Net.Search.Suggest.Jaspell
             {
                 return;
             }
-            @out.writeString(new string(new char[] { node.splitchar }, 0, 1));
+            @out.WriteString(new string(new char[] { node.splitchar }, 0, 1));
             sbyte mask = 0;
             if (node.relatives[JaspellTernarySearchTrie.TSTNode.LOKID] != null)
             {
@@ -209,10 +209,10 @@ namespace Lucene.Net.Search.Suggest.Jaspell
             {
                 mask |= HAS_VALUE;
             }
-            @out.writeByte(mask);
+            @out.WriteByte(mask);
             if (node.data != null)
             {
-                @out.writeLong((long)((Number)node.data));
+                @out.WriteLong((long)(node.data));
             }
             WriteRecursively(@out, node.relatives[JaspellTernarySearchTrie.TSTNode.LOKID]);
             WriteRecursively(@out, node.relatives[JaspellTernarySearchTrie.TSTNode.EQKID]);
@@ -231,10 +231,10 @@ namespace Lucene.Net.Search.Suggest.Jaspell
             return true;
         }
 
-        public override bool load(DataInput input)
+        public override bool Load(DataInput input)
         {
             count = input.ReadVLong();
-            JaspellTernarySearchTrie.TSTNode root = new JaspellTernarySearchTrie.TSTNode(trie, '\0', null);
+            var root = new JaspellTernarySearchTrie.TSTNode(trie, '\0', null);
             ReadRecursively(input, root);
             trie.Root = root;
             return true;