print avg,min,max in facet stats in xml/json output

This commit is contained in:
Matt Wells
2014-12-11 12:28:04 -08:00
parent cd7ce466a1
commit daebad6e79
2 changed files with 77 additions and 18 deletions

@ -6413,12 +6413,12 @@ bool Msg40::printFacetsForTable ( SafeBuf *sb , QueryTerm *qt ) {
"\t\t<docCount>%"INT32""
"</docCount>\n"
,count);
// some stats now
// some stats now for floats
if ( isFloat && fe->m_count ) {
sb->safePrintf("\t\t<average>");
float sum = *(float *)&fe->m_sum;
float avg = sum/(float)fe->m_count;
sb->printFloatPretty ( avg );
double sum = *(double *)&fe->m_sum;
double avg = sum/(double)fe->m_count;
sb->printFloatPretty ( (float)avg );
sb->safePrintf("\t\t</average>\n");
sb->safePrintf("\t\t<min>");
float min = *(float *)&fe->m_min;
@ -6429,8 +6429,20 @@ bool Msg40::printFacetsForTable ( SafeBuf *sb , QueryTerm *qt ) {
sb->printFloatPretty ( max );
sb->safePrintf("</max>\n");
}
// some stats now for ints
if ( isInt && fe->m_count ) {
sb->safePrintf("\t\t<average>");
int64_t sum = fe->m_sum;
double avg = (double)sum/(double)fe->m_count;
sb->printFloatPretty ( (float)avg );
sb->safePrintf("\t\t</average>\n");
sb->safePrintf("\t\t<min>");
int32_t min = fe->m_min;
sb->safePrintf("%"INT32"</min>\n",min);
sb->safePrintf("\t\t<max>");
int32_t max = fe->m_max;
sb->safePrintf("%"INT32"</max>\n",max);
}
sb->safePrintf("\t</facet>\n");
continue;
}
@ -6501,8 +6513,49 @@ bool Msg40::printFacetsForTable ( SafeBuf *sb , QueryTerm *qt ) {
// just use quotes for ranges like "[1-3)" now
sb->safePrintf("\"");
sb->safePrintf(",\n"
"\t\"docCount\":%"INT32"\n"
"}\n,\n", count);
"\t\"docCount\":%"INT32""
, count );
// if it's a # then we print stats after
if ( isString )
sb->safePrintf("\n");
else
sb->safePrintf(",\n");
// some stats now for floats
if ( isFloat && fe->m_count ) {
sb->safePrintf("\t\"average\":");
double sum = *(double *)&fe->m_sum;
double avg = sum/(double)fe->m_count;
sb->printFloatPretty ( (float)avg );
sb->safePrintf(",\n");
sb->safePrintf("\t\"min\":");
float min = *(float *)&fe->m_min;
sb->printFloatPretty ( min );
sb->safePrintf(",\n");
sb->safePrintf("\t\"max\":");
float max = *(float *)&fe->m_max;
sb->printFloatPretty ( max );
sb->safePrintf("\n");
}
// some stats now for ints
if ( isInt && fe->m_count ) {
sb->safePrintf("\t\"average\":");
int64_t sum = fe->m_sum;
double avg = (double)sum/(double)fe->m_count;
sb->printFloatPretty ( (float)avg );
sb->safePrintf(",\n");
sb->safePrintf("\t\"min\":");
int32_t min = fe->m_min;
sb->safePrintf("%"INT32",\n",min);
sb->safePrintf("\t\"max\":");
int32_t max = fe->m_max;
sb->safePrintf("%"INT32"\n",max);
}
sb->safePrintf("}\n,\n" );
continue;
}

@ -7190,7 +7190,7 @@ void PosdbTable::intersectLists10_r ( ) {
qt->m_fieldCode != FIELD_GBFACETINT &&
qt->m_fieldCode != FIELD_GBFACETFLOAT )
continue;
char *p = miniMergedList[i];
char *p2 = miniMergedList[i];
//char *pend = miniMergedEnd [i];
//
// just grab the first value i guess...
@ -7202,12 +7202,15 @@ void PosdbTable::intersectLists10_r ( ) {
// the same gbxpathsitehash...
bool firstTime = true;
//int32_t lastVal;
// loop over entire termlist
for ( ; ; ) {
// do not breach sublist
if ( p >= miniMergedEnd[i] ) break;
if ( p2 >= miniMergedEnd[i] ) break;
// break if 12 byte key: another docid!
if ( ! firstTime && !(p[0] & 0x04) ) break;
if ( ! firstTime && !(p2[0] & 0x04) ) break;
// . first key is the full size
// . uses the w,G,s,v and F bits to hold this
@ -7215,7 +7218,16 @@ void PosdbTable::intersectLists10_r ( ) {
// can be any val, like now SectionStats is
// using it for the innerHtml sentence
// content hash32
int32_t val32 = g_posdb.getFacetVal32 ( p );
int32_t val32 = g_posdb.getFacetVal32 ( p2 );
// PREADVANCE "p"
// to avoid dupage...
//lastVal = val32;
// skip over 6 or 12 byte key
if ( firstTime ) p2 += 12;
else p2 += 6;
firstTime = false;
float *fp = (float *)&val32;
@ -7336,12 +7348,6 @@ void PosdbTable::intersectLists10_r ( ) {
}
// to avoid dupage...
//lastVal = val32;
// skip over 6 or 12 byte key
if ( firstTime ) p += 12;
else p += 6;
firstTime = false;
}
}