当前位置: 首页>>代码示例>>C#>>正文


C# Transaction.InsertTable方法代码示例

本文整理汇总了C#中Transaction.InsertTable方法的典型用法代码示例。如果您正苦于以下问题:C# Transaction.InsertTable方法的具体用法?C# Transaction.InsertTable怎么用?C# Transaction.InsertTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Transaction的用法示例。


在下文中一共展示了Transaction.InsertTable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoIndexing

        /// <summary>
        /// itbls and transaction must be supplied, to make it working from outside
        /// </summary>
        internal void DoIndexing(Transaction itran, Dictionary<string, ITS> xitbls)
        {
            byte[] btUdtStart = DateTime.UtcNow.Ticks.To_8_bytes_array_BigEndian();

            ITS its = null;

            byte[] kA = null;
            byte[] kZ = null;
            byte[] newSrch = null;
            Row<string, byte[]> rWord = null;
            //Dictionary<string, WordInDocs> wds = new Dictionary<string, WordInDocs>();
            WordInDocs wd = null;

            uint iterBlockId = 0;
            int iterBlockLen = 0;
            int blockSize = 0;
            byte[] btBlock = null;
            Dictionary<uint, byte[]> block = new Dictionary<uint, byte[]>();
            byte[] btWah = null;
            byte[] tmp = null;
            byte[] val = null;
            WABI wah = null;

            foreach (var tbl in xitbls)
            {
                its = tbl.Value;
                if (its.srch == null)   //Can be instantiated in insert procedure, depending how we use indexer
                {
                    its.srch = itran.InsertTable<byte>(tbl.Key, 3, 0);
                    its.srch.ValuesLazyLoadingIsOn = false;
                }
                //Are instantiated only hear
                its.blocks = itran.InsertTable<byte>(tbl.Key, 10, 0);
                its.words = itran.InsertTable<byte>(tbl.Key, 20, 0);
                its.currentBlock = itran.Select<int, uint>(tbl.Key, 11).Value;
                its.numberInBlock = itran.Select<int, uint>(tbl.Key, 12).Value;

                its.blocks.ValuesLazyLoadingIsOn = false;
                its.words.ValuesLazyLoadingIsOn = false;

                if (its.currentBlock == 0)
                {
                    its.numberInBlock = 0;
                    its.currentBlock = 1;
                }

                //Getting latest indexing time for that table
                var litRow = itran.Select<byte, byte[]>(tbl.Key, 4);
                byte[] lastIndexed = DateTime.MinValue.Ticks.To_8_bytes_array_BigEndian();
                if (litRow.Exists)
                    lastIndexed = litRow.Value;

                kA = lastIndexed.Concat(int.MinValue.To_4_bytes_array_BigEndian());
                kZ = DateTime.MaxValue.Ticks.To_8_bytes_array_BigEndian().Concat(int.MaxValue.To_4_bytes_array_BigEndian());

                //Key is word, Value.Item1 is documents list from which this word must be removed, Value.Item2 is documents List where word must be added
                Dictionary<string, Tuple<HashSet<int>, HashSet<int>, WordInDocs>> ds = new Dictionary<string, Tuple<HashSet<int>, HashSet<int>, WordInDocs>>();
                Tuple<HashSet<int>, HashSet<int>, WordInDocs> tpl = null;

                //Dictionary<string, byte[]> tmpWrds = new Dictionary<string, byte[]>(StringComparison.Ordinal);
                var tmpWrds = new SortedDictionary<string, byte[]>(StringComparer.Ordinal);

                foreach (var docId in its.ChangedDocIds)
                {
                    //diff will return list of words to be removed and list of words to be added
                    newSrch = its.srch.Select<byte[], byte[]>(docId.To_4_bytes_array_BigEndian().Concat(new byte[] { 1 })).Value;

                    var diff = WordsDiff(
                        its.srch.Select<byte[], byte[]>(docId.To_4_bytes_array_BigEndian().Concat(new byte[] { 0 }), true).Value, //Current searchables
                        newSrch //new
                        );

                    //Copying new searchables to current searchables
                    its.srch.ChangeKey<byte[]>(docId.To_4_bytes_array_BigEndian().Concat(new byte[] { 1 }), docId.To_4_bytes_array_BigEndian().Concat(new byte[] { 0 }));
                    //its.srch.Insert<byte[], byte[]>(docId.To_4_bytes_array_BigEndian().Concat(new byte[] { 0 }), newSrch);

                    Action <string> createNew = (word) =>
                    {
                        if (!tmpWrds.ContainsKey(word))
                        {
                            rWord = its.words.Select<string, byte[]>(word, true);
                            wd = new WordInDocs();

                            if (rWord.Exists)
                            {
                                wd.BlockId = rWord.Value.Substring(0, 4).To_UInt32_BigEndian();
                                wd.NumberInBlock = rWord.Value.Substring(4, 4).To_UInt32_BigEndian();
                            }
                            else
                            {
                                its.numberInBlock++;

                                if (its.numberInBlock > itran._transactionUnit.TransactionsCoordinator._engine.Configuration.TextSearchConfig.QuantityOfWordsInBlock)  //Quantity of words (WAHs) in block
                                {
                                    its.currentBlock++;
                                    its.numberInBlock = 1;
                                }
//.........这里部分代码省略.........
开发者ID:hhblaze,项目名称:DBreeze,代码行数:101,代码来源:TextSearchHandler.cs

示例2: InsertDocumentText

        /// <summary>
        /// 
        /// </summary>
        /// <param name="tran"></param>
        /// <param name="tableName"></param>
        /// <param name="documentId"></param>
        /// <param name="containsWords"></param>
        /// <param name="fullMatchWords"></param>
        /// <param name="deferredIndexing"></param>
        /// <param name="containsMinimalLength"></param>
        /// <param name="iMode"></param>
        public void InsertDocumentText(Transaction tran, string tableName, byte[] documentId, string containsWords, string fullMatchWords, bool deferredIndexing, int containsMinimalLength, eInsertMode iMode)
        {
            //tran._transactionUnit.TransactionsCoordinator._engine.Configuration.
            if (String.IsNullOrEmpty(tableName) || documentId == null)
                return;

            if ((iMode == eInsertMode.Append || iMode == eInsertMode.Remove) && (String.IsNullOrEmpty(containsWords) && String.IsNullOrEmpty(fullMatchWords)))
                return;

            SortedDictionary<string, WordDefinition> pST = this.GetWordsDefinitionFromText(containsWords, fullMatchWords, containsMinimalLength); //flattend searchables
            StringBuilder sbPs = new StringBuilder();

            //Registering all tables for text-search in current transaction
            ITS its = null;
            if (!itbls.TryGetValue(tableName, out its))
            {
                its = new ITS()
                {
                    e2i = tran.InsertTable<byte>(tableName, 1, 0),
                    i2e = tran.InsertTable<byte>(tableName, 2, 0),
                    srch = tran.InsertTable<byte>(tableName, 3, 0),
                };

                its.e2i.ValuesLazyLoadingIsOn = false;
                its.i2e.ValuesLazyLoadingIsOn = false;
                its.srch.ValuesLazyLoadingIsOn = false;

                itbls.Add(tableName, its);
            }

            //Internal document ID
            int iId = 0;

            //Searching document by externalID
            var r1 = its.e2i.Select<byte[], int>(documentId);

            if (r1.Exists)          //DOCUMENT EXISTS
            {
                iId = r1.Value;

                //Getting old searchables for this document
                byte[] oldSrch = its.srch.Select<byte[], byte[]>(iId.To_4_bytes_array_BigEndian().Concat(new byte[] { 0 }), true).Value;
                HashSet<string> oldSearchables = GetSearchablesFromByteArray_AsHashSet(oldSrch); //always instantiated hashset

                switch (iMode)
                {
                    case eInsertMode.Insert:
                        //Comparing
                        if (oldSearchables.Intersect(pST.Keys).Count() == oldSearchables.Count && oldSearchables.Count == pST.Keys.Count)
                            return; //Going out, nothing to insert

                        foreach (var ps1i in pST)
                        {
                            sbPs.Append(ps1i.Key);
                            sbPs.Append(" ");
                        }
                        break;
                    case eInsertMode.Append:
                    case eInsertMode.Remove:

                        if ((iMode == eInsertMode.Append)
                            &&
                            oldSearchables.Intersect(pST.Keys).Count() == oldSearchables.Count
                            &&
                            oldSearchables.Count == pST.Keys.Count
                            )
                            return; //Going out, nothing to insert

                        foreach (var ew in pST.Keys)
                        {
                            if (iMode == eInsertMode.Append)
                                oldSearchables.Add(ew);
                            else
                                oldSearchables.Remove(ew);
                        }

                        foreach (var el in oldSearchables)
                        {
                            sbPs.Append(el);
                            sbPs.Append(" ");
                        }

                        break;
                }
            }
            else
            {
                //DOCUMENT NEW
                if (pST.Count < 1)
//.........这里部分代码省略.........
开发者ID:hhblaze,项目名称:DBreeze,代码行数:101,代码来源:TextSearchHandler.cs


注:本文中的Transaction.InsertTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。