Exemple #1
0
PUBLIC EBOOL EGGAPI eggSySRecorder_init()
{
    if(!POINTER_IS_INVALID(g_sysRecorder_handle))
    {
        exit(-1);
    }
    
    g_sysRecorder_handle = (HEGGSYSRECORDER)malloc(sizeof(EGGSYSRECORDER));
    memset(g_sysRecorder_handle, 0, sizeof(EGGSYSRECORDER));
    pthread_mutex_init( &g_sysRecorder_handle->mutex, NULL);
    
    if(access(EGG_SYSRECORD_PATH, F_OK) != 0)
    {
        exit(-1);
    }
    g_sysRecorder_handle->path = (char*)malloc(1024);
    g_sysRecorder_handle->path[0] = 0;
    strcat(g_sysRecorder_handle->path, "/%%%");
    strcat(g_sysRecorder_handle->path, EGG_SYSRECORD_PATH);
    
    HEGGHANDLE hHandle = eggDirectory_open(g_sysRecorder_handle->path);

    g_sysRecorder_handle->hIndexReader = eggIndexReader_open(hHandle);
    g_sysRecorder_handle->hIndexSearcher = eggIndexSearcher_new(g_sysRecorder_handle->hIndexReader);
    g_sysRecorder_handle->hIndexWriter = eggIndexWriter_open(hHandle, "");
    
    eggPath_close(hHandle);
    return EGG_TRUE;
}
Exemple #2
0
   int main()
{
   //ImLexAnalyzer* p_la = (ImLexAnalyzer*)ImCnLexAnalyzer_new();
   // ImLexAnalyzer* p_la = (ImLexAnalyzer*)ImCnLexAnalyzer_new();

   HEGGDIRECTORY hDirectory = eggDirectory_open("/ape/ImRoBot5/index/bbstest");
   HEGGINDEXREADER hIndexReader = eggIndexReader_open(hDirectory);
   HEGGINDEXSEARCHER hIndexSearcher = eggIndexSearcher_new(hIndexReader);
   HEGGQUERY h1, h2, h3;
   h1 = eggQuery_new_string("title", "人", 3, ANALYZER_CWSLEX);
   //h2 = eggQuery_new_string("content", "new", 3, p_la);
   // h2 = eggQuery_new_string("body", "some description", 16, p_la);
   // h3 = eggQuery_new_int32("price", 199);
   // h2 = eggQuery_and(h3, h2);
   //h1 = eggQuery_or(h2, h1);
   // h3 = h2 = 0;
   HEGGTOPCOLLECTOR hTopCollector = eggTopCollector_new(0);
   int ret = eggIndexSearcher_search_with_query(hIndexSearcher, hTopCollector, h1);
   if (ret == EGG_TRUE)
   {
        eggTopCollector_normalized(hTopCollector, EGG_TOPSORT_SCORE);
        // eggTopCollector_normalized(hTopCollector, EGG_TOPSORT_NOT);
        HEGGSCOREDOC lp_score_doc = eggTopCollector_top_docs(hTopCollector);
        count_t cnt =  eggTopCollector_total_hits(hTopCollector);
        printf("have hit %u documents\n", cnt);

        if (cnt > 0)
        {
             printf("last document: id[%llu]\n", lp_score_doc[cnt-1].idDoc);
             HEGGDOCUMENT lp_eggDocument = EGG_NULL;
             eggIndexReader_get_document(hIndexReader,
                                lp_score_doc[cnt-1].idDoc, &lp_eggDocument);
             HEGGFIELD lp_field = eggDocument_get_field(lp_eggDocument,"title");
             unsigned len = 0;
             char *val = eggField_get_value(lp_field, &len);
             printf("last document: body[%.*s]\n", len, val);
             lp_field = 0;
             eggDocument_delete(lp_eggDocument);
        }
   }

   eggTopCollector_delete(hTopCollector);
   eggQuery_delete(h1);
   eggIndexSearcher_delete(hIndexSearcher);
   eggIndexReader_close(hIndexReader);
   eggDirectory_close(hDirectory);
   ImLexAnalyzer_delete(p_la);
}
Exemple #3
0
EBOOL eggMemEggHandle_init(HEGGMEMEGGHANDLE hEggMemEggHandle, char *eggPath, char *analyzerName)
{
    if (!hEggMemEggHandle)
    {
        return EGG_FALSE;
    }
    char *eggPath_extr;
    int n;
    n = strlen(eggPath);
    if (eggPath[n-1] != '/')
    {
        eggPath_extr = malloc(n + 2);
        assert(eggPath_extr);
        sprintf(eggPath_extr, "%s/", eggPath);
    }
    else
    {
        eggPath_extr = strdup(eggPath);
        assert(eggPath_extr);
    }
    hEggMemEggHandle->eggPath = eggPath_extr;
    assert(hEggMemEggHandle->eggPath);
    hEggMemEggHandle->analyzerName = strdup(analyzerName);
    assert(hEggMemEggHandle->analyzerName);    
    hEggMemEggHandle->hEggHandle = (HEGGHANDLE)eggDirectory_open(eggPath);
    hEggMemEggHandle->hWriter = eggIndexWriter_open(hEggMemEggHandle->hEggHandle, analyzerName);
    hEggMemEggHandle->hReader = eggIndexWriter_init_reader(hEggMemEggHandle->hWriter);
    hEggMemEggHandle->hSearcher = eggIndexSearcher_new(hEggMemEggHandle->hReader);
    
    if (hEggMemEggHandle->hEggHandle && hEggMemEggHandle->hWriter
        && hEggMemEggHandle->hReader && hEggMemEggHandle->hSearcher)
    {
        return EGG_TRUE;
    }
    else
    {
        return EGG_FALSE;
    }
}
Exemple #4
0
int main(int argc, char* argv[])
{
    if(argc != 2)
    {
        printf("argc error!\n");
        exit(-1);
    }
    if(access(argv[1], F_OK))
    {
        printf("path is error!\n");
        exit(-1);
    }
    char fddPath[1024];
    char iddPath[1024];
    char idxBakPath[1024];
    char idxPath[1024];
    HEGGDIRECTORY lp_dir =  eggDirectory_open(argv[1]);
    HEGGINDEXREADER hEggIndexReader = eggIndexReader_open(lp_dir);
    
    sprintf(fddPath, "%s/egg.fdd", argv[1]);
    sprintf(iddPath, "%s/egg.idd", argv[1]);
    sprintf(idxBakPath, "%s/eggbak.idx", argv[1]);
    sprintf(idxPath, "%s/egg.idx", argv[1]);
    
    HEGGFILE lp_egg_field = EggFile_open(fddPath);
    HEGGFILE lp_egg_id = EggFile_open(iddPath);
    HEGGFILE lp_egg_idx_bak = EggFile_open(idxBakPath);
    HEGGFILE lp_egg_idx = EggFile_open(idxPath);
    
    HEGGFIELDVIEW lp_field_view = eggFieldView_new(lp_egg_field);
    HEGGINDEXVIEW lp_index_view = eggIndexView_new(lp_egg_idx, NULL);
    HEGGIDVIEW lp_id_view = eggIdView_new(lp_egg_id);
    HEGGINDEXVIEW lp_index_bak_view = eggIndexView_new(lp_egg_idx_bak, NULL);

    fdid_t fdid = 0;
    struct eggIndexInfo *lp_index_info;
        
    int n_field = 0;
    int n_key_cnt = 0;
    while ((lp_index_info = eggFieldView_iter(lp_field_view, &fdid)))
    {
        eggIndexView_load_info(lp_index_view, lp_index_info, lp_field_view);
        
        struct eggIndexInfo *lp_index_info_bak = (struct eggIndexInfo*)malloc(sizeof(struct eggIndexInfo));
        memcpy(lp_index_info_bak, lp_index_info, sizeof(struct eggIndexInfo));
        
        lp_index_info_bak->rootOff = 0;
        lp_index_info_bak->leafOff = 0;

        eggIndexView_load_info(lp_index_bak_view, lp_index_info_bak, EGG_NULL);
        
        int cnt = 0;
        offset64_t n_iter_off = EGGINDEXVIEW_LEAFOFF(lp_index_view);
        while (n_iter_off)
        {
            HEGGINDEXNODEVIEW lp_node_view = eggIndexView_load_node(lp_index_view, n_iter_off);
            index_t n_index_iter = 0;
            while(n_index_iter != EGGINDEXNODEVIEW_RDCNT(lp_node_view))
            {
                HEGGINDEXRECORD pRecord = EGGINDEXNODEVIEW_RECORD_INDEX(lp_node_view, n_index_iter);
                printf("KEY[%.*s] KEY CNT : %d\n",
                       EGGINDEXRECORD_KSIZE(pRecord),
                       EGGINDEXRECORD_KEY(pRecord), n_key_cnt++);
                
                eggIndexView_insert(lp_index_bak_view, EGGINDEXRECORD_KEY(pRecord), EGGINDEXRECORD_KSIZE(pRecord), EGGINDEXRECORD_VAL(pRecord), EGGINDEXRECORD_VSIZE(pRecord) );
                cnt++;
                n_index_iter++;
            }
            size16_t n_node_size = sizeof(EGGINDEXNODE) + lp_index_view->hInfo->rdSize * (lp_index_view->hInfo->rdCnt + 1);

            n_iter_off = eggIndexNodeView_get_nextoff(lp_node_view);
            eggIndexNodeView_delete(lp_node_view);
        }
        eggFieldView_release_indexinfo(lp_field_view, lp_index_info_bak->fid, lp_index_info_bak);
//        free(lp_index_info);
        printf("field %d[%d]\n", n_field, cnt);
        printf("------------------------------------\n");
        n_field++;
    }
    return 0;
}