Skip to content

Instantly share code, notes, and snippets.

@Nick-S-2018
Created May 17, 2023 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nick-S-2018/490ceb0dc7a27b544fd1597826f0ab5e to your computer and use it in GitHub Desktop.
Save Nick-S-2018/490ceb0dc7a27b544fd1597826f0ab5e to your computer and use it in GitHub Desktop.
Basic testing example
using System;
using System.Collections.Generic;
using System.Net.Http;
using ManticoreSearch.Api;
using ManticoreSearch.Client;
using ManticoreSearch.Model;
namespace Example
{
public class BasicExample
{
public static void Main()
{
Configuration config = new Configuration();
config.BasePath = "http://127.0.0.1:9308";
var httpClient = new HttpClient();
var utilsApi = new UtilsApi(httpClient, config);
var indexApi = new IndexApi(httpClient, config);
var searchApi = new SearchApi(httpClient, config);
utilsApi.Sql("drop table products1", true);
string tableBody = "create table if not exists products1 (ProductUrl text, Name text, Sku text,ShortDescription text,FullDescription text,Price float, OldPriceValue float, Published bool, Quantity integer, HasDiscountsApplied bool, StockQuantity integer, ShowOnHomepage bool, CreatedOnUtc timestamp)";
utilsApi.Sql(tableBody, true);
Dictionary<string, Object> doc = new Dictionary<string, Object> {
{"Name", "build-your-own-computer 2"},
{"ProductUrl", "build-your-own-computer2"},
{"Sku", "COMP_CUST_2"},
{"ShortDescription", "Digital Storm Vanquish 3 Desktop PC"},
{"FullDescription", "<p>Blow the doors off today’s most demanding games with maximum detail, speed, and power for an immersive gaming experience without breaking the bank.</p>\n<p>Stay ahead of the competition, VANQUISH 3 is fully equipped to easily handle future upgrades, keeping your system on the cutting edge for years to come.</p>\n<p>Each system is put through an extensive stress test, ensuring you experience zero bottlenecks and get the maximum performance from your hardware.</p>"},
{"Price", 1259.0000},
{"OldPriceValue", 0.0000},
{"Published", true},
{"Quantity", 10000},
{"HasDiscountsApplied", false},
{"StockQuantity", 1},
{"ShowOnHomepage", false},
{"CreatedOnUtc", "2023-03-16T08:51:28.541735"}
};
InsertDocumentRequest insertDocumentRequest = new InsertDocumentRequest(index: "products1", id: 1, doc: doc);
indexApi.Insert(insertDocumentRequest);
var searchRequest = new SearchRequest(index: "products1", query: new { match = new { Name = "build" } }, limit: 100);
var searchResponse = searchApi.Search(searchRequest);
Console.WriteLine(searchResponse);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment