IFulltext SessionBuild Snippets AsyncTDocument(IEnumerableString, String, Snippets Options) Method
Builds snippets for the given data using the text processing settings from the index for the given
document type.
Definition
Namespace: SphinxConnector.FluentApi
Assembly: SphinxConnector (in SphinxConnector.dll) Version: 6.1.0
A list of strings with the snippets.
Assembly: SphinxConnector (in SphinxConnector.dll) Version: 6.1.0
C#
Task<IList<string>> BuildSnippetsAsync<TDocument>(
IEnumerable<string> data,
string query,
SnippetsOptions options
)
VB
Function BuildSnippetsAsync(Of TDocument) (
data As IEnumerable(Of String),
query As String,
options As SnippetsOptions
) As Task(Of IList(Of String))Parameters
- data IEnumerableString
- The data to build snippets for.
- query String
- The query to build snippets for.
- options SnippetsOptions
- The options to use.
Type Parameters
- TDocument
- The document type to build snippets for. This determines the index to take the text processing settings from.
Return Value
TaskIListStringA list of strings with the snippets.
Example
Suppose you have the following class representing a document in your index:
C#
public class Product
{
public int Id { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public decimal Price { get; set; }
public int CategoryId { get; set; }
public int VendorId { get; set; }
public int Weight { get; set; }
}
C#
using (IFulltextSession fulltextSession = fulltextStore.StartSession())
{
var results = await fulltextSession.Query<Product>().
Match("my query").
ToList();
var descriptionSnippets = await fulltextSession.BuildSnippetsAsync<Product>(results.Select(p => p.Description), "my query", new SnippetsOptions
{
BeforeMatch = "<i>",
AfterMatch = "</i>",
HtmlStripMode = HtmlStripMode.Strip
}););
}Exceptions
| ObjectDisposedException | Occurs when the session has already been disposed. |
| ArgumentNullException | One of data, query or options is null. |
| ArgumentException | query is empty. |
| FulltextException | Occurs when there is an error during the execution of the query. |