searchengine/oss/loc/analysis/inc/public/clutil.h
changeset 24 65456528cac2
equal deleted inserted replaced
23:d4d56f5e7c55 24:65456528cac2
       
     1 /*
       
     2 * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef CLUTIL_H_
       
    19 #define CLUTIL_H_
       
    20 
       
    21 #include "CLucene.h"
       
    22 
       
    23 namespace analysis {
       
    24 
       
    25 	/**
       
    26 	 * Defines analyzer that uses given tokenizer T
       
    27 	 */
       
    28     template <class T>
       
    29     class TemplateAnalyzer : public lucene::analysis::Analyzer {
       
    30         public:
       
    31             TemplateAnalyzer();
       
    32             virtual lucene::analysis::TokenStream* 
       
    33                 tokenStream(const TCHAR* fieldName, 
       
    34                             CL_NS(util)::Reader* reader) {
       
    35                 return new T(reader, true);
       
    36             }
       
    37     };
       
    38 
       
    39 	/**
       
    40 	 * Defines analyzer that uses given tokenizer T with an argument A1 
       
    41 	 * combinged with filter F1. By using cpix analyzer definition syntax, 
       
    42 	 * the defined analyzer is T(A1)>F1 
       
    43 	 */
       
    44     template <class T, class A1, class F1>
       
    45     class TemplateAnalyzer1A1F : public lucene::analysis::Analyzer {
       
    46         public:
       
    47             TemplateAnalyzer1A1F(A1 a1) : a1_(a1) {};
       
    48             virtual lucene::analysis::TokenStream* 
       
    49                 tokenStream(const TCHAR* fieldName, 
       
    50                             CL_NS(util)::Reader* reader) {
       
    51                 return new F1(new T(reader, a1_), true);
       
    52             }
       
    53         private:
       
    54             A1 a1_;
       
    55     };
       
    56     
       
    57 	/**
       
    58 	 * Defines analyzer that uses given tokenizer T combined with filter F1. 
       
    59 	 * By using cpix analyzer definition syntax, the defined analyzer is 
       
    60 	 * T>F1. 
       
    61 	 */
       
    62     template <class T, class F1>
       
    63     class TemplateAnalyzer1F : public lucene::analysis::Analyzer {
       
    64         public:
       
    65             TemplateAnalyzer1F() {};
       
    66             virtual lucene::analysis::TokenStream* 
       
    67                 tokenStream(const TCHAR* fieldName, 
       
    68                             CL_NS(util)::Reader* reader) {
       
    69                 return new F1(new T(reader), true);
       
    70             }
       
    71     };
       
    72 
       
    73 }
       
    74 
       
    75 #endif /* CLUTIL_H_ */