Library/PackageCache/com.unity.quicksearch@1.6.0-preview.8/Editor/Indexing/SearchIndexer.cs
/// <summary>
/// Read a stream and populate the index from it.
/// </summary>
/// <param name="stream">Stream where to read the index from.</param>
/// <param name="checkVersionOnly">If true, it will only read the version of the index and stop reading any more content.</param>
/// <returns>Returns false if the version of the index is not supported.</returns>
Read a stream and populate the index from it.
Read a stream and populate the index from it .
public bool Read(Stream stream, bool checkVersionOnly)
        {
            using (var indexReader = new BinaryReader(stream))
            {
                int version = indexReader.ReadInt32();
                if (version != SearchIndexEntry.version)
                    return false;
                if (checkVersionOnly)
                    return true;
                indexReader.ReadString(); 
                var elementCount = indexReader.ReadInt32();
                var documents = new SearchDocument[elementCount];
                for (int i = 0; i < elementCount; ++i)
                {
                    documents[i] = new SearchDocument(indexReader.ReadString());
                    bool readMetadata = indexReader.ReadBoolean();
                    if (readMetadata)
                        documents[i].metadata = indexReader.ReadString();
                }
                elementCount = indexReader.ReadInt32();
                #if UNITY_2020_1_OR_NEWER
                var hashes = new Dictionary<string, Hash128>();
                #else
                var hashes = new Dictionary<string, string>();
                #endif
                for (int i = 0; i < elementCount; ++i)
                {
                    var key = indexReader.ReadString();
                    #if UNITY_2020_1_OR_NEWER
                    var hash = Hash128.Parse(indexReader.ReadString());
                    #else
                    var hash = indexReader.ReadString();
                    #endif
                    hashes[key] = hash;
                }
                elementCount = indexReader.ReadInt32();
                var indexes = new List<SearchIndexEntry>(elementCount);
                for (int i = 0; i < elementCount; ++i)
                {
                    var key = indexReader.ReadInt64();
                    var crc = indexReader.ReadInt32();
                    var type = (SearchIndexEntry.Type)indexReader.ReadInt32();
                    var index = indexReader.ReadInt32();
                    var score = indexReader.ReadInt32();
                    indexes.Add(new SearchIndexEntry(key, crc, type, index, score));
                }
                elementCount = indexReader.ReadInt32();
                var keywords = new string[elementCount];
                for (int i = 0; i < elementCount; ++i)
                    keywords[i] = indexReader.ReadString();
                lock (this)
                {
                    ApplyIndexes(documents, indexes.ToArray(), hashes);
                    m_Keywords = new HashSet<string>(keywords);
                }
                return true;
            }
        }
public bool Read ( Stream stream , bool checkVersionOnly ) { using ( var indexReader = new BinaryReader ( stream ) ) { int version = indexReader . ReadInt32 ( ) ; if ( version != SearchIndexEntry . version ) return false ; if ( checkVersionOnly ) return true ; indexReader . ReadString ( ) ; var elementCount = indexReader . ReadInt32 ( ) ; var documents = new SearchDocument [ elementCount ] ; for ( int i = 0 ; i < elementCount ; ++ i ) { documents [ i ] = new SearchDocument ( indexReader . ReadString ( ) ) ; bool readMetadata = indexReader . ReadBoolean ( ) ; if ( readMetadata ) documents [ i ] . metadata = indexReader . ReadString ( ) ; } elementCount = indexReader . ReadInt32 ( ) ; if UNITY_2020_1_OR_NEWER var hashes = new Dictionary < string , Hash128 > ( ) ; else var hashes = new Dictionary < string , string > ( ) ; endif for ( int i = 0 ; i < elementCount ; ++ i ) { var key = indexReader . ReadString ( ) ; if UNITY_2020_1_OR_NEWER var hash = Hash128 . Parse ( indexReader . ReadString ( ) ) ; else var hash = indexReader . ReadString ( ) ; endif hashes [ key ] = hash ; } elementCount = indexReader . ReadInt32 ( ) ; var indexes = new List < SearchIndexEntry > ( elementCount ) ; for ( int i = 0 ; i < elementCount ; ++ i ) { var key = indexReader . ReadInt64 ( ) ; var crc = indexReader . ReadInt32 ( ) ; var type = ( SearchIndexEntry . Type ) indexReader . ReadInt32 ( ) ; var index = indexReader . ReadInt32 ( ) ; var score = indexReader . ReadInt32 ( ) ; indexes . Add ( new SearchIndexEntry ( key , crc , type , index , score ) ) ; } elementCount = indexReader . ReadInt32 ( ) ; var keywords = new string [ elementCount ] ; for ( int i = 0 ; i < elementCount ; ++ i ) keywords [ i ] = indexReader . ReadString ( ) ; lock ( this ) { ApplyIndexes ( documents , indexes . ToArray ( ) , hashes ) ; m_Keywords = new HashSet < string > ( keywords ) ; } return true ; } }
Read a stream and populate the index from it.
Read a stream and populate the index from it .
// Skip // Documents // Hashes // Indexes // Keywords // No need to sort the index, it is already sorted in the file stream.
Returns false if the version of the index is not supported.
Returns false if the version of the index is not supported .
stream
Stream
Stream where to read the index from.
Stream where to read the index from .
checkVersionOnly
bool
If true, it will only read the version of the index and stop reading any more content.
If true it will only read the version of the index and stop reading any more content .