Exemple #1
0
        unsafe public void Prepare(DocumentResultForSort[] docResults)
        {
            for (int index = 0; index < _SortFieldsCount; index++)
            {
                bool asc;
                if (index == 0)
                {
                    asc = _Asc1;
                }
                else
                {
                    asc = _Asc2;
                }

                if (_OrderBys[index].Name.Equals("DocId", StringComparison.CurrentCultureIgnoreCase))
                {
                    for (int i = 0; i < docResults.Length; i++)
                    {
                        if (index == 0)
                        {
                            docResults[i].SortValue = docResults[i].DocId;
                        }
                        else
                        {
                            docResults[i].SortValue1 = docResults[i].DocId;
                        }
                    }
                }
                else if (_OrderBys[index].Name.Equals("Score", StringComparison.CurrentCultureIgnoreCase))
                {
                    for (int i = 0; i < docResults.Length; i++)
                    {
                        if (index == 0)
                        {
                            docResults[i].SortValue = docResults[i].Score;
                        }
                        else
                        {
                            docResults[i].SortValue1 = docResults[i].Score;
                        }
                    }
                }
                else
                {
                    Data.Field field = _DBProvider.GetField(_OrderBys[index].Name);

                    if (field != null)
                    {
                        if (field.IndexType != Hubble.Core.Data.Field.Index.Untokenized)
                        {
                            throw new ParseException(string.Format("Order by field name:{0} is not Untokenized Index!", _OrderBys[index].Name));
                        }


                        switch (field.DataType)
                        {
                        case Hubble.Core.Data.DataType.Date:
                        case Hubble.Core.Data.DataType.SmallDateTime:
                        case Hubble.Core.Data.DataType.Int:
                        case Hubble.Core.Data.DataType.SmallInt:
                        case Hubble.Core.Data.DataType.TinyInt:
                        {
                            _DBProvider.FillPayloadData(docResults);

                            for (int i = 0; i < docResults.Length; i++)
                            {
                                int *payLoadData = docResults[i].PayloadData;

                                Query.SortInfo sortInfo = Data.DataTypeConvert.GetSortInfo(asc, field.DataType,
                                                                                           payLoadData, field.TabIndex, field.SubTabIndex, field.DataLength);

                                if (index == 0)
                                {
                                    docResults[i].SortValue = sortInfo.IntValue;
                                }
                                else
                                {
                                    docResults[i].SortValue1 = sortInfo.IntValue;
                                }
                            }
                        }
                        break;

                        case Hubble.Core.Data.DataType.BigInt:
                        case Hubble.Core.Data.DataType.DateTime:
                        {
                            _DBProvider.FillPayloadData(docResults);

                            for (int i = 0; i < docResults.Length; i++)
                            {
                                int *payLoadData = docResults[i].PayloadData;

                                Query.SortInfo sortInfo = Data.DataTypeConvert.GetSortInfo(asc, field.DataType,
                                                                                           payLoadData, field.TabIndex, field.SubTabIndex, field.DataLength);

                                if (index == 0)
                                {
                                    docResults[i].SortValue = sortInfo.LongValue;
                                }
                                else
                                {
                                    docResults[i].SortValue1 = sortInfo.LongValue;
                                }
                            }
                        }
                        break;

                        case Hubble.Core.Data.DataType.Float:
                        {
                            _DBProvider.FillPayloadData(docResults);

                            for (int i = 0; i < docResults.Length; i++)
                            {
                                int *payLoadData = docResults[i].PayloadData;

                                Query.SortInfo sortInfo = Data.DataTypeConvert.GetSortInfo(asc, field.DataType,
                                                                                           payLoadData, field.TabIndex, field.SubTabIndex, field.DataLength);

                                if (index == 0)
                                {
                                    docResults[i].SortValue = (long)(sortInfo.DoubleValue * 1000);
                                }
                                else
                                {
                                    docResults[i].SortValue1 = (long)(sortInfo.DoubleValue * 1000);
                                }
                            }
                        }
                        break;
                        }
                    }
                }
            }
        }