Esempio n. 1
0
        public static long PeekValueFromData(byte[] data, IndexDataType sIndex, int index)
        {
            switch (sIndex)
            {
            case IndexDataType.Int8:
            {
                return(data[index]);
            }

            case IndexDataType.Int16:
            {
                return(BitConverter.ToInt16(data, index));
            }

            case IndexDataType.Int32:
            {
                return(BitConverter.ToInt32(data, index));
            }

            case IndexDataType.Int64:
            {
                return(BitConverter.ToInt64(data, index));
            }
            }
            return(-1);
        }
Esempio n. 2
0
        /// <summary>
        /// 根据数据对象信息,添加数据索引
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item"></param>
        /// <returns></returns>
        public async Task <SearcherResult> Add <T>(T item) where T : BaseIndexModel
        {
            IndexDataType dataType = default(IndexDataType);

            Type type = item.GetType();

            if (type == typeof(Job))
            {
                dataType = IndexDataType.Job;
            }
            else if (type == typeof(Merchant))
            {
                dataType = IndexDataType.Merchant;
            }
            else if (type == typeof(MerchantProduct))
            {
                dataType = IndexDataType.MerchantProduct;
            }
            else if (type == typeof(MallProduct))
            {
                dataType = IndexDataType.MallProduct;
            }

            var config = ApiConfigRoot.Configs.FirstOrDefault(p => p.DataType == dataType && p.ActionMode == ActionMode.InsertByEntity);

            var dicParameter = DicMapper.ToMap(item);

            return(await DoWork(dicParameter, config));
        }
Esempio n. 3
0
 public AdditionalHeader(string name, int startIndex, int value, IndexDataType dataType)
 {
     Name       = name;
     StartIndex = startIndex;
     Value      = value;
     DataType   = dataType;
 }
Esempio n. 4
0
 public BasicHeaderInfo(bool chekcedPacketSize, bool checkedPacketID, int indexPacketSize, int indexPacketID, IndexDataType dIndexPacketSize, IndexDataType dIndexPacketID)
 {
     CheckedPacketSize = chekcedPacketSize;
     CheckedPacketID   = checkedPacketID;
     IndexPacketSize   = indexPacketSize;
     IndexPacketID     = indexPacketID;
     DIndexPacketSize  = dIndexPacketSize;
     DIndexPacketID    = dIndexPacketID;
 }
Esempio n. 5
0
 /// <summary>
 /// 将删除文件添加到队列结尾
 /// </summary>
 /// <param name="dataType"></param>
 /// <param name="areaID"></param>
 /// <param name="ids"></param>
 public void Delete(IndexDataType dataType, int areaID, IEnumerable <long> ids)
 {
     if (null != ids)
     {
         foreach (var id in ids)
         {
             Delete(dataType, areaID, id);
         }
     }
 }
Esempio n. 6
0
        /// <summary>
        /// 将删除文件添加到队列结尾
        /// </summary>
        /// <param name="dataType"></param>
        /// <param name="areaID"></param>
        /// <param name="id"></param>
        public void Delete(IndexDataType dataType, int areaID, long id)
        {
            if (id > 0)
            {
                QueueModel model = new QueueModel();
                model.ActionMode = ActionMode.Delete;
                model.Data       = null;
                model.DataType   = dataType;
                model.ID         = id;
                model.AreaID     = areaID;

                indexQueue.Enqueue(model);
            }
        }
Esempio n. 7
0
        private uint IndexDataTypeSize(IndexDataType type)
        {
            switch (type)
            {
            case IndexDataType.UInt: return(4);

            case IndexDataType.UShort: return(2);

            case IndexDataType.UByte: return(1);
            }

            Log.Core.Error("unknown index data type given to buffer element");
            return(0);
        }
Esempio n. 8
0
        /// <summary>
        /// 初始化索引文件
        /// </summary>
        /// <param name="dataType"><seealso cref="IndexDataType"/>成员</param>
        public async Task <SearcherResult> Init(IndexDataType dataType)
        {
            var config = ApiConfigRoot.Configs.FirstOrDefault(p => p.DataType == dataType && p.ActionMode == ActionMode.Init);

            if (null == config || string.IsNullOrWhiteSpace(config.Url))
            {
                return new SearcherResult
                       {
                           Content    = "接口配置信息无效",
                           Exception  = null,
                           StatusCode = 0,
                           Timespan   = TimeSpan.Zero
                       }
            }
            ;

            return(await DoWork(null, config));
        }
        /// <summary>
        /// 搜索指定类型的数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="dataType"></param>
        /// <param name="areaID"></param>
        /// <param name="keyword"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        private List <T> SearchData <T>(IndexDataType dataType, int?areaID, string keyword, int pageIndex, int pageSize, out int count) where T : BaseIndexModel
        {
            string indexPath = string.Empty;

            switch (dataType)
            {
            case IndexDataType.Job: indexPath = IndexConfiguration.GetJobPath(); break;

            case IndexDataType.MallProduct: indexPath = IndexConfiguration.GetMallProductPath(); break;

            case IndexDataType.Merchant: indexPath = IndexConfiguration.GetMerchantPath(); break;

            case IndexDataType.MerchantProduct: indexPath = IndexConfiguration.GetMerchantProductPath(); break;
            }

            List <string> fields = new List <string> {
                "name"
            };                                                //, "desc"

            BooleanQuery bquery = new BooleanQuery();

            //分词器
            Analyzer analyzer = new StandardAnalyzer(IndexConfiguration.LuceneMatchVersion);

            //搜索条件
            Query kwdQuery = MultiFieldQueryParser.Parse(IndexConfiguration.LuceneMatchVersion, keyword, fields.ToArray(), new Occur[] { Occur.SHOULD }, analyzer);//, Occur.SHOULD

            bquery.Add(kwdQuery, Occur.MUST);

            if (areaID.HasValue && areaID.Value > 0)
            {
                Query query = new QueryParser(IndexConfiguration.LuceneMatchVersion, "areaid", analyzer).Parse(areaID.Value.ToString());

                bquery.Add(query, Occur.MUST);
            }

            Sort sort = new Sort(new SortField("updatetime", SortField.STRING, true));

            count = 0;

            var list = SearchHelper.Search <T>(indexPath, bquery, sort, pageIndex, pageSize, out count);

            return(list);
        }
Esempio n. 10
0
        /// <summary>
        /// 根据数据类型及ID,添加数据索引
        /// </summary>
        /// <param name="dataType"><seealso cref="IndexDataType"/>成员</param>
        /// <param name="dataID"></param>
        public async Task <SearcherResult> Add(IndexDataType dataType, long dataID)
        {
            var config = ApiConfigRoot.Configs.FirstOrDefault(p => p.DataType == dataType && p.ActionMode == ActionMode.InsertByID);

            string parameterName = "id";

            switch (dataType)
            {
            case IndexDataType.Job: parameterName = "jobID"; break;

            case IndexDataType.MallProduct: parameterName = "productID"; break;

            case IndexDataType.Merchant: parameterName = "merchantID"; break;

            case IndexDataType.MerchantProduct: parameterName = "productID"; break;
            }

            Dictionary <string, string> dicParameter = new Dictionary <string, string>();

            dicParameter.Add(parameterName, dataID.ToString());

            return(await DoWork(dicParameter, config));
        }
Esempio n. 11
0
        public static byte[] HeaderToByteArray(IndexDataType dIndex, int value)
        {
            byte[] result = null;
            switch (dIndex)
            {
            case IndexDataType.Int8:
            {
                result = BitConverter.GetBytes((byte)value);
                break;
            }

            case IndexDataType.Int16:
            {
                result = BitConverter.GetBytes((Int16)value);
                break;
            }

            case IndexDataType.Int32:
            {
                result = BitConverter.GetBytes((Int32)value);
                break;
            }

            case IndexDataType.Int64:
            {
                result = BitConverter.GetBytes((Int64)value);
                break;
            }

            default:
            {
                break;
            }
            }
            return(result);
        }
        public IActionResult SearchCustom(int areaID, string keyword, string typeLen)
        {
            if (string.IsNullOrWhiteSpace(typeLen))
            {
                typeLen = string.Empty;
            }

            string[] fields = new[] { "name" };           //, "desc"

            Occur[] flags = new Occur[] { Occur.SHOULD }; //, Occur.SHOULD

            Sort sort = new Sort(new SortField("updatetime", SortField.STRING, true));

            Dictionary <IndexDataType, int> dicTypeLen = new Func <string, Dictionary <IndexDataType, int> >((str) =>
            {
                Dictionary <IndexDataType, int> rst = new Dictionary <IndexDataType, int>();

                string[] tlArr = typeLen.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                foreach (var tl in tlArr)
                {
                    string[] temp = tl.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries);

                    if (temp.Length != 2)
                    {
                        continue;
                    }

                    IndexDataType dt = (IndexDataType)Enum.Parse(typeof(IndexDataType), temp[0]);

                    int len = 0;
                    int.TryParse(temp[1], out len);

                    if (len > 0)
                    {
                        rst[dt] = len;
                    }
                }
                return(rst);
            }).Invoke(typeLen);

            CustomViewModel result = new CustomViewModel();

            if (dicTypeLen.Count > 0)
            {
                foreach (var kv in dicTypeLen)
                {
                    int count = 0;

                    switch (kv.Key)
                    {
                    case IndexDataType.Job:
                        var _joblist = SearchData <Job>(IndexDataType.Job, Location.OperatorArea, keyword, 1, kv.Value, out count);
                        result.Job = new ViewData <Job>
                        {
                            Count = count,
                            Data  = _joblist
                        };
                        break;

                    case IndexDataType.MallProduct:
                        var _mallprolist = SearchData <MallProduct>(IndexDataType.MallProduct, Location.OperatorArea, keyword, 1, kv.Value, out count);
                        result.MallProduct = new ViewData <MallProduct>
                        {
                            Count = count,
                            Data  = _mallprolist
                        };
                        break;

                    case IndexDataType.Merchant:
                        var _merchantlist = SearchData <Merchant>(IndexDataType.Merchant, Location.OperatorArea, keyword, 1, kv.Value, out count);
                        result.Merchant = new ViewData <Merchant>
                        {
                            Count = count,
                            Data  = _merchantlist
                        };
                        break;

                    case IndexDataType.MerchantProduct:
                        var _merchantprolist = SearchData <MerchantProduct>(IndexDataType.MerchantProduct, Location.OperatorArea, keyword, 1, kv.Value, out count);
                        result.MerchantProduct = new ViewData <MerchantProduct>
                        {
                            Count = count,
                            Data  = _merchantprolist
                        };
                        break;
                    }
                }
            }

            return(Success(result));
        }
Esempio n. 13
0
        public IndexKey(object value)
        {
            this.Value    = value;
            this.IsNumber = false;

            // null
            if (value == null)
            {
                this.Type = IndexDataType.Null; this.Length = 0;
            }

            // int
            else if (value is Byte)
            {
                this.Type = IndexDataType.Byte; this.Length = 1; this.IsNumber = true;
            }
            else if (value is Int16)
            {
                this.Type = IndexDataType.Int16; this.Length = 2; this.IsNumber = true;
            }
            else if (value is UInt16)
            {
                this.Type = IndexDataType.UInt16; this.Length = 2; this.IsNumber = true;
            }
            else if (value is Int32)
            {
                this.Type = IndexDataType.Int32; this.Length = 4; this.IsNumber = true;
            }
            else if (value is UInt32)
            {
                this.Type = IndexDataType.UInt32; this.Length = 4; this.IsNumber = true;
            }
            else if (value is Int64)
            {
                this.Type = IndexDataType.Int64; this.Length = 8; this.IsNumber = true;
            }
            else if (value is UInt64)
            {
                this.Type = IndexDataType.UInt64; this.Length = 8; this.IsNumber = true;
            }

            // decimal
            else if (value is Single)
            {
                this.Type = IndexDataType.Single; this.Length = 4; this.IsNumber = true;
            }
            else if (value is Double)
            {
                this.Type = IndexDataType.Double; this.Length = 8; this.IsNumber = true;
            }
            else if (value is Decimal)
            {
                this.Type = IndexDataType.Decimal; this.Length = 16; this.IsNumber = true;
            }

            // string
            else if (value is String)
            {
                this.Type = IndexDataType.String; this.Length = Encoding.UTF8.GetByteCount((string)Value) + 1 /* +1 = For String Length on store */;
            }

            // Others
            else if (value is Boolean)
            {
                this.Type = IndexDataType.Boolean; this.Length = 1;
            }
            else if (value is DateTime)
            {
                this.Type = IndexDataType.DateTime; this.Length = 8;
            }
            else if (value is Guid)
            {
                this.Type = IndexDataType.Guid; this.Length = 16;
            }

            // if not found, exception
            else
            {
                throw LiteException.IndexTypeNotSupport(value.GetType());
            }

            // increase "Type" byte in length
            this.Length++;

            // withespace empty string == null
            if (this.Type == IndexDataType.String && ((string)value).Trim().Length == 0)
            {
                this.Value  = null;
                this.Type   = IndexDataType.Null;
                this.Length = 1;
            }

            // limit in 255 string bytes
            if (this.Type == IndexDataType.String && this.Length > MAX_LENGTH_SIZE)
            {
                throw LiteException.IndexKeyTooLong();
            }
        }