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; }
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 ----- */
static HEGGQUERY nextQuery(char *fieldName, char *keybuf) { HEGGQUERY h1 = NULL; if (keybuf[0] == '"') { char *key; char *p = keybuf+1; while (p[0]) { if (p[0] == '"') { break; } else if (p[0] == '\\') { p++; if (p[0] == '\0') { fprintf(stderr, "input string invalid \\\n"); exit(-1); } p++; } else { p++; } } p[0] = '\0'; key = keybuf+1; h1 = eggQuery_new_string(fieldName, key, p-key, NULL); } else if (keybuf[0] == 'i') { int i; i = atoi(keybuf+1); h1 = eggQuery_new_int32(fieldName, i); } else if (keybuf[0] == 'l') { int64_t l; l = strtoll(keybuf+1, NULL, 0); h1 = eggQuery_new_int64(fieldName, l); } else if (keybuf[0] == 'f') { double f; f = strtod(keybuf+1, NULL); h1 = eggQuery_new_double(fieldName, f); } else { fprintf(stderr, "please \"string\" or i32 or l64 or f3.3333 \n"); exit(-1); } return h1; }
int main() { HEGGHANDLE hHandle = eggPath_open("file:///tmp/"); HEGGINDEXREADER hIndexReader = eggIndexReader_open(hHandle); HEGGINDEXSEARCHER hIndexSearcher = eggIndexSearcher_new(hIndexReader); HEGGQUERY hq = eggQuery_new_string("content", "is good", strlen("is good"), ANALYZER_CWSLEX); if(hq != EGG_NULL) { printf("query init OK! \n"); } //填0取所有结果,非0按填的值取个数 HEGGTOPCOLLECTOR hTopCollector = eggTopCollector_new(0); eggTopCollector_set_sorttype(hTopCollector, EGG_TOPSORT_WEIGHT); printf("eggTopCollector sortType is EGG_TOPSORT_WEIGHT \n"); EBOOL ret = eggIndexSearcher_search_with_query(hIndexSearcher, hTopCollector, hq); if (ret == EGG_TRUE) { //对最后结果进行排序 //EGG_TOPSORT_WEIGHT: 按document的weight排序 //EGG_TOPSORT_SCORE: 按查询关键字的相关度排序(打分排序) //EGG_TOPSORT_NOT: 不排序 HEGGSCOREDOC lp_score_doc = eggTopCollector_top_docs(hTopCollector); count_t cnt = eggTopCollector_total_hits(hTopCollector); index_t i = 0; printf("have hit %u documents\n", cnt); while (i != cnt) { HEGGDOCUMENT lp_eggDocument = EGG_NULL; eggIndexReader_get_document(hIndexReader, lp_score_doc[i].idDoc, &lp_eggDocument); HEGGFIELD lp_field = eggDocument_get_field(lp_eggDocument, "content"); unsigned len = 0; char *val = eggField_get_value(lp_field, &len); printf("id : [%llu], content : [%s], weight : [%d]\n", EGGDID_DOCID(&lp_score_doc[i].idDoc), val, eggDocument_get_weight(lp_eggDocument)); lp_field = 0; eggDocument_delete(lp_eggDocument); i++; } } eggTopCollector_delete(hTopCollector); eggQuery_delete(hq); eggIndexSearcher_delete(hIndexSearcher); eggIndexReader_close(hIndexReader); eggPath_close(hHandle); return 0; }
void query::add(const char *keywords, std::string key) { HEGGQUERY new_query; new_query = eggQuery_new_string(keywords, key.c_str(), key.length(), ANALYZER_CWSLEX); if(query_str == NULL) { query_str = new_query; } }
int main(int argc, char* argv[]) { HEGGHANDLE hHandle = eggPath_open("file:///egg/"); HEGGINDEXREADER hIndexReader = eggIndexReader_open(hHandle); HEGGINDEXSEARCHER hIndexSearcher = eggIndexSearcher_new(hIndexReader); HEGGQUERY hq = eggQuery_new_string("content", argv[1], strlen(argv[1]), ""); if(hq != EGG_NULL) { printf("query init OK! \n"); } HEGGTOPCOLLECTOR hTopCollector = eggTopCollector_new(0); EBOOL ret = eggIndexSearcher_search_with_query(hIndexSearcher, hTopCollector, hq); if (ret == EGG_TRUE) { HEGGSCOREDOC lp_score_doc = eggTopCollector_top_docs(hTopCollector); count_t cnt = eggTopCollector_total_hits(hTopCollector); index_t i = 0; printf("have hit %u documents\n", cnt); while (i != cnt) { HEGGDOCUMENT lp_eggDocument = EGG_NULL; eggIndexReader_get_document(hIndexReader, lp_score_doc[i].idDoc, &lp_eggDocument); HEGGFIELD lp_field = eggDocument_get_field(lp_eggDocument, "content"); unsigned len = 0; char *val = eggField_get_value(lp_field, &len); printf("id : [%llu], content : [%s], \n", EGGDID_DOCID(&lp_score_doc[i].idDoc), val); lp_field = 0; eggDocument_delete(lp_eggDocument); i++; } } eggTopCollector_delete(hTopCollector); eggQuery_delete(hq); eggIndexSearcher_delete(hIndexSearcher); eggIndexReader_close(hIndexReader); eggPath_close(hHandle); return 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); }
void* EGGAPI eggSySRecorder_get_records(char* infotype ) { if(POINTER_IS_INVALID(g_sysRecorder_handle)) { return EGG_NULL; } if(POINTER_IS_INVALID(infotype)) { return EGG_NULL; } pthread_mutex_lock( &g_sysRecorder_handle->mutex); HEGGTOPCOLLECTOR hTopCollector = eggTopCollector_new(0); HEGGQUERY hQuery = eggQuery_new_string(EGG_SYS_TYPEINFO, infotype, strlen(infotype), ""); eggIndexSearcher_search_with_query(g_sysRecorder_handle->hIndexSearcher, hTopCollector, hQuery); eggQuery_delete(hQuery); pthread_mutex_unlock( &g_sysRecorder_handle->mutex); }