Library/PackageCache/com.unity.quicksearch@1.6.0-preview.8/Editor/Indexing/SearchIndexer.cs
/// <summary>
/// Run a search query in the index.
/// </summary>
/// <param name="query">Search query to look out for. If if matches any of the indexed variations a result will be returned.</param>
/// <param name="maxScore">Maximum score of any matched Search Result. See <see cref="SearchResult.score"/>.</param>
/// <param name="patternMatchLimit">Maximum number of matched Search Result that can be returned. See <see cref="SearchResult"/>.</param>
/// <returns>Returns a collection of Search Result matching the query.</returns>
Run a search query in the index.
Run a search query in the index .
public virtual IEnumerable<SearchResult> Search(string query, int maxScore = int.MaxValue, int patternMatchLimit = 2999)
        {
            {
                if (!m_IndexReady)
                    return Enumerable.Empty<SearchResult>();
                var tokens = getQueryTokensHandler(query);
                Array.Sort(tokens, SortTokensByPatternMatches);
                var lengths = tokens.Select(p => p.Length).ToArray();
                var patterns = tokens.Select(p => p.GetHashCode()).ToArray();
                if (patterns.Length == 0)
                    return Enumerable.Empty<SearchResult>();
                var wiec = new SearchIndexComparer();
                lock (this)
                {
                    var remains = SearchIndexes(patterns[0], lengths[0], SearchIndexEntry.Type.Word, maxScore, wiec, null, patternMatchLimit).ToList();
                    patternMatchCount[patterns[0]] = remains.Count;
                    if (remains.Count == 0)
                        return Enumerable.Empty<SearchResult>();
                    for (int i = 1; i < patterns.Length; ++i)
                    {
                        var subset = new SearchResultCollection(remains);
                        remains = SearchIndexes(patterns[i], lengths[i], SearchIndexEntry.Type.Word, maxScore, wiec, subset, patternMatchLimit).ToList();
                        if (remains.Count == 0)
                            break;
                    }
                    return remains.Select(fi => new SearchResult(m_Documents[fi.index].id, fi.index, fi.score));
                }
            }
        }
public virtual IEnumerable < SearchResult > Search ( string query , int maxScore = int . MaxValue , int patternMatchLimit = 2999 ) { { if ( ! m_IndexReady ) return Enumerable . Empty < SearchResult > ( ) ; var tokens = getQueryTokensHandler ( query ) ; Array . Sort ( tokens , SortTokensByPatternMatches ) ; var lengths = tokens . Select ( p => p . Length ) . ToArray ( ) ; var patterns = tokens . Select ( p => p . GetHashCode ( ) ) . ToArray ( ) ; if ( patterns . Length == 0 ) return Enumerable . Empty < SearchResult > ( ) ; var wiec = new SearchIndexComparer ( ) ; lock ( this ) { var remains = SearchIndexes ( patterns [ 0 ] , lengths [ 0 ] , SearchIndexEntry . Type . Word , maxScore , wiec , null , patternMatchLimit ) . ToList ( ) ; patternMatchCount [ patterns [ 0 ] ] = remains . Count ; if ( remains . Count == 0 ) return Enumerable . Empty < SearchResult > ( ) ; for ( int i = 1 ; i < patterns . Length ; ++ i ) { var subset = new SearchResultCollection ( remains ) ; remains = SearchIndexes ( patterns [ i ] , lengths [ i ] , SearchIndexEntry . Type . Word , maxScore , wiec , subset , patternMatchLimit ) . ToList ( ) ; if ( remains . Count == 0 ) break ; } return remains . Select ( fi => new SearchResult ( m_Documents [ fi . index ] . id , fi . index , fi . score ) ) ; } } }
Run a search query in the index.
Run a search query in the index .
//using (new DebugTimer($"Search Index ({query})"))
Returns a collection of Search Result matching the query.
Returns a collection of Search Result matching the query .
query
string
Search query to look out for. If if matches any of the indexed variations a result will be returned.
Search query to look out for . If if matches any of the indexed variations a result will be returned .
maxScore
int
Maximum score of any matched Search Result. See .
Maximum score of any matched Search Result . See .
patternMatchLimit
int
Maximum number of matched Search Result that can be returned. See .
Maximum number of matched Search Result that can be returned . See .