lucenenet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <>
Subject [GitHub] [lucenenet] theolivenbaum commented on issue #350: Change ScoreDoc to struct?
Date Wed, 23 Sep 2020 13:06:06 GMT

theolivenbaum commented on issue #350:

   It seems like there are only 3 classes that derive from `ScoreDoc`: `OneGroup`, `FieldDoc`,
   One possible way to go about this (as we can't use generics, and using an interface on
the struct will result in boxing anyway), would be to add two fields to ScoreDoc, one to hold
the expected content type, and the other to hold the content:
   public struct ScoreDoc
       private byte _contentType;
       private object _content;
       public float Score { get; }
       public int Doc { get; }
       public int ShardIndex { get; } 
       public bool IsNull() => _contentType == 0;
       public bool IsNotNull() => _contentType != 0;
       public bool IsFieldDoc() => _contentType == _fieldDocType;
       public bool IsEntry() => _contentType == _entryType || _contentType == _oneGroupType;
// OneGroupContent derives from Entry
       public bool IsOneGroup() => _contentType == _oneGroupType ;
       private const byte _scoreDocType = 1;
       private const byte _fieldDocType = 2;
       private const byte _entryType = 3;
       private const byte _oneGroupType = 4;
       public FieldDocContent AsFieldDoc() 
           if(IsFieldDoc()) return (FieldDocContent)_content;
           throw new Exception("Invalid type");
       public EntryContent AsEntry() 
           if(IsEntry()) return (EntryContent )_content;
           throw new Exception("Invalid type");
       public OneGroupContent AsOneGroup() 
           if(IsOneGroup()) return (OneGroupContent )_content;
           throw new Exception("Invalid type");

This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:

View raw message