sort str facets by their int values (str hashes) for consistency for now

since we do not know the strings themselves at that time in Msg40.cpp
This commit is contained in:
mwells
2014-09-10 08:22:11 -07:00
parent 8f14207fc9
commit cc76a36458

@ -6134,6 +6134,7 @@ bool Msg40::printFacetTables ( SafeBuf *sb ) {
}
HashTableX *g_fht = NULL;
QueryTerm *g_qt = NULL;
// sort facets by document counts before displaying
static int feCmp ( const void *a1, const void *b1 ) {
@ -6141,7 +6142,14 @@ static int feCmp ( const void *a1, const void *b1 ) {
long b = *(long *)b1;
FacetEntry *fe1 = (FacetEntry *)g_fht->getValFromSlot(a);
FacetEntry *fe2 = (FacetEntry *)g_fht->getValFromSlot(b);
return (fe2->m_count - fe1->m_count);
if ( fe2->m_count > fe1->m_count ) return 1;
if ( fe2->m_count < fe1->m_count ) return -1;
long *k1 = (long *)g_fht->getKeyFromSlot(a);
long *k2 = (long *)g_fht->getKeyFromSlot(b);
if ( g_qt->m_fieldCode == FIELD_GBFACETFLOAT )
return (int)( *(float *)k2 - *(float *)k1 );
// otherwise an int
return ( *k2 - *k1 );
}
bool Msg40::printFacetsForTable ( SafeBuf *sb , QueryTerm *qt ) {
@ -6163,6 +6171,7 @@ bool Msg40::printFacetsForTable ( SafeBuf *sb , QueryTerm *qt ) {
}
// use this as global for qsort
g_fht = fht;
g_qt = qt;
// use qsort
gbqsort ( ptrs , numPtrs , sizeof(long) , feCmp , 0 );