Ejemplo n.º 1
0
            internal static int SortWordEntryComparer(WordIndexEntry item1, WordIndexEntry item2)
            {
                var c = item1.length.CompareTo(item2.length);

                if (c != 0)
                {
                    return(c);
                }
                c = item1.key.CompareTo(item2.key);
                if (c != 0)
                {
                    return(c);
                }
                if (item2.score == int.MaxValue)
                {
                    return(0);
                }
                return(item1.score.CompareTo(item2.score));
            }
Ejemplo n.º 2
0
            protected void UpdateIndexWithNewContent(string[] updated, string[] removed, string[] moved)
            {
                if (!m_IndexReady)
                {
                    return;
                }

                //using( new DebugTimer("Refreshing index with " + String.Join("\r\n\t", updated) +  $"\r\nRemoved: {String.Join("\r\n\t", removed)}" + $"\r\nMoved: {String.Join("\r\n\t", moved)}\r\n"))
                {
                    lock (this)
                    {
                        List <string>         entries = null;
                        List <WordIndexEntry> words   = null;

                        // Filter already known entries.
                        updated = updated.Where(u => Array.FindIndex(m_Entries, e => e == u) == -1).ToArray();

                        bool updateIndex = false;
                        if (updated.Length > 0)
                        {
                            entries = new List <string>(m_Entries);
                            words   = new List <WordIndexEntry>(m_WordIndexEntries);

                            var wiec         = new WordIndexEntryComparer();
                            var partialIndex = BuildPartialIndex(String.Empty, 0, updated, 0);

                            // Update entry file indexes
                            for (int i = 0; i < partialIndex.Count; ++i)
                            {
                                var pk               = partialIndex[i];
                                var updatedEntry     = updated[pk.fileIndex];
                                var matchedFileIndex = entries.FindIndex(e => e == updatedEntry);
                                if (matchedFileIndex == -1)
                                {
                                    entries.Add(updatedEntry);
                                    matchedFileIndex = entries.Count - 1;
                                }

                                var newWordIndex = new WordIndexEntry(pk.key, pk.length, matchedFileIndex, pk.score);
                                var insertIndex  = words.BinarySearch(newWordIndex, wiec);
                                if (insertIndex > -1)
                                {
                                    words.Insert(insertIndex, newWordIndex);
                                }
                                else
                                {
                                    words.Insert(~insertIndex, newWordIndex);
                                }
                            }

                            updateIndex = true;
                        }

                        // Remove items
                        if (removed.Length > 0)
                        {
                            entries = entries ?? new List <string>(m_Entries);
                            words   = words ?? new List <WordIndexEntry>(m_WordIndexEntries);

                            for (int i = 0; i < removed.Length; ++i)
                            {
                                var entryToBeRemoved = removed[i];
                                var entryIndex       = entries.FindIndex(e => e == entryToBeRemoved);
                                if (entryIndex > -1)
                                {
                                    updateIndex |= words.RemoveAll(w => w.fileIndex == entryIndex) > 0;
                                }
                            }
                        }

                        if (updateIndex)
                        {
                            UpdateIndexes(entries.ToArray(), SortIndexes(words));
                        }
                    }
                }
            }
Ejemplo n.º 3
0
                public override bool Equals(object y)
                {
                    WordIndexEntry other = (WordIndexEntry)y;

                    return(key == other.key && length == other.length && fileIndex == other.fileIndex);
                }