Class SearchIndexer
Base class for an Indexer of document which allow retrieving of a document given a specific pattern in roughly log(n).
Inherited Members
Namespace: UnityEditor.Search
Assembly: com.unity.quicksearch.dll
Syntax
public class SearchIndexer
Constructors
SearchIndexer()
Create a new default SearchIndexer.
Declaration
public SearchIndexer()
SearchIndexer(string)
Create a new SearchIndexer.
Declaration
public SearchIndexer(string name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Name of the indexer |
Properties
documentCount
Returns how many documents the index contains.
Declaration
public int documentCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
keywordCount
Returns how many keywords the index contains.
Declaration
public int keywordCount { get; }
Property Value
| Type | Description |
|---|---|
| int |
minWordIndexationLength
Minimal indexed word size.
Declaration
public int minWordIndexationLength { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
name
Name of the index. Generally this name is given by a user from a SearchDatabase.Settings
Declaration
public string name { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
resolveDocumentHandler
Handler used to resolve a document id to some other data string.
Declaration
public Func<string, string> resolveDocumentHandler { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<string, string> |
skipEntryHandler
Handler used to skip some entries.
Declaration
public Func<string, bool> skipEntryHandler { get; set; }
Property Value
| Type | Description |
|---|---|
| Func<string, bool> |
Methods
AddDocument(string, bool)
Add a new document to be indexed.
Declaration
public int AddDocument(string document, bool checkIfExists = true)
Parameters
| Type | Name | Description |
|---|---|---|
| string | document | Unique id of the document |
| bool | checkIfExists | Pass true if this document has some chances of existing already. |
Returns
| Type | Description |
|---|---|
| int | The document index/handle used to add new index entries. |
AddExactWord(string, int, int)
Add a new word coming from a specific document to the index. The word will be added as an exact match.
Declaration
public void AddExactWord(string word, int score, int documentIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| string | word | Word to add to the index. |
| int | score | Relevance score of the word. |
| int | documentIndex | Document where the indexed word was found. |
AddNumber(string, double, int, int)
Add a key-number value pair to the index. The key won't be added with variations.
Declaration
public void AddNumber(string key, double value, int score, int documentIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Key used to retrieve the value. |
| double | value | Number value to store in the index. |
| int | score | Relevance score of the word. |
| int | documentIndex | Document where the indexed value was found. |
AddProperty(string, string, int, bool, bool)
Add a property value to the index. A property is specified with a key and a string value. The value will be stored with multiple variations.
Declaration
public void AddProperty(string key, string value, int documentIndex, bool saveKeyword = false, bool exact = true)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Key used to retrieve the value. |
| string | value | String value to store in the index. |
| int | documentIndex | Document where the indexed value was found. |
| bool | saveKeyword | Define if we store this key in the keyword registry of the index. See GetKeywords(). |
| bool | exact | If true, we will store also an exact match entry for this word. |
AddProperty(string, string, int, int, bool, bool)
Add a property value to the index. A property is specified with a key and a string value. The value will be stored with multiple variations.
Declaration
public void AddProperty(string key, string value, int score, int documentIndex, bool saveKeyword = false, bool exact = true)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Key used to retrieve the value. |
| string | value | String value to store in the index. |
| int | score | Relevance score of the word. |
| int | documentIndex | Document where the indexed value was found. |
| bool | saveKeyword | Define if we store this key in the keyword registry of the index. See GetKeywords(). |
| bool | exact | If true, we will store also an exact match entry for this word. |
AddProperty(string, string, int, int, int, int, bool, bool)
Add a property value to the index. A property is specified with a key and a string value. The value will be stored with multiple variations.
Declaration
public void AddProperty(string name, string value, int minVariations, int maxVariations, int score, int documentIndex, bool saveKeyword = false, bool exact = true)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | Key used to retrieve the value. |
| string | value | String value to store in the index. |
| int | minVariations | Minimum number of variations to compute for the value. Cannot be higher than the length of the word. |
| int | maxVariations | Maximum number of variations to compute for the value. Cannot be higher than the length of the word. |
| int | score | Relevance score of the word. |
| int | documentIndex | Document where the indexed value was found. |
| bool | saveKeyword | Define if we store this key in the keyword registry of the index. See GetKeywords(). |
| bool | exact | If true, we will store also an exact match entry for this word. |
AddWord(string, int, int)
Add a new word coming from a specific document to the index. The word will be added with multiple variations allowing partial search.
Declaration
public void AddWord(string word, int score, int documentIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| string | word | Word to add to the index. |
| int | score | Relevance score of the word. |
| int | documentIndex | Document where the indexed word was found. |
AddWord(string, int, int, int)
Add a new word coming from a specific document to the index. The word will be added with multiple variations allowing partial search.
Declaration
public void AddWord(string word, int size, int score, int documentIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| string | word | Word to add to the index. |
| int | size | Number of variations to compute. |
| int | score | Relevance score of the word. |
| int | documentIndex | Document where the indexed word was found. |
AddWord(string, int, int, int, int)
Add a new word coming from a specific document to the index. The word will be added with multiple variations allowing partial search.
Declaration
public void AddWord(string word, int minVariations, int maxVariations, int score, int documentIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| string | word | Word to add to the index. |
| int | minVariations | Minimum number of variations to compute. Cannot be higher than the length of the word. |
| int | maxVariations | Maximum number of variations to compute. Cannot be higher than the length of the word. |
| int | score | Relevance score of the word. |
| int | documentIndex | Document where the indexed word was found. |
Finish()
Finalize the current index, sorting and compiling of all the indexes.
Declaration
public void Finish()
Finish(Action)
/// Finalize the current index, sorting and compiling of all the indexes.
Declaration
public void Finish(Action threadCompletedCallback)
Parameters
| Type | Name | Description |
|---|---|---|
| Action | threadCompletedCallback | Callback invoked when the index is ready to be used. |
Finish(Action<byte[]>, string[])
/// Finalize the current index, sorting and compiling of all the indexes.
Declaration
public void Finish(Action<byte[]> threadCompletedCallback, string[] removedDocuments)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<byte[]> | threadCompletedCallback | Callback invoked when the index binary blob is ready. |
| string[] | removedDocuments | Documents to be removed from current index (if any) |
GetDocument(int)
Return a search document by its index.
Declaration
public SearchDocument GetDocument(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| int | index | Valid index of the document to access. |
Returns
| Type | Description |
|---|---|
| SearchDocument | Indexed search document |
GetMetaInfo(string)
Declaration
public string GetMetaInfo(string documentId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | documentId |
Returns
| Type | Description |
|---|---|
| string |
IndexDocument(string, bool)
Function to override in a concrete SearchIndexer to index the content of a document.
Declaration
public virtual void IndexDocument(string document, bool checkIfDocumentExists)
Parameters
| Type | Name | Description |
|---|---|---|
| string | document | Path of the document to index. |
| bool | checkIfDocumentExists | Check if the document actually exists. |
IsReady()
Is the index fully built and up to date and ready for search.
Declaration
public bool IsReady()
Returns
| Type | Description |
|---|---|
| bool | Returns true if the index is ready for search. |
LoadBytes(byte[], Action<bool>)
Load asynchronously (i.e. in another thread) the index from a binary buffer.
Declaration
public bool LoadBytes(byte[] bytes, Action<bool> finished)
Parameters
| Type | Name | Description |
|---|---|---|
| byte[] | bytes | Binary buffer containing the index representation. |
| Action<bool> | finished | Callback that will trigger when the index is fully loaded. The callback parameters indicate if the loading was succesful. |
Returns
| Type | Description |
|---|---|
| bool | Returns false if the index is of an unsupported version or if there was a problem initializing the reading thread. |
Read(Stream, bool)
Read a stream and populate the index from it.
Declaration
public bool Read(Stream stream, bool checkVersionOnly)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | Stream where to read the index from. |
| bool | checkVersionOnly | If true, it will only read the version of the index and stop reading any more content. |
Returns
| Type | Description |
|---|---|
| bool | Returns false if the version of the index is not supported. |
SaveBytes()
Get the bytes representation of this index. See Write(Stream).
Declaration
public byte[] SaveBytes()
Returns
| Type | Description |
|---|---|
| byte[] | Bytes representation of the index. |
Search(string, int, int)
Declaration
public virtual IEnumerable<SearchResult> Search(string query, int maxScore = 2147483647, int patternMatchLimit = 2999)
Parameters
| Type | Name | Description |
|---|---|---|
| string | query | |
| int | maxScore | |
| int | patternMatchLimit |
Returns
| Type | Description |
|---|---|
| IEnumerable<SearchResult> |
Search(string, SearchContext, SearchProvider, int, int)
Run a search query in the index.
Declaration
public virtual IEnumerable<SearchResult> Search(string query, SearchContext context, SearchProvider provider, int maxScore = 2147483647, int patternMatchLimit = 2999)
Parameters
| Type | Name | Description |
|---|---|---|
| string | query | Search query to look out for. If if matches any of the indexed variations a result will be returned. |
| SearchContext | context | The search context on which the query is applied. |
| SearchProvider | provider | The provider that initiated the search. |
| int | maxScore | Maximum score of any matched Search Result. See score. |
| int | patternMatchLimit | Maximum number of matched Search Result that can be returned. See SearchResult. |
Returns
| Type | Description |
|---|---|
| IEnumerable<SearchResult> | Returns a collection of Search Result matching the query. |
Search(SearchContext, SearchProvider, int, int)
Declaration
public virtual IEnumerable<SearchResult> Search(SearchContext context, SearchProvider provider, int maxScore = 2147483647, int patternMatchLimit = 2999)
Parameters
| Type | Name | Description |
|---|---|---|
| SearchContext | context | |
| SearchProvider | provider | |
| int | maxScore | |
| int | patternMatchLimit |
Returns
| Type | Description |
|---|---|
| IEnumerable<SearchResult> |
SetMetaInfo(string, string)
Declaration
public void SetMetaInfo(string documentId, string metadata)
Parameters
| Type | Name | Description |
|---|---|---|
| string | documentId | |
| string | metadata |
SkipEntry(string, bool)
Called when the index is built to see if a specified document needs to be indexed. See skipEntryHandler
Declaration
public virtual bool SkipEntry(string document, bool checkRoots = false)
Parameters
| Type | Name | Description |
|---|---|---|
| string | document | Path of a document |
| bool | checkRoots |
Returns
| Type | Description |
|---|---|
| bool | Returns true if the document doesn't need to be indexed. |
Start(bool)
Start indexing entries.
Declaration
public void Start(bool clear = false)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | clear | True if the the current index should be cleared. |
Write(Stream)
Write a binary representation of the the index on a stream.
Declaration
public void Write(Stream stream)
Parameters
| Type | Name | Description |
|---|---|---|
| Stream | stream | Stream where to write the index. |