organizer_plat/searchfw_launcher_api/inc/searchtextsearcher.h
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:  Class handling the search of several keywords in a block of 
       
    15 *                text.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #ifndef      C_SEARCHTEXTSEARCHER_H
       
    21 #define      C_SEARCHTEXTSEARCHER_H
       
    22 
       
    23 //System Includes
       
    24 #include <badesca.h>
       
    25 #include <searchbooleancondition.h>
       
    26 
       
    27 //Forward Declarations
       
    28 class MSearchTextSearcherObserver;
       
    29 class CSearchAlgorithm;
       
    30 class CSearchCondition;
       
    31 class CSearchSingleCondition;
       
    32 class CSearchBooleanCondition;
       
    33 class TKeywordSearchStatus;
       
    34 
       
    35 /**
       
    36  * This class handles the search of several keywords 
       
    37  * in a block of text.
       
    38  * Data/text can be supplied in steps and it does not need 
       
    39  * to be known in advance.
       
    40  * @lib searchutilities.lib
       
    41  */
       
    42 NONSHARABLE_CLASS( CSearchTextSearcher )  :  public CBase 
       
    43     {
       
    44     
       
    45 public:
       
    46 
       
    47     enum TSearchCriteriaOperator
       
    48         {
       
    49         ESearchCriteriaAND,
       
    50         ESearchCriteriaOR,
       
    51         ESearchCriteriaNO  
       
    52         };
       
    53     
       
    54     /** 
       
    55      * Symbian OS 2 phased constructor.
       
    56      *
       
    57      * @param aObserver	- Text searcher's observer
       
    58      * @return - A pointer to the created instance of CSearchTextSearcher.
       
    59      */
       
    60      IMPORT_C static CSearchTextSearcher* NewL( 
       
    61                      MSearchTextSearcherObserver& aObserver );
       
    62         
       
    63     /** 
       
    64      * Symbian OS 2 phased constructor
       
    65      *
       
    66      * @param aObserver -	Text searcher's observer
       
    67      * @return - A pointer to the created instance of CSearchTextSearcher.
       
    68      */
       
    69      IMPORT_C static CSearchTextSearcher* NewLC( 
       
    70             MSearchTextSearcherObserver& aObserver );
       
    71 		
       
    72     /**
       
    73      * Destructor.
       
    74      */
       
    75      virtual ~CSearchTextSearcher();
       
    76     
       
    77     /**
       
    78      * Cleans up internal data. Must be called before each new search is 
       
    79      * started. Does not clean up the parameters set via SetParametersL.
       
    80      * 
       
    81      * When same search parameters are needed with different search text, 
       
    82      * call Cleanup but not SetParametersL.
       
    83      *
       
    84      */
       
    85      IMPORT_C void Cleanup();
       
    86     
       
    87     /**
       
    88      * Sets the search parameters for the search.
       
    89      *
       
    90      * @param aKeywords - Keywords for the search.
       
    91      * @param aOperator - Determines the operation for the search(AND, OR, ...)
       
    92      * @param aCaseSensitive - Flag indicating case sensitivity
       
    93      */
       
    94      IMPORT_C void SetParametersL( const MDesCArray& aKeywords,
       
    95                    CSearchTextSearcher::TSearchCriteriaOperator aOperator, 
       
    96                    TBool aCaseSensitive );
       
    97 								                        
       
    98     /**
       
    99      * Sets the search parameters for the search.
       
   100      *
       
   101      * @param	aCondition The condition of the search.
       
   102      */
       
   103      IMPORT_C void SetParametersL( const CSearchCondition& aCondition );
       
   104                                   
       
   105     /**
       
   106      * Starts the text search with the previous supplied parameters 
       
   107      * set by SetParametersL. 16 bit version.
       
   108      *
       
   109      * @param aToBeSearchedDes - 16 bit descriptor to be searched.
       
   110      */
       
   111     IMPORT_C void SearchL( const TDesC16& aToBeSearchedDes );
       
   112 		
       
   113     /**
       
   114      * Starts the text search with the previous supplied parameters 
       
   115      * set by SetParametersL(). 8 bit version.
       
   116      *
       
   117      * @param aToBeSearchedDes - 8 bit descriptor to be searched.
       
   118      */
       
   119      IMPORT_C void SearchL( const TDesC8& aToBeSearchedDes );
       
   120      
       
   121      /**
       
   122      * Sets the flag for email search
       
   123      *
       
   124      * @param	aSearchEmail 
       
   125      */
       
   126      IMPORT_C void SearchEmailAddress( TBool aSearchEmail );
       
   127      
       
   128      /**
       
   129      * Return the search keywords
       
   130      *
       
   131      * @param   aSearchEmail 
       
   132      */
       
   133      IMPORT_C CDesC16ArrayFlat* SearchKeyword();
       
   134 private:
       
   135 
       
   136     /** 
       
   137      * Performs the first phase of two phase construction.
       
   138      *
       
   139      * @param	aObserver	Text searcher's observer
       
   140      */
       
   141      CSearchTextSearcher( MSearchTextSearcherObserver& aObserver );
       
   142     
       
   143     /**
       
   144      * Performs the second phase construction.
       
   145      */
       
   146      void ConstructL();
       
   147 
       
   148     /**
       
   149      * Compares the to be searched string with the list of keywords. 
       
   150      *  16 bit version.
       
   151      *
       
   152      * @param aToBeSearchedDes - Text to be searched.
       
   153      * @param aKeywords - Array of keywords to be matched.
       
   154      * @param aKeywordSearchStatusArray Array storing the search 
       
   155      *        result for each individual search keyword
       
   156      * @param aOperator - Determines the operation for the search
       
   157      *                     (AND, OR, ...)
       
   158      * @param aCaseSensitive - Flag indicating case sensitivity
       
   159      */
       
   160      TBool DoStringCompareWithKeywordsL( const TDesC& aToBeSearchedDes,
       
   161                 const CDesC16Array& aKeywords, 
       
   162                 RArray<TKeywordSearchStatus>& aKeywordSearchStatusArray,
       
   163                 TSearchCriteriaOperator aOperator, 
       
   164                 TBool aCaseSensitive );
       
   165 
       
   166     /**
       
   167      * Compares the to be searched string with the list of keywords. 
       
   168      * 8 bit version.
       
   169      *
       
   170      *
       
   171      * @param aToBeSearchedDes -      Text to be searched.
       
   172      * @param aKeywords - Array of keywords to be matched.
       
   173      * @param aKeywordSearchStatusArray - Array storing the search result for 
       
   174      *					       				each individual search keyword
       
   175      * @param aOperator - Determines the operation for the search
       
   176      *		 			    (AND, OR, ...)
       
   177      * @param aCaseSensitive -  Flag indicating case sensitivity
       
   178      */
       
   179      TBool DoStringCompareWithKeywordsL( const TDesC8& aToBeSearchedDes,
       
   180                    const CDesC8Array& aKeywords, 
       
   181                    RArray<TKeywordSearchStatus>& aKeywordSearchStatusArray,
       
   182                    TSearchCriteriaOperator aOperator, 
       
   183                    TBool aCaseSensitive );
       
   184                                        
       
   185     
       
   186     /**
       
   187      * Sets data from singlecondition class
       
   188      *
       
   189      * @param aCondition - single condition info
       
   190      */
       
   191      void  SetSingleConditionDataL( 
       
   192               const CSearchSingleCondition& aCondition );   
       
   193     
       
   194     /**
       
   195      * Sets data from singlecondition class
       
   196      *
       
   197      * @param aKeywords	- Array of keywords to be matched.
       
   198      */
       
   199      void  DoUftTo8BitConversionL( const MDesC16Array&  aKeywords );  
       
   200     
       
   201     /**
       
   202      * Sets if boolean condition  
       
   203      */
       
   204      void  SetCriteriaOperator( );        
       
   205     
       
   206     /**
       
   207      * This method based on keyword status HitL() observer method will be  
       
   208      * called, this method is only called if condition type is of boolean
       
   209      *
       
   210      * @param aKeywordSearchStatusArray - keyword status array
       
   211      */
       
   212     void CheckForBooleanClausesL( RArray<TKeywordSearchStatus>& 
       
   213                                   aKeywordSearchStatusArray );                      
       
   214 	
       
   215 private:
       
   216     
       
   217     
       
   218     /**
       
   219      * Searchalgorith to use for searching
       
   220      * Own
       
   221      */
       
   222      CSearchAlgorithm* iSearchAlgorithm;
       
   223     
       
   224     /**
       
   225      * A file session for the unicode converter
       
   226      * Own
       
   227      */
       
   228      RArray<CSearchBooleanCondition::TBooleanClause>  iClause;   
       
   229 	
       
   230    
       
   231     /**
       
   232      * Text searcher's observer
       
   233      */
       
   234      MSearchTextSearcherObserver& iObserver;
       
   235 
       
   236     
       
   237     /**
       
   238      * array that contains 16 bit keywords to search
       
   239      * Not owned
       
   240      */
       
   241      const CDesC16Array* iSearchKeywords;		
       
   242     
       
   243     
       
   244     /**
       
   245      * array that contains 8 bit versions from keywords to search
       
   246      * These are copied from the 16bit version when search is done 
       
   247      * in text that is available in 8 bit format
       
   248      *
       
   249      * Own
       
   250      */
       
   251      CDesC8ArrayFlat* iSearchKeywords8;	
       
   252     
       
   253     
       
   254     /**
       
   255      * array that contains 16 bit versions from keywords to search
       
   256      *
       
   257      * Own
       
   258      */
       
   259      CDesC16ArrayFlat* iSearchKeywords16; 	
       
   260     
       
   261     /**
       
   262      * Determines the operation for the search (AND, OR, ...)
       
   263      */
       
   264      TSearchCriteriaOperator iOperator;
       
   265     
       
   266     /**
       
   267      * Flag indicating case sensitivity
       
   268      */
       
   269      TBool iCaseSensitive;
       
   270     
       
   271     /**
       
   272      * Flag indicating whether search parameters where set.
       
   273      */
       
   274      TBool iHaveParameters;
       
   275     
       
   276     /**
       
   277      * Array storing the search result for each individual search keyword
       
   278      */
       
   279      RArray<TKeywordSearchStatus> iKeywordSearchStatusArray;
       
   280     
       
   281     /**
       
   282      * Character position of the 1st keyword match
       
   283      */
       
   284      TBool iIsBooleanCondition;
       
   285     
       
   286     /**
       
   287      * Keywords sount
       
   288      */
       
   289      TInt iCount;
       
   290     
       
   291     /**
       
   292      * To check wheather all the conditions are of same type
       
   293      */
       
   294      TBool iSameCondition;
       
   295     
       
   296     /**
       
   297      * Type of boolean clause ( EBooleanMust , EBooleanShould or 
       
   298      * EBooleanMustNot )
       
   299      */
       
   300      CSearchBooleanCondition::TBooleanClause  iBooleanClause;
       
   301     
       
   302     /**
       
   303      * Type of boolean clause 
       
   304      */
       
   305      CSearchBooleanCondition::TBooleanClause  iIntermediateClause;
       
   306 
       
   307     };
       
   308     
       
   309 #endif  //C_SEARCHTEXTSEARCHER_H       
       
   310     
       
   311     
       
   312