using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

using Lucene.Net;
using Lucene.Net.Analysis;

using CMS.SiteProvider;

/// <summary>
/// My media search analyzer.
/// </summary>
public class MyMediaSearchAnalyzer : Analyzer
{
    /// <summary>
    /// Token stream.
    /// </summary>
    /// <param name="fieldName">Field name</param>
    /// <param name="reader">Text reader</param>
    public override TokenStream TokenStream(string fieldName, System.IO.TextReader reader)
    {
        // Do not split word in search mode
        if (fieldName == SearchHelper.CONTENT_FIELD)
        {
            // Get original text
            string text = reader.ReadToEnd();
            // Create new TextReader instance
            StringReader sr = new StringReader(text);
            reader = sr as System.IO.TextReader;
        }

        // Use media tokenizer
        TokenStream result = new MyMediaTokenizer(reader);
        // Use lowercase filter and return token stream
        return new LowerCaseFilter(result);
    }


    /// <summary>
    /// Construct a new MyMediaSearchAnalyzer.
    /// </summary>
    public MyMediaSearchAnalyzer()
    {
    }
}

