You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucenenet.apache.org by mh...@apache.org on 2011/08/10 20:25:16 UTC
[Lucene.Net] svn commit: r1156294 [1/2] - in
/incubator/lucene.net/branches/Lucene.Net_4e: src/Lucene.Net/
src/Lucene.Net/Analysis/ src/Lucene.Net/Analysis/TokenAttributes/
src/Lucene.Net/Index/ src/Lucene.Net/Util/ test/Lucene.Net.Test/
test/Lucene.Net.Test/Analys...
Author: mherndon
Date: Wed Aug 10 18:25:15 2011
New Revision: 1156294
URL: http://svn.apache.org/viewvc?rev=1156294&view=rev
Log:
ported offset,payload,position increment, and type attributes. also ported payload with unit tests. the more integration payload tests will have to wait till other index types are ported
Added:
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/Token.cs
- copied, changed from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/IOffsetAttribute.cs
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/IPayloadAttribute.cs
- copied, changed from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/IPositionIncrementAttribute.cs
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/ITermToBytesRefAttribute.cs
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/ITypeAttribute.cs
- copied, changed from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/OffsetAttribute.cs
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/PayloadAttribute.cs
- copied, changed from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/KeywordAttribute.cs
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/PositionIncrementAttribute.cs
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/TypeAttribute.cs
- copied, changed from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/KeywordAttribute.cs
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Index/
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Index/DocsAndPositionEnumerator.cs
- copied, changed from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Index/Payload.cs
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Index/TermsHashPerField.cs
- copied, changed from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs
- copied, changed from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs
incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/OffsetAttributeTest.cs
- copied, changed from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/FlagsAttributeTest.cs
incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/PayloadAttributeTest.cs
incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/PositionIncrementAttributeTest.cs
incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/TypeAttributeTest.cs
incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Index/
incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Index/PayloadTest.cs
Modified:
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/FlagsAttribute.cs
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/KeywordAttribute.cs
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Lucene.Net.csproj
incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/AttributeBase.cs
incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/CharTermAttributeTest.cs
incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/FlagsAttributeTest.cs
incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Lucene.Net.Test.csproj
incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Settings.StyleCop
Copied: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/Token.cs (from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/Token.cs?p2=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/Token.cs&p1=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs&r1=1156293&r2=1156294&rev=1156294&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/Token.cs Wed Aug 10 18:25:15 2011
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
-// <copyright company="Apache" file="TokenStream.cs">
+// <copyright company="Apache" file="Token.cs">
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
@@ -27,9 +27,9 @@ namespace Lucene.Net.Analysis
using System.Text;
/// <summary>
- /// TODO: update
+ /// TODO: port
/// </summary>
- public class TokenStream
+ public class Token
{
}
}
\ No newline at end of file
Modified: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/FlagsAttribute.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/FlagsAttribute.cs?rev=1156294&r1=1156293&r2=1156294&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/FlagsAttribute.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/FlagsAttribute.cs Wed Aug 10 18:25:15 2011
@@ -52,6 +52,22 @@ namespace Lucene.Net.Analysis.TokenAttri
public class FlagsAttribute : AttributeBase, IFlagsAttribute
{
/// <summary>
+ /// Initializes a new instance of the <see cref="FlagsAttribute"/> class.
+ /// </summary>
+ public FlagsAttribute()
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="FlagsAttribute"/> class.
+ /// </summary>
+ /// <param name="flags">The flags.</param>
+ public FlagsAttribute(int flags)
+ {
+ this.Flags = flags;
+ }
+
+ /// <summary>
/// Gets or sets the flags.
/// </summary>
/// <value>The flags.</value>
Added: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/IOffsetAttribute.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/IOffsetAttribute.cs?rev=1156294&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/IOffsetAttribute.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/IOffsetAttribute.cs Wed Aug 10 18:25:15 2011
@@ -0,0 +1,70 @@
+// -----------------------------------------------------------------------
+// <copyright company="Apache" file="IOffsetAttribute.cs">
+//
+// 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.
+//
+// </copyright>
+// -----------------------------------------------------------------------
+
+namespace Lucene.Net.Analysis.TokenAttributes
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+
+ /// <summary>
+ /// The start and end character offset of a <see cref="Token"/>
+ /// </summary>
+ public interface IOffsetAttribute
+ {
+ /// <summary>
+ /// Gets or sets the start of the offset.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// The difference between the offset's start and end
+ /// may not be equal to the length of the term text.
+ /// The term text may have been altered by a stemmer
+ /// some other filter
+ /// </para>
+ /// </remarks>
+ /// <value>The offset start.</value>
+ int OffsetStart { get; set; }
+
+
+ /// <summary>
+ /// Gets or sets the end of the offset.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// This will be the end of the offset. Which is one greater than
+ /// the position of the last character corresponding to this token
+ /// in the source text. The length of the token in the source text
+ /// is the <c>OffsetEnd</c> - <c>OffsetStart</c>
+ /// </para>
+ /// </remarks>
+ /// <value>The offset end.</value>
+ int OffsetEnd { get; set; }
+
+ /// <summary>
+ /// Sets the offset.
+ /// </summary>
+ /// <param name="start">The start.</param>
+ /// <param name="end">The end.</param>
+ void SetOffset(int start, int end);
+ }
+}
Copied: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/IPayloadAttribute.cs (from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/IPayloadAttribute.cs?p2=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/IPayloadAttribute.cs&p1=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs&r1=1156293&r2=1156294&rev=1156294&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/IPayloadAttribute.cs Wed Aug 10 18:25:15 2011
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
-// <copyright company="Apache" file="TokenStream.cs">
+// <copyright company="Apache" file="IPayloadAttribute.cs">
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
@@ -19,17 +19,24 @@
// </copyright>
// -----------------------------------------------------------------------
-namespace Lucene.Net.Analysis
+namespace Lucene.Net.Analysis.TokenAttributes
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
+ using Lucene.Net.Index;
/// <summary>
- /// TODO: update
+ /// The payload of a <see cref="Token"/>.
/// </summary>
- public class TokenStream
+ /// <seealso cref="Index.Payload" />
+ public interface IPayloadAttribute
{
+ /// <summary>
+ /// Gets or sets the payload.
+ /// </summary>
+ /// <value>The payload.</value>
+ Payload Payload { get; set; }
}
-}
\ No newline at end of file
+}
Added: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/IPositionIncrementAttribute.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/IPositionIncrementAttribute.cs?rev=1156294&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/IPositionIncrementAttribute.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/IPositionIncrementAttribute.cs Wed Aug 10 18:25:15 2011
@@ -0,0 +1,68 @@
+// -----------------------------------------------------------------------
+// <copyright company="Apache" file="IPositionIncrementAttribute.cs">
+//
+// 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.
+//
+// </copyright>
+// -----------------------------------------------------------------------
+
+
+
+namespace Lucene.Net.Analysis.TokenAttributes
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using Lucene.Net.Index;
+
+ /// <summary>
+ /// The <see cref="PositionIncrement"/> determines the position of
+ /// this token relative to the previous <see cref="Token"/> in a
+ /// <see cref="TokenStream"/>. This is used in phrase searching.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// <b>Set the <see cref="PositionIncrement"/> to Zero</b> to put multiple terms
+ /// in the same position. An example of this would be if a word has multiple
+ /// stems. A Search for phrases that includes either stem will match. In
+ /// this case, all but the first stem's <see cref="PositionIncrement"/> should be
+ /// set to zero.
+ /// </para>
+ /// <para>
+ /// The increment of the first instance should be one.
+ /// Repeating a token with an increment of zero can also be used
+ /// to boost the scores of matches of that token
+ /// </para>
+ /// <para>
+ /// <b>Set the <see cref="PositionIncrement"/> to values greater than one</b> to in
+ /// inhibit exact phrase matches. For example, if one does not want phrases to match
+ /// across remove stop words, then one could build a stop word filter that removes stop
+ /// words. It can also set the <see cref="PositionIncrement"/> to the number of stop
+ /// words remove before each non-stop word. Exact phrase queries will then only match
+ /// when the terms occurs with no intervening stop words.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="DocsAndPositionEnumerator"/>
+ public interface IPositionIncrementAttribute
+ {
+ /// <summary>
+ /// Gets or sets the position increment. The default value is one.
+ /// </summary>
+ /// <value>The position increment. The default value is one.</value>
+ int PositionIncrement { get; set; }
+ }
+}
Added: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/ITermToBytesRefAttribute.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/ITermToBytesRefAttribute.cs?rev=1156294&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/ITermToBytesRefAttribute.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/ITermToBytesRefAttribute.cs Wed Aug 10 18:25:15 2011
@@ -0,0 +1,85 @@
+// -----------------------------------------------------------------------
+// <copyright company="Apache" file="ITermToBytesRefAttribute.cs">
+//
+// 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.
+//
+// </copyright>
+// -----------------------------------------------------------------------
+
+
+
+namespace Lucene.Net.Analysis.TokenAttributes
+{
+ using Lucene.Net.Index;
+ using Lucene.Net.Util;
+
+ /// <summary>
+ /// This attribute is requested by the <see cref="TermsHashPerField"/>
+ /// to index the contents. It can be used to customize the byte[] encoding of terms.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// The expected use is to call <see cref="BytesRef"/> then invoke
+ /// <see cref="FillBytesRef"/> for each term.
+ /// </para>
+ /// <note>
+ /// Experimental: This is a very expert API, please <see cref="ICharTermAttribute"/>
+ /// and its implementation of this method for UTF-8 terms.
+ /// </note>
+ /// <code lang="c#">
+ /// TermToBytesRefAttribute attribute = tokenStream.GetAttribute(typeof(TermToBytesRefAttribute));
+ /// BytesRef bytes = attribute.BytesRef;
+ ///
+ /// while(attribute.IncrementToken())
+ /// {
+ /// int hash attribute.FillBytesRef();
+ /// if(isInteresting(bytes))
+ /// {
+ /// // do something with it.
+ /// Use(new BytesRef(bytes));
+ /// }
+ /// }
+ /// </code>
+ /// </remarks>
+ public interface ITermToBytesRefAttribute
+ {
+ /// <summary>
+ /// Gets the <see cref="BytesRef"/>. The bytes are updated
+ /// from the current term when the invoker calls <see cref="FillBytesRef"/>.
+ /// </summary>
+ /// <value>The bytes ref.</value>
+ BytesRef BytesRef { get; }
+
+ /// <summary>
+ /// Updates the bytes <see cref="BytesRef"/> to contain
+ /// the term's final encoding. Then it returns its hashcode.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// Implement the following code for performance reasons, if
+ /// the code can calculate the has on-the-fly. If this is not the
+ /// case, just return the <see cref="BytesRef"/>'s hashcode.
+ /// </para>
+ /// <code lang="c#">
+ /// int hash = 0;
+ /// for(int i = this.termBytes.Offset; i < this.termBytes.Offset + this.termBytes.Length; i++)
+ /// hash = (31*hash) + this.termBytes.Bytes[i];
+ /// </code>
+ /// </remarks>
+ /// <returns>The hashcode from the <see cref="BytesRef"/>'s hashcode.</returns>
+ int FillBytesRef();
+ }
+}
Copied: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/ITypeAttribute.cs (from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/ITypeAttribute.cs?p2=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/ITypeAttribute.cs&p1=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs&r1=1156293&r2=1156294&rev=1156294&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/ITypeAttribute.cs Wed Aug 10 18:25:15 2011
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
-// <copyright company="Apache" file="TokenStream.cs">
+// <copyright company="Apache" file="ITypeAttribute.cs">
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
@@ -19,17 +19,17 @@
// </copyright>
// -----------------------------------------------------------------------
-namespace Lucene.Net.Analysis
+namespace Lucene.Net.Analysis.TokenAttributes
{
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
/// <summary>
- /// TODO: update
+ /// A <see cref="Token"/>'s lexical type. The default value is 'word'.
/// </summary>
- public class TokenStream
+ public interface ITypeAttribute
{
+ /// <summary>
+ /// Gets or sets the <see cref="Token"/>'s lexical type.
+ /// </summary>
+ /// <value>The type.</value>
+ string Type { get; set; }
}
-}
\ No newline at end of file
+}
Modified: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/KeywordAttribute.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/KeywordAttribute.cs?rev=1156294&r1=1156293&r2=1156294&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/KeywordAttribute.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/KeywordAttribute.cs Wed Aug 10 18:25:15 2011
@@ -36,6 +36,22 @@ namespace Lucene.Net.Analysis.TokenAttri
public class KeywordAttribute : Util.AttributeBase, IKeywordAttribute
{
/// <summary>
+ /// Initializes a new instance of the <see cref="KeywordAttribute"/> class.
+ /// </summary>
+ public KeywordAttribute()
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="KeywordAttribute"/> class.
+ /// </summary>
+ /// <param name="isKeyword">if set to <c>true</c> [is keyword].</param>
+ public KeywordAttribute(bool isKeyword)
+ {
+ this.IsKeyword = isKeyword;
+ }
+
+ /// <summary>
/// Gets or sets a value indicating whether this instance is keyword.
/// </summary>
/// <value>
Added: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/OffsetAttribute.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/OffsetAttribute.cs?rev=1156294&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/OffsetAttribute.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/OffsetAttribute.cs Wed Aug 10 18:25:15 2011
@@ -0,0 +1,141 @@
+// -----------------------------------------------------------------------
+// <copyright company="Apache" file="OffsetAttribute.cs">
+//
+// 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.
+//
+// </copyright>
+// -----------------------------------------------------------------------
+
+namespace Lucene.Net.Analysis.TokenAttributes
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using Lucene.Net.Util;
+
+ /// <summary>
+ /// The start and end character offset of a <see cref="Token"/>.
+ /// </summary>
+ public class OffsetAttribute : AttributeBase, IOffsetAttribute
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="OffsetAttribute"/> class.
+ /// </summary>
+ public OffsetAttribute()
+ : this(0, 0)
+ {
+ }
+
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="OffsetAttribute"/> class.
+ /// </summary>
+ /// <param name="start">The start.</param>
+ /// <param name="end">The end.</param>
+ public OffsetAttribute(int start, int end)
+ {
+ this.SetOffset(start, end);
+ }
+
+
+ /// <summary>
+ /// Gets or sets the start of the offset.
+ /// </summary>
+ /// <value>The offset start.</value>
+ /// <remarks>
+ /// The difference between the offset's start and end
+ /// may not be equal to the length of the term text.
+ /// The term text may have been altered by a stemmer
+ /// some other filter
+ /// </remarks>
+ public int OffsetStart { get; set; }
+
+ /// <summary>
+ /// Gets or sets the end of the offset.
+ /// </summary>
+ /// <value>The offset end.</value>
+ /// <remarks>
+ /// This will be the end of the offset. Which is one greater than
+ /// the position of the last character corresponding to this token
+ /// in the source text. The length of the token in the source text
+ /// is the <c>OffsetEnd</c> - <c>OffsetStart</c>
+ /// </remarks>
+ public int OffsetEnd { get; set; }
+
+ /// <summary>
+ /// Clears the instance.
+ /// </summary>
+ public override void Clear()
+ {
+ this.SetOffset(0, 0);
+ }
+
+ /// <summary>
+ /// Copies the values to the target.
+ /// </summary>
+ /// <param name="attributeBase">The attribute base.</param>
+ public override void CopyTo(AttributeBase attributeBase)
+ {
+ IOffsetAttribute attribute = (IOffsetAttribute)attributeBase;
+ attribute.SetOffset(this.OffsetStart, this.OffsetEnd);
+ }
+
+ /// <summary>
+ /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
+ /// </summary>
+ /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
+ /// <returns>
+ /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
+ /// </returns>
+ public override bool Equals(object obj)
+ {
+ if (this == obj)
+ return true;
+
+ OffsetAttribute y = obj as OffsetAttribute;
+
+ return y != null &&
+ y.OffsetStart == this.OffsetStart &&
+ y.OffsetEnd == this.OffsetEnd;
+ }
+
+ /// <summary>
+ /// Returns a hash code for this instance.
+ /// </summary>
+ /// <returns>
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
+ /// </returns>
+ public override int GetHashCode()
+ {
+ int code = this.OffsetStart;
+ code = (code * 31) + this.OffsetEnd;
+ return code;
+ }
+
+
+ /// <summary>
+ /// Sets the offset.
+ /// </summary>
+ /// <param name="start">The start.</param>
+ /// <param name="end">The end.</param>
+ public void SetOffset(int start, int end)
+ {
+ this.OffsetStart = start;
+ this.OffsetEnd = end;
+ }
+ }
+}
\ No newline at end of file
Copied: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/PayloadAttribute.cs (from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/KeywordAttribute.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/PayloadAttribute.cs?p2=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/PayloadAttribute.cs&p1=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/KeywordAttribute.cs&r1=1156293&r2=1156294&rev=1156294&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/KeywordAttribute.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/PayloadAttribute.cs Wed Aug 10 18:25:15 2011
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
-// <copyright company="Apache" file="KeywordAttribute.cs">
+// <copyright company="Apache" file="PayloadAttribute.cs">
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
@@ -19,46 +19,71 @@
// </copyright>
// -----------------------------------------------------------------------
+
+
namespace Lucene.Net.Analysis.TokenAttributes
{
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
+ using Lucene.Net.Index;
+ using Lucene.Net.Util;
/// <summary>
- /// The attribute that can be used to make a token as a keyword. Keyword
- /// aware <see cref="TokenStream"/>s can decide to modify a token
- /// based on the return value of <see cref="IsKeyword"/>, if the token
- /// is modified. Stemming filters for instance can use this attribute
- /// to conditionally skip a term if <see cref="IsKeyword"/> returns <c>true</c>.
+ /// The payload of a Token.
/// </summary>
- public class KeywordAttribute : Util.AttributeBase, IKeywordAttribute
+ /// <seealso cref="Index.Payload"/>
+ public class PayloadAttribute : AttributeBase, IPayloadAttribute
{
/// <summary>
- /// Gets or sets a value indicating whether this instance is keyword.
+ /// Initializes a new instance of the <see cref="PayloadAttribute"/> class.
+ /// </summary>
+ public PayloadAttribute()
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="PayloadAttribute"/> class.
+ /// </summary>
+ /// <param name="payload">The payload.</param>
+ public PayloadAttribute(Payload payload)
+ {
+ this.Payload = payload;
+ }
+
+ /// <summary>
+ /// Gets or sets the payload.
/// </summary>
- /// <value>
- /// <c>true</c> if this instance is keyword; otherwise, <c>false</c>.
- /// </value>
- public bool IsKeyword { get; set; }
+ /// <value>The payload.</value>
+ public Index.Payload Payload { get; set; }
/// <summary>
/// Clears the instance.
/// </summary>
public override void Clear()
{
- this.IsKeyword = false;
+ this.Payload = null;
+ }
+
+ /// <summary>
+ /// Creates a clone of the object, generally shallow.
+ /// </summary>
+ /// <returns>an the clone of the current instance.</returns>
+ public override object Clone()
+ {
+ PayloadAttribute clone = (PayloadAttribute)this.MemberwiseClone();
+
+ if (this.Payload != null)
+ clone.Payload = (Payload)this.Payload.Clone();
+
+ return clone;
}
/// <summary>
- /// Copies to the target attribute base.
+ /// Copies this instance to the specified target.
/// </summary>
/// <param name="attributeBase">The attribute base.</param>
- public override void CopyTo(Util.AttributeBase attributeBase)
+ public override void CopyTo(AttributeBase attributeBase)
{
- IKeywordAttribute attr = (IKeywordAttribute)attributeBase;
- attr.IsKeyword = this.IsKeyword;
+ IPayloadAttribute attribute = (IPayloadAttribute)attributeBase;
+ attribute.Payload = this.Payload == null ? null : (Payload)this.Payload.Clone();
}
/// <summary>
@@ -73,11 +98,15 @@ namespace Lucene.Net.Analysis.TokenAttri
if (this == obj)
return true;
- if (this.GetType() != obj.GetType())
+ PayloadAttribute attribute = obj as PayloadAttribute;
+
+ if (attribute == null)
return false;
- KeywordAttribute y = obj as KeywordAttribute;
- return y != null && this.IsKeyword == y.IsKeyword;
+ if (attribute.Payload == null || this.Payload == null)
+ return attribute.Payload == null && this.Payload == null;
+
+ return attribute.Payload.Equals(this.Payload);
}
/// <summary>
@@ -88,7 +117,7 @@ namespace Lucene.Net.Analysis.TokenAttri
/// </returns>
public override int GetHashCode()
{
- return this.IsKeyword ? 31 : 37;
+ return this.Payload == null ? 0 : this.Payload.GetHashCode();
}
}
}
\ No newline at end of file
Added: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/PositionIncrementAttribute.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/PositionIncrementAttribute.cs?rev=1156294&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/PositionIncrementAttribute.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/PositionIncrementAttribute.cs Wed Aug 10 18:25:15 2011
@@ -0,0 +1,143 @@
+// -----------------------------------------------------------------------
+// <copyright company="Apache" file="PositionIncrementAttribute.cs">
+//
+// 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.
+//
+// </copyright>
+// -----------------------------------------------------------------------
+
+namespace Lucene.Net.Analysis.TokenAttributes
+{
+ using System;
+ using Lucene.Net.Util;
+
+ /// <summary>
+ /// The <see cref="PositionIncrement"/> determines the position of
+ /// this token relative to the previous <see cref="Token"/> in a
+ /// <see cref="TokenStream"/>. This is used in phrase searching.
+ /// </summary>
+ /// <remarks>
+ /// <para>
+ /// <b>Set the <see cref="PositionIncrement"/> to Zero</b> to put multiple terms
+ /// in the same position. An example of this would be if a word has multiple
+ /// stems. A Search for phrases that includes either stem will match. In
+ /// this case, all but the first stem's <see cref="PositionIncrement"/> should be
+ /// set to zero.
+ /// </para>
+ /// <para>
+ /// The increment of the first instance should be one.
+ /// Repeating a token with an increment of zero can also be used
+ /// to boost the scores of matches of that token
+ /// </para>
+ /// <para>
+ /// <b>Set the <see cref="PositionIncrement"/> to values greater than one</b> to in
+ /// inhibit exact phrase matches. For example, if one does not want phrases to match
+ /// across remove stop words, then one could build a stop word filter that removes stop
+ /// words. It can also set the <see cref="PositionIncrement"/> to the number of stop
+ /// words remove before each non-stop word. Exact phrase queries will then only match
+ /// when the terms occurs with no intervening stop words.
+ /// </para>
+ /// </remarks>
+ /// <seealso cref="Lucene.Net.Index.DocsAndPositionEnumerator"/>
+ public class PositionIncrementAttribute : AttributeBase, IPositionIncrementAttribute
+ {
+ private int positionIncrement = 1;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="PositionIncrementAttribute"/> class.
+ /// </summary>
+ public PositionIncrementAttribute()
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="PositionIncrementAttribute"/> class.
+ /// </summary>
+ /// <param name="positionIncrement">The position increment.</param>
+ public PositionIncrementAttribute(int positionIncrement)
+ {
+ this.PositionIncrement = positionIncrement;
+ }
+
+ /// <summary>
+ /// Gets or sets the position increment. The default value is one.
+ /// </summary>
+ /// <value>The position increment. The default value is one.</value>
+ /// <exception cref="ArgumentOutOfRangeException">Throws when the value being set is less than zero.</exception>
+ public int PositionIncrement
+ {
+ get
+ {
+ return this.positionIncrement;
+ }
+
+ set
+ {
+ if (value < 0)
+ throw new ArgumentOutOfRangeException(
+ "value",
+ "The position increment 'value' must be greater than 0.");
+
+ this.positionIncrement = value;
+ }
+ }
+
+ /// <summary>
+ /// Clears the instance.
+ /// </summary>
+ public override void Clear()
+ {
+ this.positionIncrement = 1;
+ }
+
+ /// <summary>
+ /// Copies this instance to the specified target.
+ /// </summary>
+ /// <param name="attributeBase">The attribute base.</param>
+ public override void CopyTo(AttributeBase attributeBase)
+ {
+ IPositionIncrementAttribute attribute = (IPositionIncrementAttribute)attributeBase;
+ attribute.PositionIncrement = this.PositionIncrement;
+ }
+
+ /// <summary>
+ /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
+ /// </summary>
+ /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
+ /// <returns>
+ /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
+ /// </returns>
+ public override bool Equals(object obj)
+ {
+ if (obj == this)
+ return true;
+
+ PositionIncrementAttribute attribute = obj as PositionIncrementAttribute;
+ return attribute != null && attribute.PositionIncrement == this.PositionIncrement;
+ }
+
+ /// <summary>
+ /// Returns a hash code for this instance.
+ /// </summary>
+ /// <returns>
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
+ /// </returns>
+ public override int GetHashCode()
+ {
+ return this.PositionIncrement;
+ }
+ }
+}
\ No newline at end of file
Copied: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/TypeAttribute.cs (from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/KeywordAttribute.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/TypeAttribute.cs?p2=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/TypeAttribute.cs&p1=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/KeywordAttribute.cs&r1=1156293&r2=1156294&rev=1156294&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/KeywordAttribute.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenAttributes/TypeAttribute.cs Wed Aug 10 18:25:15 2011
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
-// <copyright company="Apache" file="KeywordAttribute.cs">
+// <copyright company="Apache" file="TypeAttribute.cs">
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
@@ -25,40 +25,66 @@ namespace Lucene.Net.Analysis.TokenAttri
using System.Collections.Generic;
using System.Linq;
using System.Text;
+ using Lucene.Net.Util;
/// <summary>
- /// The attribute that can be used to make a token as a keyword. Keyword
- /// aware <see cref="TokenStream"/>s can decide to modify a token
- /// based on the return value of <see cref="IsKeyword"/>, if the token
- /// is modified. Stemming filters for instance can use this attribute
- /// to conditionally skip a term if <see cref="IsKeyword"/> returns <c>true</c>.
+ /// A <see cref="Token"/>'s lexical type. The default value is 'word'.
/// </summary>
- public class KeywordAttribute : Util.AttributeBase, IKeywordAttribute
+ public class TypeAttribute : AttributeBase, ITypeAttribute
{
/// <summary>
- /// Gets or sets a value indicating whether this instance is keyword.
+ /// The default type for the <see cref="Token"/>'s lexical type.
/// </summary>
- /// <value>
- /// <c>true</c> if this instance is keyword; otherwise, <c>false</c>.
- /// </value>
- public bool IsKeyword { get; set; }
+ public const string DefaultType = "word";
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TypeAttribute"/> class.
+ /// </summary>
+ public TypeAttribute()
+ : this(DefaultType)
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="TypeAttribute"/> class.
+ /// </summary>
+ /// <param name="type">The type.</param>
+ public TypeAttribute(string type)
+ {
+ this.Type = type;
+ }
+
+ /// <summary>
+ /// Gets or sets the <see cref="Token"/>'s lexical type.
+ /// </summary>
+ /// <value>The type.</value>
+ public string Type { get; set; }
/// <summary>
/// Clears the instance.
/// </summary>
public override void Clear()
{
- this.IsKeyword = false;
+ this.Type = DefaultType;
}
/// <summary>
- /// Copies to the target attribute base.
+ /// Creates a clone of the object, generally shallow.
+ /// </summary>
+ /// <returns>an the clone of the current instance.</returns>
+ public override object Clone()
+ {
+ return new TypeAttribute() { Type = this.Type };
+ }
+
+ /// <summary>
+ /// Copies this instance to the specified target.
/// </summary>
/// <param name="attributeBase">The attribute base.</param>
- public override void CopyTo(Util.AttributeBase attributeBase)
+ public override void CopyTo(AttributeBase attributeBase)
{
- IKeywordAttribute attr = (IKeywordAttribute)attributeBase;
- attr.IsKeyword = this.IsKeyword;
+ ITypeAttribute attribute = (ITypeAttribute)attributeBase;
+ attribute.Type = this.Type;
}
/// <summary>
@@ -66,18 +92,16 @@ namespace Lucene.Net.Analysis.TokenAttri
/// </summary>
/// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
/// <returns>
- /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
+ /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
/// </returns>
public override bool Equals(object obj)
{
- if (this == obj)
+ if (obj == this)
return true;
- if (this.GetType() != obj.GetType())
- return false;
+ TypeAttribute attribute = obj as TypeAttribute;
- KeywordAttribute y = obj as KeywordAttribute;
- return y != null && this.IsKeyword == y.IsKeyword;
+ return attribute != null && attribute.Type.Equals(this.Type);
}
/// <summary>
@@ -88,7 +112,7 @@ namespace Lucene.Net.Analysis.TokenAttri
/// </returns>
public override int GetHashCode()
{
- return this.IsKeyword ? 31 : 37;
- }
+ return this.Type.GetHashCode();
+ }
}
}
\ No newline at end of file
Modified: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs?rev=1156294&r1=1156293&r2=1156294&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs Wed Aug 10 18:25:15 2011
@@ -27,7 +27,7 @@ namespace Lucene.Net.Analysis
using System.Text;
/// <summary>
- /// TODO: update
+ /// TODO: port
/// </summary>
public class TokenStream
{
Copied: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Index/DocsAndPositionEnumerator.cs (from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Index/DocsAndPositionEnumerator.cs?p2=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Index/DocsAndPositionEnumerator.cs&p1=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs&r1=1156293&r2=1156294&rev=1156294&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Index/DocsAndPositionEnumerator.cs Wed Aug 10 18:25:15 2011
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
-// <copyright company="Apache" file="TokenStream.cs">
+// <copyright company="Apache" file="DocsAndPositionEnumerator.cs">
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
@@ -19,7 +19,7 @@
// </copyright>
// -----------------------------------------------------------------------
-namespace Lucene.Net.Analysis
+namespace Lucene.Net.Index
{
using System;
using System.Collections.Generic;
@@ -27,9 +27,9 @@ namespace Lucene.Net.Analysis
using System.Text;
/// <summary>
- /// TODO: update
+ /// TODO: port
/// </summary>
- public class TokenStream
+ public class DocsAndPositionEnumerator
{
}
}
\ No newline at end of file
Added: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Index/Payload.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Index/Payload.cs?rev=1156294&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Index/Payload.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Index/Payload.cs Wed Aug 10 18:25:15 2011
@@ -0,0 +1,240 @@
+// -----------------------------------------------------------------------
+// <copyright company="Apache" file="Payload.cs">
+//
+// 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.
+//
+// </copyright>
+// -----------------------------------------------------------------------
+
+
+
+namespace Lucene.Net.Index
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using Lucene.Net.Support;
+ using Util;
+
+ /// <summary>
+ /// TODO: port
+ /// </summary>
+ public class Payload : ICloneable
+ {
+ private byte[] data;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Payload"/> class. This
+ /// constructor will create an empty payload with a null for the <see cref="Data"/>.
+ /// </summary>
+ public Payload()
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="Payload"/> class.
+ /// </summary>
+ /// <param name="data">The data.</param>
+ /// <param name="offset">The offset.</param>
+ /// <param name="limit">The limit.</param>
+ public Payload(byte[] data, int offset = 0, int limit = 0)
+ {
+ this.SetData(data, offset, limit);
+ }
+
+ /// <summary>
+ /// Gets or sets the offset.
+ /// </summary>
+ /// <value>The offset.</value>
+ public int Offset { get; set; }
+
+ /// <summary>
+ /// Gets or sets the length.
+ /// </summary>
+ /// <value>The length.</value>
+ public int Length { get; protected set; }
+
+ /// <summary>
+ /// Gets or sets the data.
+ /// </summary>
+ /// <value>The data.</value>
+ public byte[] Data
+ {
+ get
+ {
+ return this.data;
+ }
+
+ set
+ {
+ this.SetData(value);
+ }
+ }
+
+ /// <summary>
+ /// Retrieves the byte at the given index. Similar to CharAt
+ /// </summary>
+ /// <param name="index">The index.</param>
+ /// <returns>An instance of <see cref="Byte"/>.</returns>
+ /// <exception cref="IndexOutOfRangeException">
+ /// Thrown when the specified index is less than 0 or greater than
+ /// or equal to the <see cref="Length"/>
+ /// </exception>
+ public virtual byte ByteAt(int index)
+ {
+ if (0 <= index && index < this.Length)
+ return this.Data[this.Offset + index];
+
+ throw new IndexOutOfRangeException(
+ string.Format(
+ "The index must be greater than 0 and less than the length '{0}', The index was '{1}'",
+ this.Length,
+ index));
+ }
+
+ /// <summary>
+ /// Creates a clone of the object, generally shallow.
+ /// </summary>
+ /// <returns>an the clone of the current instance.</returns>
+ public object Clone()
+ {
+ Payload clone = (Payload)this.MemberwiseClone();
+
+ if (this.Offset == 0 && this.Length == this.Data.Length)
+ {
+ clone.data = new byte[this.Data.Length];
+ this.CopyTo(clone.data);
+ }
+ else
+ {
+ clone.data = this.ToByteArray();
+ clone.Offset = 0;
+ }
+
+ return clone;
+ }
+
+ /// <summary>
+ /// Copies the payload data to a byte array.
+ /// </summary>
+ /// <param name="target">The target.</param>
+ /// <param name="offset">The offset of the target. The default is 0.</param>
+ /// <exception cref="ArgumentNullException">
+ /// Thrown when <paramref name="target"/> is null.
+ /// </exception>
+ /// <exception cref="IndexOutOfRangeException">
+ /// Thrown when this instances <see cref="Length"/> is greater than
+ /// the combined target length and offset.
+ /// </exception>
+ public virtual void CopyTo(byte[] target, int offset = 0)
+ {
+ if (target == null)
+ throw new ArgumentNullException("target");
+
+ if (this.Length > target.Length + offset)
+ throw new IndexOutOfRangeException(
+ string.Format(
+ "The combined target length and offset '{0}' must be smaller the payload length '{1}' ",
+ target.Length + offset,
+ this.Length));
+
+ Array.Copy(this.Data, this.Offset, target, offset, this.Length);
+ }
+
+ /// <summary>
+ /// Determines whether the specified <see cref="System.Object"/> is equal to this instance.
+ /// </summary>
+ /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param>
+ /// <returns>
+ /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; otherwise, <c>false</c>.
+ /// </returns>
+ public override bool Equals(object obj)
+ {
+ if (obj == this)
+ return true;
+
+ if (!(obj is Payload))
+ return false;
+
+ Payload payload = (Payload)obj;
+
+ if (this.Length == payload.Length)
+ {
+ for (int i = 0; i < this.Length; i++)
+ {
+ if (this.Data[this.Offset + i] != payload.Data[payload.Offset + i])
+ return false;
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+
+ /// <summary>
+ /// Returns a hash code for this instance.
+ /// </summary>
+ /// <returns>
+ /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
+ /// </returns>
+ public override int GetHashCode()
+ {
+ return this.Data.CreateHashCode(this.Offset, this.Offset + this.Length);
+ }
+
+ /// <summary>
+ /// Sets the payload data. A reference to the passed-in aray is held but
+ /// not copied
+ /// </summary>
+ /// <param name="data">The data.</param>
+ /// <param name="offset">The offset of the data.</param>
+ /// <param name="length">The length of the data.</param>
+ /// <exception cref="ArgumentException">
+ /// Thrown when <paramref name="offset"/> is less than 0
+ /// or when the <paramref name="offset"/> and <paramref name="length"/>
+ /// is greater than <paramref name="data"/>'s length.
+ /// </exception>
+ public void SetData(byte[] data, int offset = 0, int length = 0)
+ {
+ if (offset < 0 || (offset + length) > data.Length)
+ throw new ArgumentException(
+ string.Format(
+ "The offset must be 0 or greater and the offset and length " +
+ "combined must be less that length of byte[]. The offset was '{0}' ",
+ offset),
+ "offset");
+
+ this.data = data;
+ this.Offset = offset;
+ this.Length = length == 0 ? data.Length : length;
+ }
+
+ /// <summary>
+ /// Allocates a new byte array. Then copies the payload data into the new array
+ /// and returns it.
+ /// </summary>
+ /// <returns>An instance of <see cref="T:System.Byte[]"/>.</returns>
+ public virtual byte[] ToByteArray()
+ {
+ byte[] copy = new byte[this.Length];
+ Array.Copy(this.Data, this.Offset, copy, 0, this.Length);
+
+ return copy;
+ }
+ }
+}
\ No newline at end of file
Copied: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Index/TermsHashPerField.cs (from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Index/TermsHashPerField.cs?p2=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Index/TermsHashPerField.cs&p1=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs&r1=1156293&r2=1156294&rev=1156294&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Index/TermsHashPerField.cs Wed Aug 10 18:25:15 2011
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
-// <copyright company="Apache" file="TokenStream.cs">
+// <copyright company="Apache" file="TermsHashPerField.cs">
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
@@ -19,7 +19,7 @@
// </copyright>
// -----------------------------------------------------------------------
-namespace Lucene.Net.Analysis
+namespace Lucene.Net.Index
{
using System;
using System.Collections.Generic;
@@ -27,9 +27,9 @@ namespace Lucene.Net.Analysis
using System.Text;
/// <summary>
- /// TODO: update
+ /// TODO: port
/// </summary>
- public class TokenStream
+ public class TermsHashPerField
{
}
}
\ No newline at end of file
Modified: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Lucene.Net.csproj
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Lucene.Net.csproj?rev=1156294&r1=1156293&r2=1156294&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Lucene.Net.csproj (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Lucene.Net.csproj Wed Aug 10 18:25:15 2011
@@ -45,13 +45,26 @@
<Reference Include="System.Xml.Serialization" />
</ItemGroup>
<ItemGroup>
+ <Compile Include="Analysis\Token.cs" />
<Compile Include="Analysis\TokenAttributes\CharTermAttribute.cs" />
<Compile Include="Analysis\TokenAttributes\ICharTermAttribute.cs" />
<Compile Include="Analysis\TokenAttributes\FlagsAttribute.cs" />
<Compile Include="Analysis\TokenAttributes\IFlagsAttribute.cs" />
<Compile Include="Analysis\TokenAttributes\IKeywordAttribute.cs" />
+ <Compile Include="Analysis\TokenAttributes\IOffsetAttribute.cs" />
+ <Compile Include="Analysis\TokenAttributes\IPayloadAttribute.cs" />
+ <Compile Include="Analysis\TokenAttributes\IPositionIncrementAttribute.cs" />
+ <Compile Include="Analysis\TokenAttributes\ITermToBytesRefAttribute.cs" />
+ <Compile Include="Analysis\TokenAttributes\ITypeAttribute.cs" />
<Compile Include="Analysis\TokenAttributes\KeywordAttribute.cs" />
+ <Compile Include="Analysis\TokenAttributes\OffsetAttribute.cs" />
+ <Compile Include="Analysis\TokenAttributes\PayloadAttribute.cs" />
+ <Compile Include="Analysis\TokenAttributes\PositionIncrementAttribute.cs" />
+ <Compile Include="Analysis\TokenAttributes\TypeAttribute.cs" />
<Compile Include="Analysis\TokenStream.cs" />
+ <Compile Include="Index\DocsAndPositionEnumerator.cs" />
+ <Compile Include="Index\Payload.cs" />
+ <Compile Include="Index\TermsHashPerField.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Support\BaseDictionaryOfTKeyTValue.cs" />
<Compile Include="Support\ICloneable.cs" />
@@ -64,6 +77,7 @@
<Compile Include="Util\ArrayUtil.cs" />
<Compile Include="Util\AttributeBase.cs" />
<Compile Include="Util\AttributeSource.cs" />
+ <Compile Include="Util\BytesRef.cs" />
<Compile Include="Util\IAttribute.cs" />
<Compile Include="Util\RamUsageEstimator.cs" />
</ItemGroup>
Modified: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/AttributeBase.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/AttributeBase.cs?rev=1156294&r1=1156293&r2=1156294&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/AttributeBase.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/AttributeBase.cs Wed Aug 10 18:25:15 2011
@@ -57,7 +57,7 @@ namespace Lucene.Net.Util
public abstract void Clear();
/// <summary>
- /// Copies to.
+ /// Copies this instance to the specified target.
/// </summary>
/// <param name="attributeBase">The attribute base.</param>
public abstract void CopyTo(AttributeBase attributeBase);
Copied: incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs (from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs?p2=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs&p1=incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs&r1=1156293&r2=1156294&rev=1156294&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Analysis/TokenStream.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/src/Lucene.Net/Util/BytesRef.cs Wed Aug 10 18:25:15 2011
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
-// <copyright company="Apache" file="TokenStream.cs">
+// <copyright company="Apache" file="BytesRef.cs">
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
@@ -19,7 +19,7 @@
// </copyright>
// -----------------------------------------------------------------------
-namespace Lucene.Net.Analysis
+namespace Lucene.Net.Util
{
using System;
using System.Collections.Generic;
@@ -27,9 +27,18 @@ namespace Lucene.Net.Analysis
using System.Text;
/// <summary>
- /// TODO: update
+ /// TODO: port
/// </summary>
- public class TokenStream
+ public sealed class BytesRef : IComparable<BytesRef>
{
+ /// <summary>
+ /// Compares this instance to the other <see cref="BytesRef"/> instance.
+ /// </summary>
+ /// <param name="other">The other.</param>
+ /// <returns>An instance of <see cref="Int32"/>.</returns>
+ public int CompareTo(BytesRef other)
+ {
+ throw new NotImplementedException();
+ }
}
}
\ No newline at end of file
Modified: incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/CharTermAttributeTest.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/CharTermAttributeTest.cs?rev=1156294&r1=1156293&r2=1156294&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/CharTermAttributeTest.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/CharTermAttributeTest.cs Wed Aug 10 18:25:15 2011
@@ -42,7 +42,7 @@ namespace Lucene.Net.Analysis.TokenAttri
[TestFixture]
[Category(Categories.Unit)]
- [Parallelizable]
+ [Parallelizable(TestScope.Descendants)]
public class CharTermAttributeTest
{
/*
Modified: incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/FlagsAttributeTest.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/FlagsAttributeTest.cs?rev=1156294&r1=1156293&r2=1156294&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/FlagsAttributeTest.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/FlagsAttributeTest.cs Wed Aug 10 18:25:15 2011
@@ -39,7 +39,7 @@ namespace Lucene.Net.Analysis.TokenAttri
[TestFixture]
[Category(TestCategories.Unit)]
- [Parallelizable]
+ [Parallelizable(TestScope.Descendants)]
public class FlagsAttributeTest
{
[Test]
Copied: incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/OffsetAttributeTest.cs (from r1156293, incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/FlagsAttributeTest.cs)
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/OffsetAttributeTest.cs?p2=incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/OffsetAttributeTest.cs&p1=incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/FlagsAttributeTest.cs&r1=1156293&r2=1156294&rev=1156294&view=diff
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/FlagsAttributeTest.cs (original)
+++ incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/OffsetAttributeTest.cs Wed Aug 10 18:25:15 2011
@@ -1,5 +1,5 @@
// -----------------------------------------------------------------------
-// <copyright file="FlagsAttributeTest.cs" company="Apache">
+// <copyright company="Apache" file="OffsetAttributeTest.cs" >
//
// Licensed to the Apache Software Foundation (ASF) under one or more
// contributor license agreements. See the NOTICE file distributed with
@@ -21,101 +21,92 @@
namespace Lucene.Net.Analysis.TokenAttributes
{
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
-
- using Lucene.Net.Util;
-
#if NUNIT
using NUnit.Framework;
using Extensions.NUnit;
-#else
+#else
using Gallio.Framework;
using MbUnit.Framework;
#endif
-
-
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using Lucene.Net.Util;
+
+
[TestFixture]
[Category(TestCategories.Unit)]
- [Parallelizable]
- public class FlagsAttributeTest
+ [Parallelizable(TestScope.Descendants)]
+ public class OffsetAttributeTest
{
- [Test]
- public void Flags()
- {
- var attribute = new FlagsAttribute { Flags = 5 };
- Assert.AreEqual(5, attribute.Flags);
- }
[Test]
- public void Clear()
+ public void ClearOverride()
{
- var attribute = new FlagsAttribute { Flags = 5 };
- Assert.AreEqual(5, attribute.Flags);
+ var attribute = new OffsetAttribute(3, 20);
+ Assert.AreEqual(3, attribute.OffsetStart);
+ Assert.AreEqual(20, attribute.OffsetEnd);
attribute.Clear();
- Assert.AreEqual(0, attribute.Flags);
+
+ Assert.AreEqual(0, attribute.OffsetStart);
+ Assert.AreEqual(0, attribute.OffsetEnd);
}
[Test]
- public void Clone()
+ public void CopyToOverride()
{
- var attribute = new FlagsAttribute { Flags = 5 };
- Assert.AreEqual(5, attribute.Flags);
+ var attribute = new OffsetAttribute(3, 20);
+ var target = new OffsetAttributeLookalike();
- var clone = attribute.Clone() as FlagsAttribute;
- Assert.IsNotNull(clone);
- Assert.AreEqual(5, clone.Flags);
- }
-
- [Test]
- public void CopyTo()
- {
- var attribute = new FlagsAttribute { Flags = 5 };
- Assert.AreEqual(5, attribute.Flags);
+ Assert.AreEqual(0, target.OffsetStart);
+ Assert.AreEqual(0, target.OffsetEnd);
- var copy = new FlagsAttribute();
- attribute.CopyTo(copy);
-
- Assert.AreEqual(5, copy.Flags);
- }
-
- [Test]
- public void CopyTo_WithArgumentException()
- {
- var attribute = new FlagsAttribute { Flags = 5 };
- Assert.AreEqual(5, attribute.Flags);
+ attribute.CopyTo(target);
- Assert.Throws<ArgumentException>(() => attribute.CopyTo(new NonFlagAttribute()));
+ Assert.AreEqual(3, target.OffsetStart);
+ Assert.AreEqual(20, target.OffsetEnd);
}
[Test]
public void EqualsOverride()
{
- var attribute = new FlagsAttribute { Flags = 25 };
- Assert.AreEqual(25, attribute.Flags);
-
- var y = new FlagsAttribute { Flags = 25 };
-
- Assert.IsTrue(attribute.Equals(y));
+ var attribute = new OffsetAttribute(5, 30);
+ var equalAttribute = new OffsetAttribute(5, 30);
+ var notEqualAttribute = new OffsetAttribute();
+ const int wrongType = 45;
+
+ Assert.IsTrue(attribute.Equals(equalAttribute));
+ Assert.IsFalse(attribute.Equals(notEqualAttribute));
+ Assert.IsFalse(attribute.Equals(wrongType));
}
[Test]
public void GetHashCodeOverride()
{
- var attribute = new FlagsAttribute { Flags = 25 };
- Assert.AreEqual(25, attribute.Flags);
+ var attribute = new OffsetAttribute(5, 30);
+ int code = 5;
+ code = (code * 31) + 30;
- Assert.AreEqual(25, attribute.GetHashCode());
+ Assert.AreEqual(code, attribute.GetHashCode());
}
#region helpers
- private class NonFlagAttribute : AttributeBase
+ internal class OffsetAttributeLookalike : AttributeBase, IOffsetAttribute
{
+ public int OffsetStart { get; set; }
+
+ public int OffsetEnd { get; set; }
+
+ public void SetOffset(int start, int end)
+ {
+ this.OffsetStart = start;
+ this.OffsetEnd = end;
+ }
+
public override void Clear()
{
throw new NotImplementedException();
Added: incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/PayloadAttributeTest.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/PayloadAttributeTest.cs?rev=1156294&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/PayloadAttributeTest.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/PayloadAttributeTest.cs Wed Aug 10 18:25:15 2011
@@ -0,0 +1,136 @@
+// -----------------------------------------------------------------------
+// <copyright company="Apache" file="PayloadAttributeTest.cs" >
+//
+// 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.
+//
+// </copyright>
+// -----------------------------------------------------------------------
+
+using Lucene.Net.Index;
+
+namespace Lucene.Net.Analysis.TokenAttributes
+{
+#if NUNIT
+ using NUnit.Framework;
+ using Extensions.NUnit;
+#else
+ using Gallio.Framework;
+ using MbUnit.Framework;
+#endif
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using Lucene.Net.Util;
+
+
+ [TestFixture]
+ [Category(TestCategories.Unit)]
+ [Parallelizable(TestScope.Descendants)]
+ public class PayloadAttributeTest
+ {
+
+ [Test]
+ public void ClearOverride()
+ {
+ var attribute = new PayloadAttribute(new Payload());
+ Assert.IsNotNull(attribute.Payload);
+
+ attribute.Clear();
+ Assert.IsNull(attribute.Payload);
+ }
+
+ [Test]
+ public void CloneOverride()
+ {
+ var attribute = new PayloadAttribute();
+ var clone = (PayloadAttribute)attribute.Clone();
+
+ Assert.AreEqual(attribute, clone);
+ Assert.IsNull(clone.Payload);
+
+ attribute.Payload = new Payload();
+ clone = (PayloadAttribute)attribute.Clone();
+
+
+ Assert.IsNotNull(clone.Payload);
+ Assert.AreEqual(attribute.Payload, clone.Payload);
+ }
+
+ [Test]
+ public void CopyToOverride()
+ {
+ var attribute = new PayloadAttribute(new Payload());
+ var target = new PayloadAttributeLookAlike();
+ Assert.IsNull(target.Payload);
+
+ attribute.CopyTo(target);
+ Assert.AreEqual(attribute.Payload, target.Payload);
+ }
+
+ [Test]
+ public void EqualsOverride()
+ {
+ var attribute = new PayloadAttribute(new Payload());
+ var equalAttribute = new PayloadAttribute(new Payload());
+ var notEqualAttribute = new PayloadAttribute();
+ const int wrongType = 55;
+
+ Assert.IsTrue(attribute.Equals(equalAttribute));
+ Assert.IsFalse(attribute.Equals(notEqualAttribute));
+ Assert.IsFalse(attribute.Equals(wrongType));
+
+ attribute.Clear();
+
+ Assert.IsTrue(attribute.Equals(new PayloadAttribute()));
+ }
+
+ [Test]
+ public void GetHashCodeOverride()
+ {
+ var attribute = new PayloadAttribute();
+ Assert.AreEqual(0, attribute.GetHashCode());
+
+ attribute.Payload = new Payload();
+
+ Assert.AreEqual(attribute.Payload.GetHashCode(), attribute.GetHashCode());
+
+ }
+
+ #region helpers
+
+ internal class PayloadAttributeLookAlike : AttributeBase, IPayloadAttribute
+ {
+
+
+ public Payload Payload { get; set; }
+
+ public override void Clear()
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void CopyTo(AttributeBase attributeBase)
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+
+ #endregion
+
+ }
+}
Added: incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/PositionIncrementAttributeTest.cs
URL: http://svn.apache.org/viewvc/incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/PositionIncrementAttributeTest.cs?rev=1156294&view=auto
==============================================================================
--- incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/PositionIncrementAttributeTest.cs (added)
+++ incubator/lucene.net/branches/Lucene.Net_4e/test/Lucene.Net.Test/Analysis/TokenAttributes/PositionIncrementAttributeTest.cs Wed Aug 10 18:25:15 2011
@@ -0,0 +1,127 @@
+// -----------------------------------------------------------------------
+// <copyright company="Apache" file="PositionIncrementAttributeTest.cs" >
+//
+// 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.
+//
+// </copyright>
+// -----------------------------------------------------------------------
+
+namespace Lucene.Net.Analysis.TokenAttributes
+{
+#if NUNIT
+ using NUnit.Framework;
+ using Extensions.NUnit;
+#else
+ using Gallio.Framework;
+ using MbUnit.Framework;
+#endif
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+ using Lucene.Net.Util;
+
+
+ [TestFixture]
+ [Category(TestCategories.Unit)]
+ [Parallelizable(TestScope.Descendants)]
+ public class PositionIncrementAttributeTest
+ {
+
+ [Test]
+ public void SettingPositionIncrement_ThrowsArgumentOutOfRangeException()
+ {
+ var attribute = new PositionIncrementAttribute();
+
+ Assert.Throws<ArgumentOutOfRangeException>(() => {
+ attribute.PositionIncrement = -1;
+ });
+
+ Assert.DoesNotThrow(() => {
+ attribute.PositionIncrement = 1;
+ });
+ }
+
+ [Test]
+ public void ClearOverride()
+ {
+ var attribute = new PositionIncrementAttribute(23);
+ Assert.AreEqual(23, attribute.PositionIncrement);
+
+ attribute.Clear();
+
+ Assert.AreEqual(1, attribute.PositionIncrement);
+ }
+
+ [Test]
+ public void CopyToOverride()
+ {
+ var attribute = new PositionIncrementAttribute(35);
+ var target = new PositionIncrementLookAlike();
+ Assert.AreEqual(1, target.PositionIncrement);
+
+ attribute.CopyTo(target);
+ Assert.AreEqual(35, target.PositionIncrement);
+ }
+
+ [Test]
+ public void EqualsOverride()
+ {
+ var attribute = new PositionIncrementAttribute(12);
+ var equalAttribute = new PositionIncrementAttribute(12);
+ var notEqualAttribute = new PositionIncrementAttribute();
+ const string wrongType = "test";
+
+ Assert.IsTrue(attribute.Equals(equalAttribute));
+ Assert.IsFalse(attribute.Equals(notEqualAttribute));
+ Assert.IsFalse(attribute.Equals(wrongType));
+ }
+
+ [Test]
+ public void GetHashCodeOverride()
+ {
+ var attribute = new PositionIncrementAttribute();
+ Assert.AreEqual(1, attribute.GetHashCode());
+
+ attribute.PositionIncrement = 23;
+ Assert.AreEqual(23, attribute.GetHashCode());
+ }
+
+ #region helper
+
+ internal class PositionIncrementLookAlike : AttributeBase, IPositionIncrementAttribute
+ {
+ public PositionIncrementLookAlike()
+ {
+ this.PositionIncrement = 1;
+ }
+
+ public override void Clear()
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void CopyTo(AttributeBase attributeBase)
+ {
+ throw new NotImplementedException();
+ }
+
+ public int PositionIncrement { get; set; }
+ }
+
+ #endregion
+ }
+}