1 #ifndef __INDEX_RESULT_H__
2 #define __INDEX_RESULT_H__
3
4 #include "varint.h"
5 #include "redisearch.h"
6 #include "rmalloc.h"
7 #define DEFAULT_RECORDLIST_SIZE 4
8
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12
13 RSQueryTerm *NewQueryTerm(RSToken *tok, int id);
14 void Term_Free(RSQueryTerm *t);
15
16 /** Reset the state of an existing index hit. This can be used to
17 recycle index hits during reads */
18 void IndexResult_Init(RSIndexResult *h);
19
20 /* Reset the aggregate result's child vector */
AggregateResult_Reset(RSIndexResult * r)21 static inline void AggregateResult_Reset(RSIndexResult *r) {
22
23 r->docId = 0;
24 r->agg.numChildren = 0;
25 r->agg.typeMask = (RSResultType)0;
26 }
27 /* Allocate a new intersection result with a given capacity*/
28 RSIndexResult *NewIntersectResult(size_t cap, double weight);
29
30 /* Allocate a new union result with a given capacity*/
31 RSIndexResult *NewUnionResult(size_t cap, double weight);
32
33 RSIndexResult *NewVirtualResult(double weight);
34
35 RSIndexResult *NewNumericResult();
36
37 /* Allocate a new token record result for a given term */
38 RSIndexResult *NewTokenRecord(RSQueryTerm *term, double weight);
39
40 /* Append a child to an aggregate result */
AggregateResult_AddChild(RSIndexResult * parent,RSIndexResult * child)41 static inline void AggregateResult_AddChild(RSIndexResult *parent, RSIndexResult *child) {
42
43 RSAggregateResult *agg = &parent->agg;
44
45 /* Increase capacity if needed */
46 if (agg->numChildren >= agg->childrenCap) {
47 agg->childrenCap = agg->childrenCap ? agg->childrenCap * 2 : 1;
48 agg->children = (__typeof__(agg->children))rm_realloc(
49 agg->children, agg->childrenCap * sizeof(RSIndexResult *));
50 }
51 agg->children[agg->numChildren++] = child;
52 // update the parent's type mask
53 agg->typeMask |= child->type;
54 parent->freq += child->freq;
55 parent->docId = child->docId;
56 parent->fieldMask |= child->fieldMask;
57 }
58 /* Create a deep copy of the results that is totall thread safe. This is very slow so use it with
59 * caution */
60 RSIndexResult *IndexResult_DeepCopy(const RSIndexResult *res);
61
62 /* Debug print a result */
63 void IndexResult_Print(RSIndexResult *r, int depth);
64
65 /* Free an index result's internal allocations, does not free the result itself */
66 void IndexResult_Free(RSIndexResult *r);
67
68 /* Get the minimal delta between the terms in the result */
69 int IndexResult_MinOffsetDelta(const RSIndexResult *r);
70
71 /* Fill an array of max capacity cap with all the matching text terms for the result. The number of
72 * matching terms is returned */
73 size_t IndexResult_GetMatchedTerms(RSIndexResult *r, RSQueryTerm **arr, size_t cap);
74
75 /* Return 1 if the the result is within a given slop range, inOrder determines whether the tokens
76 * need to be ordered as in the query or not */
77 int IndexResult_IsWithinRange(RSIndexResult *r, int maxSlop, int inOrder);
78
79 #ifdef __cplusplus
80 }
81 #endif
82 #endif