コード例 #1
0
        /// <summary>
        /// Converts an byte array to a list of postings for a term.
        /// The byte array should follow the form
        /// < df, (docID tf p1 p2 p3), (doc2 tf p1 p2), ... >
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public List <Posting> Decoding(byte[] value)
        {
            List <int> integers = VariableBytes.DecompressToInts(value);
            // Read and construct a posting list from bytes from postings.bin
            // < df, (docID tf p1 p2 p3), (doc2 tf p1 p2), ... >
            // docIDs and positions are written as gap)

            List <Posting> postings = new List <Posting>();
            int            index    = 0;
            //1. Read document frequency
            int docFrequency = integers[index++];

            int prevDocID = 0;

            for (int i = 0; i < docFrequency; i++)         //for each posting
            {
                //2. Read documentID using gap
                int docID = prevDocID + integers[index++];

                List <int> positions = new List <int>();

                //3. Read term frequency
                int termFrequency = integers[index++];

                //4. Read positions using gap
                int prevPos = 0;
                for (int j = 0; j < termFrequency; j++)    //for each position
                {
                    int pos = prevPos + integers[index++];
                    positions.Add(pos);
                    prevPos = pos;  //update prevPos
                }

                //Insert a posting to the posting list
                postings.Add(new Posting(docID, positions));

                prevDocID = docID;  //update prevDocID
            }

            return(postings);
        }
コード例 #2
0
        /// <summary>
        /// Decode bytes to Inverted
        /// </summary>
        /// <param name="value">Bytes</param>
        /// <returns>List of integers</returns>
        public List <MaxPriorityQueue.InvertedIndex> Decoding(byte[] value)
        {
            List <int> integers = VariableBytes.DecompressToInts(value);


            List <MaxPriorityQueue.InvertedIndex> tierPostings = new List <MaxPriorityQueue.InvertedIndex>();

            int index = 0;

            int docFrequency = integers[index++];

            int previousDocId = 0;

            for (int i = 0; i < docFrequency; i++)
            {
                //Read documentID using gap
                int docID    = previousDocId + integers[index++];
                int termFreq = integers[index++];
                tierPostings.Add(new MaxPriorityQueue.InvertedIndex(termFreq, docID));
                previousDocId = docID;
            }

            return(tierPostings);
        }
コード例 #3
0
 /// <summary>
 /// Decode bytes to list of integers
 /// </summary>
 /// <param name="value">Bytes</param>
 /// <returns>List of integers</returns>
 public List <int> Decoding(byte[] value)
 {
     return(VariableBytes.DecompressToInts(value));
 }