Skip to content
Permalink
Browse files

_id is now optional in http/json results

  • Loading branch information...
glookka committed Jul 18, 2019
1 parent e212f5f commit ae3ccdc570984b8fe768e25a25180c28debf6e39
Showing with 8 additions and 3 deletions.
  1. +8 −3 src/sphinxjsonquery.cpp
@@ -1860,7 +1860,6 @@ CSphString sphEncodeResultJson ( const AggrResult_t & tRes, const CSphQuery & tQ
tOut.StartBlock ( ",", R"("hits":[)", "]" );

const CSphColumnInfo * pId = tSchema.GetAttr ( sphGetDocidName() );
assert(pId);

for ( int iMatch=tRes.m_iOffset; iMatch<tRes.m_iOffset+tRes.m_iCount; ++iMatch )
{
@@ -1869,8 +1868,14 @@ CSphString sphEncodeResultJson ( const AggrResult_t & tRes, const CSphQuery & tQ
ScopedComma_c sQueryComma ( tOut, ",", "{", "}" );

// note, that originally there is string UID, so we just output number in quotes for docid here
DocID_t tDocID = tMatch.GetAttr ( pId->m_tLocator );
tOut.Sprintf ( R"("_id":"%l","_score":%d)", tDocID, tMatch.m_iWeight );
if ( pId )
{
DocID_t tDocID = tMatch.GetAttr ( pId->m_tLocator );
tOut.Sprintf ( R"("_id":"%l","_score":%d)", tDocID, tMatch.m_iWeight );
}
else
tOut.Sprintf ( R"("_score":%d)", tMatch.m_iWeight );

tOut.StartBlock ( ",", "\"_source\":{", "}");

for ( int iAttr=0; iAttr<nSchemaAttrs; iAttr++ )

0 comments on commit ae3ccdc

Please sign in to comment.
You can’t perform that action at this time.