Skip to content

Instantly share code, notes, and snippets.

View CreateIndex.cs
public void CreateIndex(SearchServiceClient searchServiceClient)
{
var index = new Index
{
Name = "peliculas",
Fields = new []
{
new Field("peliculaId", DataType.String) { IsKey = true },
new Field("titulo", DataType.String) { IsSearchable = true, IsFilterable = true },
new Field("director", DataType.String) { IsSearchable = true, IsFilterable = true, IsFacetable = true },
View GetIndexClientForPeliculas.cs
public SearchIndexClient GetIndexClientForPeliculas(SearchServiceClient serviceClient)
{
SearchIndexClient indexClient = serviceClient.Indexes.GetClient("peliculas");
return indexClient;
}
View UploadDocuments.cs
public void UploadDocuments(SearchIndexClient indexClient)
{
var documents = new Pelicula[]
{
new Pelicula
{
PeliculaId = "tt2084970",
Titulo = "El código enigma",
Director = "Morten Tyldum",
Actores = new [] { "Benedict Cumberbatch", "Keira Knightley", "Matthew Goode" },
View Pelicula.cs
[SerializePropertyNamesAsCamelCase]
public class Pelicula
{
public string PeliculaId { get; set; }
public string Titulo { get; set; }
public string Director { get; set; }
public string[] Actores { get; set; }
View GetSearchServiceClient.cs
public SearchServiceClient GetSearchServiceClient()
{
// El nombre del servicio es solamente la primera parte de la URL del servicio,
// ej.: https://miservicio.search.windows.net/
string searchServiceName = "miservicio";
string apiKey = "Aquí va una de las keys de administración."
SearchServiceClient serviceClient = new SearchServiceClient(searchServiceName, new SearchCredentials(apiKey));
return serviceClient;
View SearchDocuments.cs
public IEnumerable<Pelicula> SearchDocuments(SearchIndexClient indexClient, string searchText, string filter = null)
{
// Ejecutamos la búsqueda basada en un texto de búsqueda y filtros opcionales
var sp = new SearchParameters();
if (!String.IsNullOrEmpty(filter))
{
sp.Filter = filter;
}
View Create DataSource
POST https://[Nombre del servicio de Search].search.windows.net/datasources?api-version=[api-version]
Content-Type: application/json
api-key: [Key de administrador del servicio de Search]
View createDataSourceBody.json
{
"name": "miorigendedatosdocumentdb",
"type": "documentdb",
"credentials": {
"connectionString": "AccountEndpoint=https://miServicioDocumentDb.documents.azure.com;AccountKey=miKeyDeAutorizacionDocDb;Database=idDeMiBaseDeDatosDocDb"
},
"container": {
"name": "idDeLaColeccionDocDb",
"query": "SELECT p.id, p.Titulo, p.Director, p.Genero, p._ts FROM Peliculas p WHERE p._ts > @HighWaterMark"
},
View SelectPeliculas.sql
SELECT p.id, p.Titulo, p.Director, p.Genero, p._ts FROM Peliculas p WHERE p._ts > @HighWaterMark
View _tsSpec.json
{
"@odata.type" : "#Microsoft.Azure.Search.HighWaterMarkChangeDetectionPolicy",
"highWaterMarkColumnName" : "_ts"
}
You can’t perform that action at this time.