コード例 #1
0
ファイル: eggSySRecorder.c プロジェクト: baifanmvp/egg3
void* EGGAPI eggSySRecorder_get_dict(char* infotype, char* analyName )
{
    if(POINTER_IS_INVALID(g_sysRecorder_handle))
    {
        return EGG_NULL;
    }
    
    if(POINTER_IS_INVALID(infotype))
    {
        return EGG_NULL;
    }
    if(POINTER_IS_INVALID(analyName))
    {
        return EGG_NULL;
    }
    
    pthread_mutex_lock( &g_sysRecorder_handle->mutex);

    HEGGTOPCOLLECTOR hTopCollector = eggTopCollector_new(0);
    
    HEGGQUERY hQuery1 = eggQuery_new_string(EGG_SYS_TYPEINFO, infotype, strlen(infotype), "");

    HEGGQUERY hQuery2 = eggQuery_new_string(EGG_SYS_ANALYNAME, analyName, strlen(analyName), "");

    hQuery1 = eggQuery_and(hQuery1, hQuery2);
    
    eggIndexSearcher_search_with_query(g_sysRecorder_handle->hIndexSearcher, hTopCollector, hQuery1);
    
    eggQuery_delete(hQuery1);
    
    pthread_mutex_unlock( &g_sysRecorder_handle->mutex);
    
    return hTopCollector;
}
コード例 #2
0
ファイル: addQueryToEgg.c プロジェクト: leajon-first/bas
    HEGGQUERY
add_query (HEGGQUERY eggQuery, char* field, char* key)
{
    HEGGQUERY new_query = NULL;

    if(!strcmp(field, "keywords"))
    {
        new_query = eggQuery_new_string("title", key,strlen(key),ANALYZER_CWSLEX);
        HEGGQUERY new_query_two = NULL;
        if(!strcmp(G->op, "search"))
        {

            new_query_two = eggQuery_new_string("content", key,strlen(key),ANALYZER_CWSLEX);
        }
        else
        {
            new_query_two = eggQuery_new_string("content_index", key,strlen(key),ANALYZER_CWSLEX);
        }

        new_query = eggQuery_or(new_query,new_query_two);
    }

 
    if(!strcmp(field, "category"))
    {

        new_query = eggQuery_new_string("category", key, strlen(key), NULL);

/*
        if(!strcmp(G->op, "search"))
        {
            // char* key_with_space = addSpace(key,30);
            new_query = eggQuery_new_string("category", key, strlen(key), NULL);
           // free(key_with_space);        
        }
        else
        {
            new_query = eggQuery_new_string("category", key, strlen(key), NULL);
        }
*/
    }


    if(new_query != NULL)  
    {
        if(eggQuery == NULL) 
        {
            eggQuery = new_query;  
        }
        else
        {
            eggQuery = eggQuery_and(eggQuery,new_query);

        }
    }
    return eggQuery;
}		/* -----  end of function get_queryadd_query  ----- */
コード例 #3
0
ファイル: eggItfTest.cpp プロジェクト: baifanmvp/egg3
void CeggItfTest::testIndexSearch(char* dir_path)
{
    char key[1000] = {0};
    type_t op = EGG_TOPSORT_SCORE;
    HEGGHANDLE hEggHandle = eggPath_open(dir_path);
    
    
    HEGGINDEXREADER hIndexReader = eggIndexReader_open(hEggHandle);
    
    HEGGINDEXSEARCHER hIndexSearcher = eggIndexSearcher_new(hIndexReader);
    char fieldName[200] = "";
    HEGGQUERY h1;
    
    h1 = getQuery();
    
    char c;
    printf("key range search?(y/n)");
    scanf("%c", &c);
    if(c == 'y')
    {
        printf("FieldName: ");
        scanf("%s", fieldName);
        

        int startPrice = 0;
        int endPrice = 0;
        printf("start Price: ");
        scanf("%d", &startPrice);
        printf("end Price: ");
        scanf("%d", &endPrice);
        HEGGQUERY h2 = 0;
        op = EGG_TOPSORT_ORDERBY;
        h2 = eggQuery_new_int32range(fieldName, startPrice, endPrice);
        h1 = eggQuery_and(h1, h2);
        
    }
    HEGGTOPCOLLECTOR hTopCollector = eggTopCollector_new(0);
    switch (1) {
    case 1:
            
        eggTopCollector_set_orderby(hTopCollector, 2, "num1", 1,
                                    "num2", 1);
        break;
    case 2:
        eggTopCollector_set_sorttype(hTopCollector, EGG_TOPSORT_SCORE);
        break;
    default:
        eggTopCollector_set_sorttype(hTopCollector, EGG_TOPSORT_NOT);
        break;
    }
        
    
    struct timeval vstart, vend;
    gettimeofday(&vstart, 0);
    EBOOL ret = eggIndexSearcher_search_with_query(hIndexSearcher, hTopCollector, h1);
    gettimeofday(&vend, 0);
    printf("search_with_query time : %f\n", (double)(vend.tv_sec - vstart.tv_sec) + (double)(vend.tv_usec - vstart.tv_usec)/1000000);
    if(ret ==EGG_FALSE)
    {
        printf("no key !\n");
        exit(1);
    }

    // eggTopCollector_delete(hTopCollector);
    // eggQuery_delete(h1);
    // eggIndexSearcher_delete(hIndexSearcher);
    // eggIndexReader_close(hIndexReader);

    // eggPath_close(hEggHandle);    

    //     return ;
    if (0)
    {                           // deprecated
        HEGGQUERY hQuery_tmp = 0;
        //取时间范围
        hQuery_tmp = eggQuery_new_stringrange("time", "1", "2");
        //按时间排序
        eggIndexSearcher_filter(hIndexSearcher, hTopCollector, hQuery_tmp, 1);
        //按相关度排序
        //eggIndexSearcher_filter(hIndexSearcher, hTopCollector, hQuery_tmp, 0);
        eggQuery_delete(hQuery_tmp);
    }
    
    HEGGSCOREDOC lp_score_doc = eggTopCollector_top_docs(hTopCollector);
    count_t cnt =  eggTopCollector_total_hits(hTopCollector);
    index_t idx = 0;
    printf("count : %d\n", cnt);
//        return ;
    #if(0)
    HEGGDOCUMENT* ppeggDocument = EGG_NULL;
    eggIndexReader_get_documentSet(hIndexReader, lp_score_doc, cnt, &ppeggDocument);
    while(idx != cnt)

    {
        printf("--------------------------\n");
        HEGGFIELD lp_field = eggDocument_get_field(ppeggDocument[idx], "f_id");
        unsigned int len = 0;
        if(lp_field)
            printf("count %d id : %lld \nf_id : %s ", idx, EGGDID_DOCID(&(lp_score_doc[idx].idDoc)), eggField_get_value(lp_field, &len));

        eggDocument_delete(ppeggDocument[idx]);
        idx++;
        
    }
    #endif
    
    #if(0)
    while(idx != cnt && idx < 10000)
    {
        HEGGDOCUMENT lp_eggDocument = EGG_NULL;
        printf("%lld ----\n", lp_score_doc[idx].idDoc);
       	eggIndexReader_get_document(hIndexReader, lp_score_doc[idx].idDoc, &lp_eggDocument);

        HEGGFIELD lp_field = eggDocument_get_field(lp_eggDocument, "f_id");
	//	HEGGFIELD lp_field2 = eggDocument_get_field(lp_eggDocument, "random");
	//HEGGFIELD lp_field3 = eggDocument_get_field(lp_eggDocument, "num1");
	//HEGGFIELD lp_field4 = eggDocument_get_field(lp_eggDocument, "num2");
        //      HEGGFIELD lp_field3 = eggDocument_get_field(lp_eggDocument, "spanfield2");        
        unsigned int len = 0;
        unsigned int len2 = 0;
        unsigned int len3 = 0;                
        if(lp_field)
            printf("count %d id : %lld  f_id: %s \n", idx, EGGDID_DOCID(&(lp_score_doc[idx].idDoc)),  eggField_get_value(lp_field, &len) );

//        if(lp_field3)
//	  printf("count %d id : %lld content : %s weightfield: %d\n", idx, EGGDID_DOCID(&(lp_score_doc[idx].idDoc)), eggField_get_value(lp_field3, &len), eggField_get_value(lp_field3, &len3));
/*
        {
            char **pkeywords;
            size16_t *pkeySz;
//          int **ppos = NULL;
            count_t nums;
            
            eggTopCollector_get_keyPosition(hTopCollector,
                                            EGGDID_DOCID(&lp_score_doc[idx].idDoc),
                                            "content", &pkeywords, &pkeySz,
                                            NULL, &nums);
            int i;
            for (i = 0; i < nums; i++)
            {

                printf("Key[%.*s]\n", pkeySz[i], pkeywords[i]);
            }
            free(pkeySz);
            for (i = 0; i < nums; i++)
            {
                free(pkeywords[i]);
            }
            free(pkeywords);
        }
*/
//        lp_field = eggDocument_get_field(lp_eggDocument, "price");
        
//        printf("date : [%s] \n", eggField_get_value(lp_field, &len));

        eggDocument_delete(lp_eggDocument);
        idx++;
        // usleep(5000);
    }
    #endif
    eggTopCollector_delete(hTopCollector);
    eggQuery_delete(h1);
    eggIndexSearcher_delete(hIndexSearcher);
    eggIndexReader_close(hIndexReader);

    eggPath_close(hEggHandle);    
}
コード例 #4
0
ファイル: eggItfTest.cpp プロジェクト: baifanmvp/egg3
static HEGGQUERY getQuery()
{
    char key[1000] = {0};
    char fieldName[200] = "";

    HEGGQUERY h1, h2;
    printf("fieldName: ");
    scanf("%s", fieldName);
    printf("key: ");
    scanf("%s", key);
    h1 = nextQuery(fieldName, key);

    while (1)
    {
        HEGGQUERY h2 = 0;
        int c;
        printf("logic? ");
        char bb[20] = "";
        fgets(bb, sizeof(bb), stdin);
        fgets(bb, sizeof(bb), stdin);        
        c = bb[0];
        printf("--------     :%c\n",c);
        if (c == 'a' || c == 'A')
        {
            printf("FieldName: ");
            scanf("%s", fieldName);
            printf("key: ");
            scanf("%s", key);
            h2 = nextQuery(fieldName, key);
            
            h1 = eggQuery_and(h1, h2);
        }
        else if  (c == 'o' || c == 'O')
        {
            printf("FieldName: ");
            scanf("%s", fieldName);
            printf("key: ");
            scanf("%s", key);
            h2 = nextQuery(fieldName, key);
            
            h1 = eggQuery_or(h1, h2);
        }
        else if  (c == '-')
        {
            printf("FieldName: ");
            scanf("%s", fieldName);
            printf("key: ");
            scanf("%s", key);
            h2 = nextQuery(fieldName,key);

            h1 = eggQuery_minus(h1, h2);
        }
        else
        {
            break;
        }
    }

    return h1;
    
}