示例#1
0
        /// <summary>
        /// Get possible questions using index.
        /// </summary>
        /// <param name="initial">The initial index.</param>
        /// <param name="limit">The maximum records.</param>
        /// <returns>All possible questions.</returns>
        public List <Question> getQuestion(string initial, int limit = 10)
        {
            if (!sorted)
            {
                sort();
            }
            long indexLow, indexHigh;
            Tuple <long, long> resultTuple = QuestionIndex.getPossibleIndex(initial);

            indexLow  = resultTuple.Item1;
            indexHigh = resultTuple.Item2;
            int locationLow = allQuestion.BinarySearch(new Question(indexLow, "", ""), (q1, q2) => q1.index.CompareTo(q2.index));

            if (locationLow < 0)
            {
                locationLow = -locationLow - 1;                  // only one -1 since we need to take the previous one
            }
            int locationHigh = allQuestion.BinarySearch(new Question(indexHigh, "", ""), (q1, q2) => q1.index.CompareTo(q2.index));

            if (locationHigh < 0)
            {
                locationHigh = -locationHigh - 1 - 1;                   //first for index inversion, second for not picking the one just larger than locationHigh.
            }
            List <Question> result = new List <Question>();

            for (int i = locationLow; i <= locationHigh; i++)
            {
                result.Add(allQuestion[i]);
                if (result.Count > limit)
                {
                    break;
                }
            }
            return(result);
        }
示例#2
0
        public static List <Question> getQuestion(string q, string a, string text = "")
        {
            List <Question> result      = new List <Question>();
            List <string>   allInitials = pinyin.getAllPossibleInitials(q);

            foreach (string s in allInitials)
            {
                if (String.IsNullOrWhiteSpace(text))
                {
                    result.Add(new Question(QuestionIndex.getPreciseIndex(s), q, a, q));
                }
                else
                {
                    result.Add(new Question(QuestionIndex.getPreciseIndex(s), q, a, text));
                }
            }
            return(result);
        }