예제 #1
0
        // --------------------------------------------------------------------------------------------------
        // Index
        // --------------------------------------------------------------------------------------------------

        // Virtual Index List wants an linkNode

        private void indexListView_RetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
        {
            int          i  = e.ItemIndex;
            ListViewItem li = new ListViewItem((i + 1).ToString());

            if (_helpKeywords == null || i >= _helpKeywords.Count)  //range check
            {
                li.SubItems.AddRange(new string[] { "?", "?" });
                e.Item = li;
                return;
            }

            //Note: We can improve speed and smoothness with some local caching

            int     topicCount;
            Keyword keyword = indexCache.GetKW(i, out topicCount);

            if (keyword == null)
            {
                _helpKeywords.MoveTo(i);
                keyword    = (Keyword)_helpKeywords.Current;
                topicCount = keyword.Topics.Count;
                indexCache.Add(i, keyword, topicCount);
            }

            String kwText = keyword.DisplayValue;

            if (keyword.IsSubkey)
            {
                kwText = "    " + kwText;
            }
            li.SubItems.AddRange(new string[] { kwText, topicCount.ToString() });
            e.Item = li;
        }
예제 #2
0
        public bool EnsureIndex(IndexDefinition indexDefinition)
        {
            // Try to not rebuild index, so we check if there exists an equal defintion already
            IndexWrapper existing;

            if (IndexCache.TryGetValue(indexDefinition.Path, out existing))
            {
                if (indexDefinition.Options.Equals(existing.IndexDefinition.Options))
                {
                    // phew, existing index was already matching. bail out
                    return(false);
                }
                DropIndex(indexDefinition.Path);
            }

            // An index can not both exclude certain values and at the same time include certain values
            var hasIncludeValues = (indexDefinition.Options.IncludeValues != null) &&
                                   (indexDefinition.Options.IncludeValues.Length > 0);
            var hasExcludeValues = (indexDefinition.Options.ExcludeValues != null) &&
                                   (indexDefinition.Options.ExcludeValues.Length > 0);

            if (hasIncludeValues && hasExcludeValues)
            {
                throw new KiwiDbException("An index can not have an exclusion list and an inclusion list at the same time.");
            }

            var index = new IndexWrapper(this, indexDefinition)
            {
                IsChanged = true
            };

            IndexCache.Add(indexDefinition.Path, index);
            Insert(indexDefinition.Path, JSON.FromObject(indexDefinition));

            // rebuild index
            foreach (var record in MasterTable.Scan())
            {
                UpdateIndex(record.Key, null, record.Value);
            }
            return(true);
        }