Class SearchIndexer
Base class for an Indexer of document which allow retrieving of a document given a specific pattern in roughly log(n).
Namespace: UnityEditor.Search
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 |
|---|---|
| Int32 |
keywordCount
Returns how many keywords the index contains.
Declaration
public int keywordCount { get; }
Property Value
| Type | Description |
|---|---|
| Int32 |
minWordIndexationLength
Minimal indexed word size.
Declaration
public int minWordIndexationLength { get; set; }
Property Value
| Type | Description |
|---|---|
| Int32 |
name
Name of the index. Generally this name is given by a user from a UnityEditor.Search.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, Boolean> |
timestamp
Time indicating when the index was saved
Declaration
public long timestamp { get; }
Property Value
| Type | Description |
|---|---|
| Int64 |
Methods
AddDocument(String, Boolean)
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 |
| Boolean | checkIfExists | Pass true if this document has some chances of existing already. |
Returns
| Type | Description |
|---|---|
| Int32 | The document index/handle used to add new index entries. |
AddDocument(String, String, String, Boolean, SearchDocumentFlags)
Declaration
public int AddDocument(string document, string name, string source, bool checkIfExists, SearchDocumentFlags flags)
Parameters
| Type | Name | Description |
|---|---|---|
| String | document | |
| String | name | |
| String | source | |
| Boolean | checkIfExists | |
| SearchDocumentFlags | flags |
Returns
| Type | Description |
|---|---|
| Int32 |
AddExactWord(String, Int32, Int32)
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. |
| Int32 | score | Relevance score of the word. |
| Int32 | documentIndex | Document where the indexed word was found. |
AddNumber(String, Double, Int32, Int32)
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. |
| Int32 | score | Relevance score of the word. |
| Int32 | documentIndex | Document where the indexed value was found. |
AddProperty(String, String, Int32, Boolean, Boolean)
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. |
| Int32 | documentIndex | Document where the indexed value was found. |
| Boolean | saveKeyword | Define if we store this key in the keyword registry of the index. See UnityEditor.Search.SearchIndexer.GetKeywords. |
| Boolean | exact | If true, we will store also an exact match entry for this word. |
AddProperty(String, String, Int32, Int32, Boolean, Boolean)
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. |
| Int32 | score | Relevance score of the word. |
| Int32 | documentIndex | Document where the indexed value was found. |
| Boolean | saveKeyword | Define if we store this key in the keyword registry of the index. See UnityEditor.Search.SearchIndexer.GetKeywords. |
| Boolean | exact | If true, we will store also an exact match entry for this word. |
AddProperty(String, String, Int32, Int32, Int32, Int32, Boolean, Boolean)
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. |
| Int32 | minVariations | Minimum number of variations to compute for the value. Cannot be higher than the length of the word. |
| Int32 | maxVariations | Maximum number of variations to compute for the value. Cannot be higher than the length of the word. |
| Int32 | score | Relevance score of the word. |
| Int32 | documentIndex | Document where the indexed value was found. |
| Boolean | saveKeyword | Define if we store this key in the keyword registry of the index. See UnityEditor.Search.SearchIndexer.GetKeywords. |
| Boolean | exact | If true, we will store also an exact match entry for this word. |
AddWord(String, Int32, Int32)
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. |
| Int32 | score | Relevance score of the word. |
| Int32 | documentIndex | Document where the indexed word was found. |
AddWord(String, Int32, Int32, Int32)
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. |
| Int32 | size | Number of variations to compute. |
| Int32 | score | Relevance score of the word. |
| Int32 | documentIndex | Document where the indexed word was found. |
AddWord(String, Int32, Int32, Int32, Int32)
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. |
| Int32 | minVariations | Minimum number of variations to compute. Cannot be higher than the length of the word. |
| Int32 | maxVariations | Maximum number of variations to compute. Cannot be higher than the length of the word. |
| Int32 | score | Relevance score of the word. |
| Int32 | 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, String[])
Declaration
public void Finish(Action threadCompletedCallback, string[] removedDocuments)
Parameters
| Type | Name | Description |
|---|---|---|
| Action | threadCompletedCallback | |
| String[] | removedDocuments |
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) |
Finish(Action<Byte[]>, String[], Boolean)
Declaration
public void Finish(Action<byte[]> threadCompletedCallback, string[] removedDocuments, bool saveBytes)
Parameters
| Type | Name | Description |
|---|---|---|
| Action<Byte[]> | threadCompletedCallback | |
| String[] | removedDocuments | |
| Boolean | saveBytes |
Finish(String[])
Declaration
public void Finish(string[] removedDocuments)
Parameters
| Type | Name | Description |
|---|---|---|
| String[] | removedDocuments |
GetDocument(Int32)
Return a search document by its index.
Declaration
public SearchDocument GetDocument(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | 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, Boolean)
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. |
| Boolean | 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 |
|---|---|
| Boolean | Returns true if the index is ready for search. |
LoadBytes(Byte[], Action<Boolean>)
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<Boolean> | finished | Callback that will trigger when the index is fully loaded. The callback parameters indicate if the loading was succesful. |
Returns
| Type | Description |
|---|---|
| Boolean | Returns false if the index is of an unsupported version or if there was a problem initializing the reading thread. |
Merge(String[], SearchIndexer, Int32, Action<Int32, SearchIndexer, Int32>)
Declaration
public void Merge(string[] removeDocuments, SearchIndexer other, int baseScore = 0, Action<int, SearchIndexer, int> documentIndexing = null)
Parameters
| Type | Name | Description |
|---|---|---|
| String[] | removeDocuments | |
| SearchIndexer | other | |
| Int32 | baseScore | |
| Action<Int32, SearchIndexer, Int32> | documentIndexing |
Read(Stream, Boolean)
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. |
| Boolean | checkVersionOnly | If true, it will only read the version of the index and stop reading any more content. |
Returns
| Type | Description |
|---|---|
| Boolean | 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, Int32, Int32)
Declaration
public virtual IEnumerable<SearchResult> Search(string query, int maxScore = 2147483647, int patternMatchLimit = 2999)
Parameters
| Type | Name | Description |
|---|---|---|
| String | query | |
| Int32 | maxScore | |
| Int32 | patternMatchLimit |
Returns
| Type | Description |
|---|---|
| IEnumerable<SearchResult> |
Search(String, SearchContext, SearchProvider, Int32, Int32)
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. |
| Int32 | maxScore | Maximum score of any matched Search Result. See score. |
| Int32 | 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, Int32, Int32)
Declaration
public virtual IEnumerable<SearchResult> Search(SearchContext context, SearchProvider provider, int maxScore = 2147483647, int patternMatchLimit = 2999)
Parameters
| Type | Name | Description |
|---|---|---|
| SearchContext | context | |
| SearchProvider | provider | |
| Int32 | maxScore | |
| Int32 | 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, Boolean)
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 |
| Boolean | checkRoots |
Returns
| Type | Description |
|---|---|
| Boolean | Returns true if the document doesn't need to be indexed. |
Start(Boolean)
Start indexing entries.
Declaration
public void Start(bool clear = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Boolean | 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. |