searchengine/cpix/tsrc/cpixsample/src/cpixsample.cpp
changeset 7 a5fbfefd615f
parent 3 ae3f1779f6da
child 8 6547bf8ca13a
equal deleted inserted replaced
3:ae3f1779f6da 7:a5fbfefd615f
     1 /*
       
     2 * Copyright (c) 2009 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 
     1 
    18 // INCLUDE FILES
     2 // INCLUDE FILES
    19 #include <stdio.h>
     3 #include <stdio.h>
    20 #include <iostream.h>
     4 #include <iostream.h>
    21 
     5 
    39 #define LDOCUID1 L"document1"
    23 #define LDOCUID1 L"document1"
    40 #define LDOCUID2 L"document2"
    24 #define LDOCUID2 L"document2"
    41 
    25 
    42 
    26 
    43 #define FIELD_ALPHA L"Alpha"
    27 #define FIELD_ALPHA L"Alpha"
       
    28 #define FIELD_ALPHA1 L"Alpha1"
    44 
    29 
    45 
    30 
    46 #define DOC1CONTENT L"mary had little lamb issue its anirban fleece was black as coal"
    31 #define DOC1CONTENT L"mary had little lamb issue its anirban fleece was black as coal"
    47 #define DOC2CONTENT L"sri rama jeyam shankar.rajendran@yahoo.co.in www.google.com U.S.A. file.txt"
    32 #define DOC2CONTENT L"sri rama jeyam and it  3gpp_70.jpg 170(kb).jpg is shankar.rajendran@yahoo.co.in then www.google.com U.S.A. file.txt"
    48 
    33 
    49 
    34 
    50 // The term that will be present in multiple documents.
    35 // The term that will be present in multiple documents.
    51 #define SEARCH_TERM L"$prefix(\"a\")"
    36 #define SEARCH_TERM L"$prefix(\"had\")"
    52 
    37 
    53 
    38 
    54 int testInit(cpix_Analyzer **analyzer_, cpix_IdxDb **idxDb_)
    39 int testInit(cpix_Analyzer **analyzer_, cpix_IdxDb **idxDb_)
    55     {
    40     {
    56     
    41     
   101 
    86 
   102 int createDocument(const wchar_t* docUid, const wchar_t* data,cpix_Analyzer **analyzer_, cpix_IdxDb **idxDb_)
    87 int createDocument(const wchar_t* docUid, const wchar_t* data,cpix_Analyzer **analyzer_, cpix_IdxDb **idxDb_)
   103     {
    88     {
   104     cpix_Document *doc;
    89     cpix_Document *doc;
   105     cpix_Field field;
    90     cpix_Field field;
       
    91     cpix_Field field1;
       
    92     cpix_Field field2;
       
    93     cpix_Field field3;
   106     cpix_Result result;
    94     cpix_Result result;
   107     
    95     
   108     doc = cpix_Document_create(&result,docUid,NULL,      // app class
    96     doc = cpix_Document_create(&result,docUid,NULL,      // app class
   109             NULL,      // excerpt
    97             NULL,      // excerpt
   110             NULL);     // mime type
    98             NULL);     // mime type
       
    99     
   111     if (cpix_Failed(&result))
   100     if (cpix_Failed(&result))
   112         {
   101         {
   113         printf("Failed to create a document\n");
   102         printf("Failed to create a document\n");
   114         return 0;
   103         return 0;
   115         }
   104         }
   116 
   105 
   117     cpix_Field_initialize(&field,
   106     cpix_Field_initialize(&field,
   118             FIELD_ALPHA,
   107             FIELD_ALPHA,
   119             data, 
   108             data, 
   120             cpix_STORE_YES |cpix_INDEX_TOKENIZED);
   109             cpix_STORE_YES |cpix_INDEX_UNTOKENIZED | cpix_AGGREGATE_YES | cpix_FREE_TEXT );
       
   110     
       
   111     cpix_Field_initialize(&field1,
       
   112                 FIELD_ALPHA1,
       
   113                 data, 
       
   114                 cpix_STORE_YES |cpix_INDEX_UNTOKENIZED | cpix_AGGREGATE_YES);
       
   115     
       
   116     
       
   117     cpix_Field_initialize(&field2,
       
   118                 L"ALPHA2",
       
   119                 L"This is shankar and I am working for nokia", 
       
   120                 cpix_STORE_YES |cpix_INDEX_TOKENIZED | cpix_AGGREGATE_YES | cpix_FREE_TEXT );
       
   121     
       
   122     
       
   123     cpix_Field_initialize(&field3,
       
   124                 L"ALPHA3",
       
   125                 L"This is shankar and I am working for nokia", 
       
   126                 cpix_STORE_NO |cpix_INDEX_TOKENIZED | cpix_AGGREGATE_YES);
   121 
   127 
   122     if (cpix_Failed(&field))
   128     if (cpix_Failed(&field))
   123         {
   129         {
   124         cpix_Document_destroy(doc);
   130         cpix_Document_destroy(doc);
   125         printf("Failed to initialize the field \n");
   131         printf("Failed to initialize the field \n");
   126         return 0;
   132         return 0;
   127         }
   133         }
   128     cpix_Document_add(doc,&field);
   134     cpix_Document_add(doc,&field);
       
   135     cpix_Document_add(doc,&field1);
       
   136     cpix_Document_add(doc,&field2);
       
   137     cpix_Document_add(doc,&field3);
   129     cpix_IdxDb_add(*idxDb_,doc,*analyzer_);
   138     cpix_IdxDb_add(*idxDb_,doc,*analyzer_);
   130 
   139 
   131     cpix_Document_destroy(doc);
   140     cpix_Document_destroy(doc);
   132     cpix_IdxDb_flush(*idxDb_);
   141     cpix_IdxDb_flush(*idxDb_);
   133     return 1;
   142     return 1;