/// <summary> /// Creates a new sprite of a data gield /// </summary> /// <param name="game">Game to bind to</param> /// <param name="source">Field data</param> public SpriteField(Game game, Data.Field source) : base(game) { this.Source = source; this.TextureName = "Graphics/blank"; this.Size = (SpriteField.GridCellSize - 1) * Vector2.One; }
/// <summary> /// Initializes spriteset /// </summary> public override void Initialize() { _spritesLeft = new List <Sprite>(); _spritesRight = new List <Sprite>(); var block = new Block(this.Type); _field = new DummyField(this.Game, block.Width + 4, block.Height + 4 + SpriteField.HiddenRows); // Add for each rotation left for (Int32 i = 0; i < 4; i++) { // Get kick values and make sprites _spritesLeft.AddRange(GetMovementSprites(block, WallkickData.LeftMovements[new Tuple <int, int>(block.Width, block.Rotation)], block.Rotation + 1, i)); block.Rotation--; } // Add for each rotation right for (Int32 i = 0; i < 4; i++) { // Get kick values and make sprites _spritesRight.AddRange(GetMovementSprites(block, WallkickData.RightMovements[new Tuple <int, int>(block.Width, block.Rotation)], block.Rotation - 1, i)); block.Rotation++; } foreach (var sprite in _spritesLeft) { sprite.Initialize(); } foreach (var sprite in _spritesRight) { sprite.Initialize(); } }
private void Init() { Data.Field rankField = Argument.DBProvider.GetField("Rank"); if (rankField != null) { if (rankField.DataType == Hubble.Core.Data.DataType.Int && rankField.IndexType == Hubble.Core.Data.Field.Index.Untokenized) { _HasRankField = true; } } }
unsafe public static void Generate(ref Docid2Long docid2Long, Data.DBProvider dbProvider, Data.Field[] orderByFields, long score) { int *p = dbProvider.GetPayloadDataWithShareLock(docid2Long.DocId); if (p == null) { throw new Data.DataException(string.Format("DocId={0} does not exist in Payload", docid2Long.DocId)); } for (int i = 0; i < orderByFields.Length; i++) { Data.Field field = orderByFields[i]; long value; if (field.Name == "score") { value = score; } else if (field.Name == "docid") { value = docid2Long.DocId; } else { value = Data.DataTypeConvert.GetLongAnyWay(field.DataType, p, field.TabIndex, field.SubTabIndex, field.DataLength); } switch (i) { case 0: docid2Long.Value1 = value; break; case 1: docid2Long.Value2 = value; break; case 2: docid2Long.Value3 = value; break; default: throw new Data.DataException("Order by fields length for optimization must be <= 3"); } } }
unsafe private void TestFillPayloadRank(string tableName) { OutputMessage("TestGetDocIdReplaceFieldValue"); AddColumn("Times"); AddColumn("Elapse(ms)"); AddColumn("ElapseOneTime(ms)"); Data.DBProvider dbProvider = Data.DBProvider.GetDBProvider(Parameters[0], false); if (dbProvider == null) { throw new DataException(string.Format("Table name {0} does not exist!", Parameters[0])); } Random rand = new Random(); int count = 1000000; int lastDocId = dbProvider.LastDocId; OriginalDocumentPositionList[] payloads = new OriginalDocumentPositionList[count]; for (int i = 0; i < payloads.Length; i++) { payloads[i] = new OriginalDocumentPositionList(i * 10); payloads[i].CountAndWordCount = 1; } payloads[0].DocumentId = 8 * payloads.Length; Data.Field rankField = dbProvider.GetField("Rank"); int tab = rankField.TabIndex; Stopwatch sw = new Stopwatch(); //int docid = rand.Next(lastDocId); sw.Start(); for (int j = 0; j < count / payloads.Length; j++) { dbProvider.FillPayloadRank(tab, count, payloads); } sw.Stop(); OutputValue("Times", count); OutputValue("Elapse(ms)", sw.ElapsedMilliseconds); OutputValue("ElapseOneTime(ms)", (double)sw.ElapsedMilliseconds / count); }
/// <summary> /// Can the order by be optimized. /// </summary> /// <returns></returns> static public bool GetOrderByCanBeOptimized(OrderBy[] orderBys, DBProvider dbProvider) { if (orderBys.Length > 3) { return(false); } if (orderBys.Length == 0) { return(false); } foreach (OrderBy orderBy in orderBys) { string fieldName = orderBy.Name; if (fieldName.Equals("docid", StringComparison.CurrentCultureIgnoreCase) || fieldName.Equals("score", StringComparison.CurrentCultureIgnoreCase)) { continue; } Data.Field field = dbProvider.GetField(fieldName); if (field.IndexType != Field.Index.Untokenized) { return(false); } if (field.DataType == DataType.Varchar || field.DataType == DataType.NChar || field.DataType == DataType.Data || field.DataType == DataType.Char || field.DataType == DataType.NChar) { return(false); } } return(true); }
unsafe internal void Sort(Query.DocumentResultForSort[] docResults, int top) { if (_OrderBys.Count <= 0) { return; } QueryResultHeapSort heapSort = new QueryResultHeapSort(_OrderBys, _DBProvider); if (heapSort.CanDo) { heapSort.Prepare(docResults); heapSort.TopSort(docResults, top); return; } foreach (SyntaxAnalysis.Select.OrderBy orderBy in _OrderBys) { Data.Field field = _DBProvider.GetField(orderBy.Name); Query.SortType sortType = Hubble.Core.Query.SortType.None; bool isDocId = false; bool isScore = false; bool isAsc = orderBy.Order.Equals("ASC", StringComparison.CurrentCultureIgnoreCase); if (field == null) { if (orderBy.Name.Equals("DocId", StringComparison.CurrentCultureIgnoreCase)) { sortType = Hubble.Core.Query.SortType.Long; isDocId = true; } else if (orderBy.Name.Equals("Score", StringComparison.CurrentCultureIgnoreCase)) { sortType = Hubble.Core.Query.SortType.Long; isScore = true; } else { throw new ParseException(string.Format("Unknown field name:{0}", orderBy.Name)); } } else { if (field.IndexType != Hubble.Core.Data.Field.Index.Untokenized) { throw new ParseException(string.Format("Order by field name:{0} is not Untokenized Index!", orderBy.Name)); } } for (int i = 0; i < docResults.Length; i++) { if (docResults[i].SortInfoList == null) { docResults[i].SortInfoList = new List <Hubble.Core.Query.SortInfo>(2); } if (isDocId) { docResults[i].SortInfoList.Add(new Hubble.Core.Query.SortInfo(isAsc, sortType, docResults[i].DocId)); } else if (isScore) { docResults[i].SortInfoList.Add(new Hubble.Core.Query.SortInfo(isAsc, sortType, docResults[i].Score)); } else { if (docResults[i].PayloadData == null) { int *payloadData = _DBProvider.GetPayloadData(docResults[i].DocId); if (payloadData == null) { throw new ParseException(string.Format("DocId={0} has not payload!", docResults[i].DocId)); } docResults[i].PayloadData = payloadData; } docResults[i].SortInfoList.Add(Data.DataTypeConvert.GetSortInfo(isAsc, field.DataType, docResults[i].PayloadData, field.TabIndex, field.SubTabIndex, field.DataLength)); } } } Array.Sort(docResults); //Has a bug of partial sort, make comments on following codes until it fixed. //if (top <= 0 || top >= docResults.Length/2) //{ // Array.Sort(docResults); //} //else //{ // QuickSort<Query.DocumentResult>.TopSort(docResults, top, new Query.DocumentResultComparer()); //} }
/// <summary> /// Get IdFields List from trigger table /// </summary> /// <param name="dbProvider">dbProvider that used to get field info</param> /// <param name="dbAdapterName">DBAdapter name</param> /// <param name="table">table that read from trigger table</param> /// <param name="lastSerial">the last serial number of trigger table from which read</param> /// <returns></returns> internal static List <IdFields> GetIdFieldsList(Data.DBProvider dbProvider, string dbAdapterName, System.Data.DataTable table, out long lastSerial) { lastSerial = -1; HashSet <string> fieldsSetWithTokenizedFields = new HashSet <string>(); HashSet <string> fieldsSetWithoutTokenizedFields = new HashSet <string>(); List <string> tempFields = new List <string>(128); List <IdFields> result = new List <IdFields>(table.Rows.Count); foreach (System.Data.DataRow row in table.Rows) { long id = long.Parse(row["id"].ToString()); lastSerial = long.Parse(row["Serial"].ToString()); string fields = row["Fields"].ToString(); tempFields.Clear(); bool hasTokenized = false; //check fields foreach (string field in fields.Split(new char[] { ',' })) { string f = field.Trim().ToLower(); if (f == "") { continue; } Data.Field dbField = dbProvider.GetField(f); if (dbField == null) { continue; } if (dbField.IndexType == Hubble.Core.Data.Field.Index.Tokenized) { hasTokenized = true; } tempFields.Add(f); } //Fill hash set if (hasTokenized) { foreach (string field in tempFields) { if (!fieldsSetWithTokenizedFields.Contains(field)) { fieldsSetWithTokenizedFields.Add(field); } } } else { foreach (string field in tempFields) { if (!fieldsSetWithoutTokenizedFields.Contains(field)) { fieldsSetWithoutTokenizedFields.Add(field); } } } result.Add(new IdFields(id, hasTokenized)); } //Get new fields string string fieldsWithTokenized = GetFieldsStringFromHashSet(fieldsSetWithTokenizedFields, dbAdapterName); string fieldsWithoutTokenized = GetFieldsStringFromHashSet(fieldsSetWithoutTokenizedFields, dbAdapterName); foreach (IdFields idFields in result) { if (idFields.HasTokenizedFields) { idFields.Fields = fieldsWithTokenized; } else { idFields.Fields = fieldsWithoutTokenized; } } //Merge same Id result.Sort(); if (result.Count > 0) { IdFields last = result[0]; for (int i = 1; i < result.Count; i++) { if (result[i].Equals(last)) { result[i] = null; continue; } else { last = result[i]; } } } return(result); }
public void CreateMirrorTable() { Debug.Assert(Table != null); List <string> primaryKeys = new List <string>(); StringBuilder sql = new StringBuilder(); sql.AppendFormat("create table {0} (", Table.DBTableName); if (Table.DocIdReplaceField != null) { primaryKeys.Add(Table.DocIdReplaceField); } else { primaryKeys.Add("DocId"); sql.Append("DocId Int NOT NULL,"); } int i = 0; for (i = 0; i < Table.Fields.Count; i++) { Data.Field field = Table.Fields[i]; string fieldSql = GetFieldLine(field); if (fieldSql != null) { sql.Append(fieldSql); if (i < Table.Fields.Count - 1) { sql.Append(","); } } } if (primaryKeys.Count > 0) { i = 0; sql.Append(" primary key ("); foreach (string pkName in primaryKeys) { if (i == 0) { sql.Append(pkName); } else { sql.Append("," + pkName); } i++; } sql.Append(")"); } sql.Append(")"); using (SQLDataProvider sqlData = new SQLDataProvider()) { sqlData.Connect(Table.ConnectionString); sqlData.ExcuteSql(sql.ToString()); if (!string.IsNullOrEmpty(Table.SQLForCreate)) { sqlData.ExcuteSql(Table.SQLForCreate); } } }
private string GetFieldLine(Data.Field field) { if (!field.Store) { return(null); } string sqlType = ""; string defaultValue = null; if (field.DefaultValue != null) { switch (field.DataType) { case DataType.TinyInt: case DataType.SmallInt: case Hubble.Core.Data.DataType.Int: case Hubble.Core.Data.DataType.BigInt: case Hubble.Core.Data.DataType.Float: defaultValue = field.DefaultValue; break; case Hubble.Core.Data.DataType.Date: case Hubble.Core.Data.DataType.SmallDateTime: case Hubble.Core.Data.DataType.DateTime: case Hubble.Core.Data.DataType.Varchar: case Hubble.Core.Data.DataType.NVarchar: case Hubble.Core.Data.DataType.Char: case Hubble.Core.Data.DataType.NChar: defaultValue = string.Format("'{0}'", field.DefaultValue.Replace("'", "''")); break; default: throw new ArgumentException(field.DataType.ToString()); } } switch (field.DataType) { case DataType.TinyInt: sqlType = "TinyInt"; break; case DataType.SmallInt: sqlType = "SmallInt"; break; case Hubble.Core.Data.DataType.Int: sqlType = "Int"; break; case Hubble.Core.Data.DataType.Date: case Hubble.Core.Data.DataType.SmallDateTime: case Hubble.Core.Data.DataType.DateTime: sqlType = "DateTime"; break; case Hubble.Core.Data.DataType.Float: sqlType = "Float"; break; case Hubble.Core.Data.DataType.BigInt: sqlType = "BigInt"; break; case Hubble.Core.Data.DataType.Varchar: sqlType = "varchar ({1})"; break; case Hubble.Core.Data.DataType.NVarchar: sqlType = "nvarchar ({1})"; break; case Hubble.Core.Data.DataType.Char: sqlType = "char ({1})"; break; case Hubble.Core.Data.DataType.NChar: sqlType = "nchar ({1})"; break; default: throw new ArgumentException(field.DataType.ToString()); } string sql = string.Format("[{0}] " + sqlType + " ", field.Name, field.DataLength <= 0 ? "max" : field.DataLength.ToString()); if (!field.CanNull) { sql += "NOT NULL "; } if (defaultValue != null) { sql += "DEFAULT " + defaultValue + " "; } return(sql); }
public void Create() { Debug.Assert(Table != null); //List<string> primaryKeys = new List<string>(); StringBuilder sql = new StringBuilder(); sql.AppendFormat("create table {0} (", Table.DBTableName); sql.Append("DocId Int NOT NULL Primary Key,"); int i = 0; for (i = 0; i < Table.Fields.Count; i++) { Data.Field field = Table.Fields[i]; string fieldSql = GetFieldLine(field); if (fieldSql != null) { sql.Append(fieldSql); if (i < Table.Fields.Count - 1) { sql.Append(","); } } //if (field.PrimaryKey) //{ // primaryKeys.Add(field.Name); //} } //if (primaryKeys.Count > 0) //{ // i = 0; // sql.Append(" primary key NONCLUSTERED("); // foreach (string pkName in primaryKeys) // { // if (i == 0) // { // sql.Append(pkName); // } // else // { // sql.Append("," + pkName); // } // i++; // } // sql.Append(")"); //} sql.Append(")"); using (OLEDataProvider sqlData = new OLEDataProvider()) { sqlData.Connect(Table.ConnectionString); sqlData.ExcuteSql(sql.ToString()); //sqlData.ExcuteSql(string.Format("create UNIQUE CLUSTERED Index I_{0}_DocId on {0}(DocId)", // Table.DBTableName)); if (!string.IsNullOrEmpty(Table.SQLForCreate)) { sqlData.ExcuteSql(Table.SQLForCreate); } } }
/// <summary> /// Initializes spriteset /// </summary> public override void Initialize() { _spritesLeft = new List<Sprite>(); _spritesRight = new List<Sprite>(); var block = new Block(this.Type); _field = new DummyField(this.Game, block.Width + 4, block.Height + 4 + SpriteField.HiddenRows); // Add for each rotation left for (Int32 i = 0; i < 4; i++) { // Get kick values and make sprites _spritesLeft.AddRange(GetMovementSprites(block, WallkickData.LeftMovements[new Tuple<int, int>(block.Width, block.Rotation)], block.Rotation + 1, i)); block.Rotation--; } // Add for each rotation right for (Int32 i = 0; i < 4; i++) { // Get kick values and make sprites _spritesRight.AddRange(GetMovementSprites(block, WallkickData.RightMovements[new Tuple<int, int>(block.Width, block.Rotation)], block.Rotation - 1, i)); block.Rotation++; } foreach (var sprite in _spritesLeft) sprite.Initialize(); foreach (var sprite in _spritesRight) sprite.Initialize(); }
private string GetFieldLine(Data.Field field) { if (!field.Store) { return(null); } string sqlType = ""; string defaultValue = null; if (field.DefaultValue != null) { switch (field.DataType) { case DataType.TinyInt: case DataType.SmallInt: case Hubble.Core.Data.DataType.Int: case Hubble.Core.Data.DataType.BigInt: case Hubble.Core.Data.DataType.Float: defaultValue = field.DefaultValue; break; case Hubble.Core.Data.DataType.Date: case Hubble.Core.Data.DataType.SmallDateTime: case Hubble.Core.Data.DataType.DateTime: DateTime dateTime; if (!DateTime.TryParseExact(field.DefaultValue, "yyyy-MM-dd HH:mm:ss", null, System.Globalization.DateTimeStyles.None, out dateTime)) { dateTime = DateTime.Parse(field.DefaultValue); } defaultValue = string.Format("to_date('{0}','yyyy-mm-dd HH24:MI:SS')", dateTime.ToString("yyyy-MM-dd HH:mm:ss")); break; case Hubble.Core.Data.DataType.Varchar: case Hubble.Core.Data.DataType.NVarchar: case Hubble.Core.Data.DataType.Char: case Hubble.Core.Data.DataType.NChar: defaultValue = string.Format("'{0}'", field.DefaultValue.Replace("'", "''")); break; default: throw new ArgumentException(field.DataType.ToString()); } } switch (field.DataType) { case DataType.TinyInt: sqlType = "SmallInt"; break; case DataType.SmallInt: sqlType = "SmallInt"; break; case Hubble.Core.Data.DataType.Int: sqlType = "Int"; break; case Hubble.Core.Data.DataType.Date: case Hubble.Core.Data.DataType.SmallDateTime: case Hubble.Core.Data.DataType.DateTime: sqlType = "Date"; break; case Hubble.Core.Data.DataType.Float: sqlType = "Double"; break; case Hubble.Core.Data.DataType.BigInt: sqlType = "Double"; break; case Hubble.Core.Data.DataType.Varchar: if (field.DataLength > 4000 || field.DataLength <= 0) { throw new ArgumentException(string.Format("Invalid data length is set in field:{0}", field.Name)); } sqlType = "varchar2 ({1})"; break; case Hubble.Core.Data.DataType.NVarchar: if (field.DataLength > 2000 || field.DataLength <= 0) { throw new ArgumentException(string.Format("Invalid data length is set in field:{0}", field.Name)); } sqlType = "nvarchar2 ({1})"; break; case Hubble.Core.Data.DataType.Char: if (field.DataLength > 2000 || field.DataLength <= 0) { throw new ArgumentException(string.Format("Invalid data length is set in field:{0}", field.Name)); } sqlType = "char ({1})"; break; case Hubble.Core.Data.DataType.NChar: if (field.DataLength > 1000 || field.DataLength <= 0) { throw new ArgumentException(string.Format("Invalid data length is set in field:{0}", field.Name)); } sqlType = "nchar ({1})"; break; default: throw new ArgumentException(field.DataType.ToString()); } string sql = string.Format("{0} " + sqlType + " ", GetFieldName(field.Name), field.DataLength.ToString()); if (defaultValue != null) { sql += "DEFAULT " + defaultValue + " "; } if (!field.CanNull) { sql += "NOT NULL "; } return(sql); }
/// <summary> /// Initializes the screen /// </summary> public override void Initialize() { this.TransitionOnTime = TimeSpan.FromSeconds(.5f); this.TransitionOffTime = TimeSpan.FromSeconds(.5f); this.IsPopup = false; base.Initialize(); // Get service _timeline = (Timeline)this.Game.Services.GetService(typeof(Timeline)); // Create Field _field = new Data.Field(this.Game, _timeline, 10, 24); _field.Initialize(); DummyField dummyField = new Data.DummyField(this.Game, 5, 5 + SpriteField.HiddenRows); // Create Sprites _spriteField = new SpriteField(this.Game, _field) { Position = Vector2.One * SpriteField.GridCellSize * 3 }; _spriteGhostBlock = new SpriteGhostBlock(this.Game, _field.CurrentBlock) { Position = _spriteField.Position }; _spriteFallingBlock = new SpriteFallingBlock(this.Game, _field.CurrentBlock) { Position = _spriteField.Position }; // Next Block and HoldBlock Boundaries _spriteNextBlockBoundary = new SpriteField(this.Game, dummyField) { Position = _spriteField.Position + (Vector2.UnitX * (_field.Width + 2)) * SpriteField.GridCellSize, }; _spriteHoldBlockBoundary = new SpriteField(this.Game, dummyField) { Position = _spriteField.Position + (Vector2.UnitX * (_field.Width + 2) + Vector2.UnitY * (6 + 1)) * SpriteField.GridCellSize, }; // Next BLock _spriteNextBlock = new SpriteBlock(this.Game, _field.NextBlock) { Position = _spriteNextBlockBoundary.Position + Vector2.One * SpriteField.GridCellSize, }; _field.NextBlock.OnTypeChanged += new BlockTypeDelegate(NextBlock_OnTypeChanged); _spriteHoldBlock = new SpriteNullableBlock(this.Game) { Position = _spriteHoldBlockBoundary.Position + Vector2.One * SpriteField.GridCellSize, }; _spriteField.Initialize(); _spriteGhostBlock.Initialize(); _spriteFallingBlock.Initialize(); _spriteNextBlockBoundary.Initialize(); _spriteHoldBlockBoundary.Initialize(); _spriteNextBlock.Initialize(); _spriteHoldBlock.Initialize(); _spriteScorePopups = new List <SpriteScorePopup>(); // Player controller _controller = new KeyboardController(this.Game, Keys.S, Keys.A, Keys.D, Keys.W, Keys.Q, Keys.E, Keys.Space, Keys.Enter); _controller.Initialize(); _field.OnGameEnded += new EventHandler(_field_OnGameEnded); _field.OnRowsCleared += new RowsDelegate(_field_OnRowsCleared); _field.OnPointsEarned += new PointsDelegate(_field_OnPointsEarned); // Start the level _timeline.Start(); }
public void Run() { if (Parameters.Count < 3) { throw new ArgumentException("Parameter 1 is table name, Parameter 2 is field name, Parameter 3 is a text for test, Parameter 4 is analyzer type(optional)"); } Data.DBProvider dbProvider = Data.DBProvider.GetDBProvider(Parameters[0]); if (dbProvider == null) { throw new Data.DataException(string.Format("Can't find table name : {0}", Parameters[0])); } Data.Field field = dbProvider.GetField(Parameters[1]); if (field == null) { throw new Data.DataException(string.Format("Can't find field name : {0}", Parameters[2])); } if (field.AnalyzerName == null) { throw new Data.DataException(string.Format("Field: {0} in {1} is not tokenized", Parameters[2], dbProvider.Table.Name)); } Analysis.IAnalyzer analyzer = Data.DBProvider.GetAnalyzer(field.AnalyzerName); if (analyzer == null) { throw new Data.DataException(string.Format("Can't find analyzer name : {0}", field.AnalyzerName)); } bool clientAnalyzer = false; if (Parameters.Count == 4) { if (Parameters[3].Equals("sqlclient", StringComparison.CurrentCultureIgnoreCase)) { clientAnalyzer = true; } } AddColumn("Word"); AddColumn("Position"); AddColumn("Rank"); if (clientAnalyzer) { foreach (Entity.WordInfo word in analyzer.TokenizeForSqlClient(Parameters[2])) { NewRow(); OutputValue("Word", word.Word); OutputValue("Position", word.Position.ToString()); OutputValue("Rank", word.Rank.ToString()); } } else { foreach (Entity.WordInfo word in analyzer.Tokenize(Parameters[2])) { NewRow(); OutputValue("Word", word.Word); OutputValue("Position", word.Position.ToString()); OutputValue("Rank", word.Rank.ToString()); } } }
public QueryResultHeapSort(List <SyntaxAnalysis.Select.OrderBy> orderBys, Data.DBProvider dbProvider) { _DBProvider = dbProvider; _OrderBys = orderBys; _CanDo = true; if (orderBys == null) { _CanDo = false; } else if (orderBys.Count <= 0 || orderBys.Count > 2) { _CanDo = false; } else { _SortFieldsCount = orderBys.Count; for (int i = 0; i < orderBys.Count; i++) { bool asc = orderBys[i].Order.Equals("ASC", StringComparison.CurrentCultureIgnoreCase); if (orderBys[i].Name.Equals("DocId", StringComparison.CurrentCultureIgnoreCase)) { if (i == 0) { _Asc1 = asc; } else { _Asc2 = asc; } } else if (orderBys[i].Name.Equals("Score", StringComparison.CurrentCultureIgnoreCase)) { if (i == 0) { _Asc1 = asc; } else { _Asc2 = asc; } } else { if (i == 0) { _Asc1 = asc; } else { _Asc2 = asc; } Data.Field field = _DBProvider.GetField(orderBys[i].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[i].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: case Hubble.Core.Data.DataType.BigInt: case Hubble.Core.Data.DataType.DateTime: case Hubble.Core.Data.DataType.Float: break; default: _CanDo = false; break; } } } if (!_CanDo) { break; } } } }
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; } } } } }
/// <summary> /// Initializes the screen /// </summary> public override void Initialize() { this.TransitionOnTime = TimeSpan.FromSeconds(.5f); this.TransitionOffTime = TimeSpan.FromSeconds(.5f); this.IsPopup = false; base.Initialize(); // Get service _timeline = (Timeline)this.Game.Services.GetService(typeof(Timeline)); // Create Field _field = new Data.Field(this.Game, _timeline, 10, 24); _field.Initialize(); DummyField dummyField = new Data.DummyField(this.Game, 5, 5 + SpriteField.HiddenRows); // Create Sprites _spriteField = new SpriteField(this.Game, _field) { Position = Vector2.One * SpriteField.GridCellSize * 3 }; _spriteGhostBlock = new SpriteGhostBlock(this.Game, _field.CurrentBlock) { Position = _spriteField.Position }; _spriteFallingBlock = new SpriteFallingBlock(this.Game, _field.CurrentBlock) { Position = _spriteField.Position }; // Next Block and HoldBlock Boundaries _spriteNextBlockBoundary = new SpriteField(this.Game, dummyField) { Position = _spriteField.Position + (Vector2.UnitX * (_field.Width + 2)) * SpriteField.GridCellSize, }; _spriteHoldBlockBoundary = new SpriteField(this.Game, dummyField) { Position = _spriteField.Position + (Vector2.UnitX * (_field.Width + 2) + Vector2.UnitY * (6 + 1)) * SpriteField.GridCellSize, }; // Next BLock _spriteNextBlock = new SpriteBlock(this.Game, _field.NextBlock) { Position = _spriteNextBlockBoundary.Position + Vector2.One * SpriteField.GridCellSize, }; _field.NextBlock.OnTypeChanged += new BlockTypeDelegate(NextBlock_OnTypeChanged); _spriteHoldBlock = new SpriteNullableBlock(this.Game) { Position = _spriteHoldBlockBoundary.Position + Vector2.One * SpriteField.GridCellSize, }; _spriteField.Initialize(); _spriteGhostBlock.Initialize(); _spriteFallingBlock.Initialize(); _spriteNextBlockBoundary.Initialize(); _spriteHoldBlockBoundary.Initialize(); _spriteNextBlock.Initialize(); _spriteHoldBlock.Initialize(); _spriteScorePopups = new List<SpriteScorePopup>(); // Player controller _controller = new KeyboardController(this.Game, Keys.S, Keys.A, Keys.D, Keys.W, Keys.Q, Keys.E, Keys.Space, Keys.Enter); _controller.Initialize(); _field.OnGameEnded += new EventHandler(_field_OnGameEnded); _field.OnRowsCleared += new RowsDelegate(_field_OnRowsCleared); _field.OnPointsEarned += new PointsDelegate(_field_OnPointsEarned); // Start the level _timeline.Start(); }
/// <summary> /// order by except only order by score desc. /// </summary> /// <param name="upDict"></param> /// <param name="docIdRank"></param> unsafe public void CalculateOptimizeNormalOrderBy(Core.SFQL.Parse.DocumentResultWhereDictionary upDict, ref Core.SFQL.Parse.DocumentResultWhereDictionary docIdRank) { DBProvider dBProvider = Argument.DBProvider; Argument.DBProvider.SharedPayloadProvider.EnterPayloladShareLock(); bool needFilterUntokenizedConditions = this.Argument.NeedFilterUntokenizedConditions; ExpressionTree untokenizedTree = this.Argument.UntokenizedTreeOnRoot; Query.DocumentResult documentResult; Query.DocumentResult *drp = &documentResult; bool orderByIncludingScore = Argument.OrderByIncludingScore(); try { Field[] orderByFields; DocId2LongComparer comparer = DocId2LongComparer.Generate( dBProvider, Argument.OrderBys, out orderByFields); bool needGroupBy = Argument.NeedGroupBy; WordIndexForQuery wifq = WordIndexes[0]; _IndexReader = wifq.WordIndex.IndexReader; Data.Field rankField = Argument.DBProvider.GetField("Rank"); if (rankField != null) { if (rankField.DataType == Hubble.Core.Data.DataType.Int && rankField.IndexType == Hubble.Core.Data.Field.Index.Untokenized) { _HasRandField = true; _RankTab = rankField.TabIndex; _DocidPayloads = new OriginalDocumentPositionList[2 * 1024]; _CurDocidPayloadIndex = _DocidPayloads.Length; } } if (_IndexReader != null) { int top; //vars for delete bool haveRecordsDeleted = dBProvider.DelProvider.Count > 0; int[] delDocs = null; int curDelIndex = 0; int curDelDocid = 0; int groupByCount = 0; int groupByLen = dBProvider.Table.GroupByLimit; int groupByStep = 1; int groupByIndex = 0; if (needGroupBy) { groupByStep = wifq.RelTotalCount / groupByLen; if (groupByStep <= 0) { groupByStep = 1; } } if (haveRecordsDeleted) { delDocs = dBProvider.DelProvider.DelDocs; curDelDocid = delDocs[curDelIndex]; } try { //calculate top //If less than 100, set to 100 if (this.Argument.End >= 0) { top = (1 + this.Argument.End / 100) * 100; if (top <= 0) { top = 100; } //if (this.Argument.End * 2 > top) //{ // top *= 2; //} } else { top = int.MaxValue; } PriorQueue <Docid2Long> priorQueue = new PriorQueue <Docid2Long>(top, comparer); int rows = 0; Entity.OriginalDocumentPositionList docList = new OriginalDocumentPositionList(); bool notEOF = GetNext(ref docList); Index.WordIndexReader wordIndexReader = wifq.WordIndex; Docid2Long last = new Docid2Long(); last.DocId = -1; int relCount = 0; while (notEOF) { //Process untokenized conditions. //If is not matched, get the next one. if (needFilterUntokenizedConditions) { int docId = docList.DocumentId; drp->DocId = docId; drp->PayloadData = dBProvider.GetPayloadDataWithShareLock(docId); if (!ParseWhere.GetComparisionExpressionValue(dBProvider, drp, untokenizedTree)) { notEOF = GetNext(ref docList); continue; } } //Process deleted records if (haveRecordsDeleted) { if (curDelIndex < delDocs.Length) { //If docid deleted, get next if (docList.DocumentId == curDelDocid) { notEOF = GetNext(ref docList); continue; } else if (docList.DocumentId > curDelDocid) { while (curDelIndex < delDocs.Length && curDelDocid < docList.DocumentId) { curDelIndex++; if (curDelIndex >= delDocs.Length) { haveRecordsDeleted = false; break; } curDelDocid = delDocs[curDelIndex]; } if (curDelIndex < delDocs.Length) { if (docList.DocumentId == curDelDocid) { notEOF = GetNext(ref docList); continue; } } } } } if (needGroupBy) { if (groupByCount < groupByLen) { if (groupByIndex >= groupByStep) { groupByIndex = 0; } if (groupByIndex == 0) { docIdRank.AddToGroupByCollection(docList.DocumentId); groupByCount++; } groupByIndex++; } } relCount++; Docid2Long cur = new Docid2Long(); if (rows >= top) { long score = 1; if (orderByIncludingScore) { int wordCount = docList.CountAndWordCount / 8; //one word, score = count score = (long)wifq.FieldRank * (long)wifq.WordRank * (long)wifq.Idf_t * (long)wordCount * (long)1000000 / ((long)wifq.Sum_d_t * (long)docList.TotalWordsInThisDocument); } cur.DocId = docList.DocumentId; cur.Rank = docList.TotalWordsInThisDocument; Docid2Long.Generate(ref cur, dBProvider, orderByFields, score); if (comparer.Compare(last, cur) > 0) { priorQueue.Add(cur); last = priorQueue.Last; } } else { long score = 1; if (orderByIncludingScore) { int wordCount = docList.CountAndWordCount / 8; //one word, score = count score = (long)wifq.FieldRank * (long)wifq.WordRank * (long)wifq.Idf_t * (long)wordCount * (long)1000000 / ((long)wifq.Sum_d_t * (long)docList.TotalWordsInThisDocument); } if (score < 0) { //Overflow score = long.MaxValue - 4000000; } cur.DocId = docList.DocumentId; cur.Rank = docList.TotalWordsInThisDocument; Docid2Long.Generate(ref cur, dBProvider, orderByFields, score); priorQueue.Add(cur); rows++; if (rows == top) { last = priorQueue.Last; } } notEOF = GetNext(ref docList); } docIdRank.RelTotalCount = relCount; foreach (Docid2Long docid2Long in priorQueue.ToArray()) { long score = comparer.GetScore(docid2Long); //use Rank store TotalWordsInThisDocument if (score < 0) { //Overflow score = long.MaxValue - 4000000; } docIdRank.Add(docid2Long.DocId, new DocumentResult(docid2Long.DocId, score)); } } finally { } docIdRank.Sorted = true; } } finally { Argument.DBProvider.SharedPayloadProvider.LeavePayloadShareLock(); } }