示例#1
0
            public override void SetReusableComponents(Analyzer analyzer, string fieldName, TokenStreamComponents components)
            {
                IDictionary <string, TokenStreamComponents> componentsPerField = (IDictionary <string, TokenStreamComponents>)GetStoredValue(analyzer);

                if (componentsPerField == null)
                {
                    componentsPerField = new Dictionary <string, TokenStreamComponents>();
                    SetStoredValue(analyzer, componentsPerField);
                }
                componentsPerField[fieldName] = components;
            }
示例#2
0
            public override void SetReusableComponents(Analyzer analyzer, string fieldName, TokenStreamComponents components)
            {
                var componentsPerField = (IDictionary <string, TokenStreamComponents>)GetStoredValue(analyzer);

                if (componentsPerField == null)
                {
                    // LUCENENET-615: This needs to support nullable keys
                    componentsPerField = new JCG.Dictionary <string, TokenStreamComponents>();
                    SetStoredValue(analyzer, componentsPerField);
                }
                componentsPerField[fieldName] = components;
            }
示例#3
0
        /// <summary>
        /// Returns a TokenStream suitable for <code>fieldName</code>, tokenizing
        /// the contents of <code>text</code>.
        /// <p>
        /// this method uses <seealso cref="#createComponents(String, Reader)"/> to obtain an
        /// instance of <seealso cref="TokenStreamComponents"/>. It returns the sink of the
        /// components and stores the components internally. Subsequent calls to this
        /// method will reuse the previously stored components after resetting them
        /// through <seealso cref="TokenStreamComponents#setReader(Reader)"/>.
        /// <p>
        /// <b>NOTE:</b> After calling this method, the consumer must follow the
        /// workflow described in <seealso cref="TokenStream"/> to properly consume its contents.
        /// See the <seealso cref="Lucene.Net.Analysis Analysis package documentation"/> for
        /// some examples demonstrating this.
        /// </summary>
        /// <param name="fieldName"> the name of the field the created TokenStream is used for </param>
        /// <param name="text"> the String the streams source reads from </param>
        /// <returns> TokenStream for iterating the analyzed content of <code>reader</code> </returns>
        /// <exception cref="AlreadyClosedException"> if the Analyzer is closed. </exception>
        /// <exception cref="IOException"> if an i/o error occurs (may rarely happen for strings). </exception>
        /// <seealso cref= #tokenStream(String, Reader) </seealso>
        public TokenStream TokenStream(string fieldName, TextReader reader)
        {
            TokenStreamComponents components = ReuseStrategy_Renamed.GetReusableComponents(this, fieldName);
            TextReader            r          = InitReader(fieldName, reader);

            if (components == null)
            {
                components = CreateComponents(fieldName, r);
                ReuseStrategy_Renamed.SetReusableComponents(this, fieldName, components);
            }
            else
            {
                components.Reader = r;//new TextReaderWrapper(r);
            }
            return(components.TokenStream);
        }
示例#4
0
        /// <summary>
        /// Returns a <see cref="TokenStream"/> suitable for <paramref name="fieldName"/>, tokenizing
        /// the contents of <c>text</c>.
        /// <para/>
        /// This method uses <see cref="CreateComponents(string, TextReader)"/> to obtain an
        /// instance of <see cref="TokenStreamComponents"/>. It returns the sink of the
        /// components and stores the components internally. Subsequent calls to this
        /// method will reuse the previously stored components after resetting them
        /// through <see cref="TokenStreamComponents.SetReader(TextReader)"/>.
        /// <para/>
        /// <b>NOTE:</b> After calling this method, the consumer must follow the
        /// workflow described in <see cref="Analysis.TokenStream"/> to properly consume its contents.
        /// See the <see cref="Lucene.Net.Analysis"/> namespace documentation for
        /// some examples demonstrating this.
        /// </summary>
        /// <param name="fieldName"> the name of the field the created <see cref="Analysis.TokenStream"/> is used for </param>
        /// <param name="reader"> the reader the streams source reads from </param>
        /// <returns> <see cref="Analysis.TokenStream"/> for iterating the analyzed content of <see cref="TextReader"/> </returns>
        /// <exception cref="ObjectDisposedException"> if the Analyzer is disposed. </exception>
        /// <exception cref="IOException"> if an i/o error occurs (may rarely happen for strings). </exception>
        /// <seealso cref="GetTokenStream(string, string)"/>
        public TokenStream GetTokenStream(string fieldName, TextReader reader)
        {
            TokenStreamComponents components = reuseStrategy.GetReusableComponents(this, fieldName);
            TextReader            r          = InitReader(fieldName, reader);

            if (components == null)
            {
                components = CreateComponents(fieldName, r);
                reuseStrategy.SetReusableComponents(this, fieldName, components);
            }
            else
            {
                components.SetReader(r);
            }
            return(components.TokenStream);
        }
示例#5
0
        /// <summary>
        /// Returns a <see cref="Analysis.TokenStream"/> suitable for <paramref name="fieldName"/>, tokenizing
        /// the contents of <paramref name="text"/>.
        /// <para/>
        /// This method uses <see cref="CreateComponents(string, TextReader)"/> to obtain an
        /// instance of <see cref="TokenStreamComponents"/>. It returns the sink of the
        /// components and stores the components internally. Subsequent calls to this
        /// method will reuse the previously stored components after resetting them
        /// through <see cref="TokenStreamComponents.SetReader(TextReader)"/>.
        /// <para/>
        /// <b>NOTE:</b> After calling this method, the consumer must follow the
        /// workflow described in <see cref="Analysis.TokenStream"/> to properly consume its contents.
        /// See the <see cref="Lucene.Net.Analysis"/> namespace documentation for
        /// some examples demonstrating this.
        /// </summary>
        /// <param name="fieldName">the name of the field the created <see cref="Analysis.TokenStream"/> is used for</param>
        /// <param name="text">the <see cref="string"/> the streams source reads from </param>
        /// <returns><see cref="Analysis.TokenStream"/> for iterating the analyzed content of <c>reader</c></returns>
        /// <exception cref="ObjectDisposedException"> if the Analyzer is disposed. </exception>
        /// <exception cref="IOException"> if an i/o error occurs (may rarely happen for strings). </exception>
        /// <seealso cref="GetTokenStream(string, TextReader)"/>
        public TokenStream GetTokenStream(string fieldName, string text)
        {
            TokenStreamComponents components = reuseStrategy.GetReusableComponents(this, fieldName);
            ReusableStringReader  strReader  =
                (components == null || components.reusableStringReader == null)
                    ? new ReusableStringReader()
                    : components.reusableStringReader;

            strReader.SetValue(text);
            var r = InitReader(fieldName, strReader);

            if (components == null)
            {
                components = CreateComponents(fieldName, r);
                reuseStrategy.SetReusableComponents(this, fieldName, components);
            }
            else
            {
                components.SetReader(r);
            }
            components.reusableStringReader = strReader;
            return(components.TokenStream);
        }
示例#6
0
 /// <summary>
 /// Wraps / alters the given <see cref="TokenStreamComponents"/>, taken from the wrapped
 /// <see cref="Analyzer"/>, to form new components. It is through this method that new
 /// <see cref="TokenFilter"/>s can be added by <see cref="AnalyzerWrapper"/>s. By default, the given
 /// components are returned.
 /// </summary>
 /// <param name="fieldName">
 ///          Name of the field which is to be analyzed </param>
 /// <param name="components">
 ///          <see cref="TokenStreamComponents"/> taken from the wrapped <see cref="Analyzer"/> </param>
 /// <returns> Wrapped / altered <see cref="TokenStreamComponents"/>. </returns>
 protected virtual TokenStreamComponents WrapComponents(string fieldName, TokenStreamComponents components)
 {
     return(components);
 }
示例#7
0
 public override void SetReusableComponents(Analyzer analyzer, string fieldName, TokenStreamComponents components)
 {
     SetStoredValue(analyzer, components);
 }
示例#8
0
 /// <summary>
 /// Stores the given TokenStreamComponents as the reusable components for the
 /// field with the give name.
 /// </summary>
 /// <param name="fieldName"> Name of the field whose TokenStreamComponents are being set </param>
 /// <param name="components"> TokenStreamComponents which are to be reused for the field </param>
 public abstract void SetReusableComponents(Analyzer analyzer, string fieldName, TokenStreamComponents components);
示例#9
0
 protected override TokenStreamComponents WrapComponents(string fieldName, TokenStreamComponents components)
 {
     return(components);
 }