You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by GitBox <gi...@apache.org> on 2020/09/23 13:06:06 UTC

[GitHub] [lucenenet] theolivenbaum commented on issue #350: Change ScoreDoc to struct?

theolivenbaum commented on issue #350:
URL: https://github.com/apache/lucenenet/issues/350#issuecomment-697351627


   It seems like there are only 3 classes that derive from `ScoreDoc`: `OneGroup`, `FieldDoc`, `FieldValueHitQueue.Entry`
   
   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:
   
   ````csharp
   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:
users@infra.apache.org