diff --git a/include/libs/index/index.h b/include/libs/index/index.h index 3d4dbade58..2535ec8a5b 100644 --- a/include/libs/index/index.h +++ b/include/libs/index/index.h @@ -53,7 +53,7 @@ int indexMultiTermQueryAdd(SIndexMultiTermQuery *pQuery, SIndexTerm */ int indexOpen(SIndexOpts *opt, const char *path, SIndex **index); void indexClose(SIndex *index); -int indexPut(SIndex *index, SIndexMultiTerm *terms, int uid); +int indexPut(SIndex *index, SIndexMultiTerm *terms, uint64_t uid); int indexDelete(SIndex *index, SIndexMultiTermQuery *query); int indexSearch(SIndex *index, SIndexMultiTermQuery *query, SArray *result); int indexRebuild(SIndex *index, SIndexOpts *opt); diff --git a/source/libs/index/inc/index_cache.h b/source/libs/index/inc/index_cache.h index b952e16a8e..f2e6df0bfb 100644 --- a/source/libs/index/inc/index_cache.h +++ b/source/libs/index/inc/index_cache.h @@ -16,13 +16,14 @@ #define __INDEX_CACHE_H__ #include "index.h" +#include "indexInt.h" #include "tlockfree.h" #include "tskiplist.h" // ----------------- row structure in skiplist --------------------- /* A data row, the format is like below: * content: |<--totalLen-->|<-- fieldid-->|<--field type -->|<-- value len--->|<-- value -->|<-- uid -->|<--version--->|<-- itermType -->| - * len : |<--int32_t -->|<-- int16_t-->|<-- int16_t --->|<--- int32_t --->|<--valuelen->|<--uint64_t->|<-- int32_t-->|<-- int8_t --->| + * len : |<--int32_t -->|<-- int16_t-->|<-- int8_t --->|<--- int32_t --->|<--valuelen->|<--uint64_t->|<-- int32_t-->|<-- int8_t --->| */ #ifdef __cplusplus @@ -40,11 +41,10 @@ IndexCache *indexCacheCreate(); void indexCacheDestroy(void *cache); -int indexCachePut(void *cache, int16_t fieldId, int16_t fieldType, const char *fieldValue, int32_t fvLen, - uint32_t version, uint64_t uid, int8_t operType); +int indexCachePut(void *cache, SIndexTerm *term, int16_t colId, int32_t version, uint64_t uid); -int indexCacheGet(void *cache, uint64_t *rst); -int indexCacheSearch(void *cache, SIndexMultiTermQuery *query, SArray *result); +//int indexCacheGet(void *cache, uint64_t *rst); +int indexCacheSearch(void *cache, SIndexTermQuery *query, int16_t colId, int32_t version, SArray *result); #ifdef __cplusplus } diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 1bc12d2b79..e6c655d097 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -74,7 +74,7 @@ void indexClose(SIndex *sIdx) { return; } -int indexPut(SIndex *index, SIndexMultiTerm * fVals, int uid) { +int indexPut(SIndex *index, SIndexMultiTerm * fVals, uint64_t uid) { #ifdef USE_LUCENE index_document_t *doc = index_document_create(); @@ -116,7 +116,7 @@ int indexPut(SIndex *index, SIndexMultiTerm * fVals, int uid) { assert(fi != NULL); int32_t colId = fi->colId; int32_t version = index->cVersion; - int ret = indexCachePut(index->cache, colId, p->colType, p->colVal, p->nColVal, version, uid, p->operType); + int ret = indexCachePut(index->cache, p, colId, version, uid); if (ret != 0) { return ret; } @@ -275,6 +275,7 @@ void indexInit() { } static int indexTermSearch(SIndex *sIdx, SIndexTermQuery *term, SArray **result) { + return 0; } static void indexInterResultsDestroy(SArray *results) { if (results == NULL) { return; } @@ -288,12 +289,17 @@ static void indexInterResultsDestroy(SArray *results) { } static int indexMergeFinalResults(SArray *interResults, EIndexOperatorType oType, SArray *fResults) { + //refactor, merge interResults into fResults by oType + SArray *first = taosArrayGetP(interResults, 0); + + //taosArraySort(first, getCom) if (oType == MUST) { - - // tag1 condition && tag2 condition + } else if (oType == SHOULD) { + // tag1 condistion || tag2 condition } else if (oType == NOT) { + // not use currently } return 0; diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index 23f7a08823..7ce23e6b6e 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -103,14 +103,13 @@ void indexCacheDestroy(void *cache) { free(pCache); } -int indexCachePut(void *cache, int16_t fieldId, int16_t fieldType, const char *fieldValue, int32_t fvLen, - uint32_t version, uint64_t uid, int8_t operType) { +int indexCachePut(void *cache, SIndexTerm *term, int16_t colId, int32_t version, uint64_t uid) { if (cache == NULL) { return -1;} IndexCache *pCache = cache; // encode data - int32_t total = sizeof(int32_t) + sizeof(fieldId) + sizeof(fieldType) + sizeof(fvLen) + fvLen + sizeof(version) + sizeof(uid) + sizeof(operType); + int32_t total = sizeof(int32_t) + sizeof(colId) + sizeof(term->colType) + sizeof(term->nColVal) + term->nColVal + sizeof(version) + sizeof(uid) + sizeof(term->operType); char *buf = calloc(1, total); char *p = buf; @@ -118,16 +117,16 @@ int indexCachePut(void *cache, int16_t fieldId, int16_t fieldType, const char *f memcpy(p, &total, sizeof(total)); p += sizeof(total); - memcpy(p, &fieldId, sizeof(fieldId)); - p += sizeof(fieldId); + memcpy(p, &colId, sizeof(colId)); + p += sizeof(colId); - memcpy(p, &fieldType, sizeof(fieldType)); - p += sizeof(fieldType); + memcpy(p, &term->colType, sizeof(term->colType)); + p += sizeof(term->colType); - memcpy(p, &fvLen, sizeof(fvLen)); - p += sizeof(fvLen); - memcpy(p, fieldValue, fvLen); - p += fvLen; + memcpy(p, &term->nColVal, sizeof(term->nColVal)); + p += sizeof(term->nColVal); + memcpy(p, term->colVal, term->nColVal); + p += term->nColVal; memcpy(p, &version, sizeof(version)); p += sizeof(version); @@ -135,8 +134,8 @@ int indexCachePut(void *cache, int16_t fieldId, int16_t fieldType, const char *f memcpy(p, &uid, sizeof(uid)); p += sizeof(uid); - memcpy(p, &operType, sizeof(operType)); - p += sizeof(operType); + memcpy(p, &term->operType, sizeof(term->operType)); + p += sizeof(term->operType); tSkipListPut(pCache->skiplist, (void *)buf); // encode end @@ -146,7 +145,7 @@ int indexCacheDel(void *cache, int32_t fieldId, const char *fieldValue, int32_t IndexCache *pCache = cache; return 0; } -int indexCacheSearch(void *cache, SIndexMultiTermQuery *query, SArray *result) { - - return 0; +int indexCacheSearch(void *cache, SIndexTermQuery *query, int16_t colId, int32_t version, SArray *result) { + return 0; } +