Search with asp.net client

I created index named “products1” and synced 100 products using asp.net client.
Now I want to find records that match with word “build”

I tried with below code, but getting wrong result and showing product with no word contains “build”

I used this code

public static void Main()
{
	Configuration config = new Configuration();
	config.BasePath = "http://127.0.0.1:9308";
	HttpClient httpClient = new HttpClient();
	HttpClientHandler httpClientHandler = new HttpClientHandler();
	var apiInstance = new SearchApi(httpClient, config, httpClientHandler);
	var searchRequest = new SearchRequest(index: "products1", query: new { match = new { _all = "build" } }, limit: 100);

	try
	{
		// Performs a search
		SearchResponse result = apiInstance.Search(searchRequest);
		Debug.WriteLine(result);
	}
	catch (ApiException  e)
	{
		Debug.Print("Exception when calling SearchApi.Search: " + e.Message);
		Debug.Print("Status Code: " + e.ErrorCode);
		Debug.Print(e.StackTrace);
	}
}

I had done everything from my side. I just stuck at here for match results.
Please help me for search.
Something is wrong with my search request ?

At first sight, your request is fine. Can you please provide us more details: the schema of your index and an example of a document from it? Also, please specify the Manticore version you use.

Hello Nick,

I am using Manticore 6.0.4

Here is my table
"create table if not exists products1 (name string,producturl string,sku string,oldpricevalue float,published bool,quantity integer,hasdiscountsapplied bool,stockquantity integer, shortdescription text,fulldescription text,showonhomepage bool,price float,createdonutc timestamp)"

And my search request is as mentioned in topic (my question)

I am not using MySQL, I am using MS SQL, So there is any issue with SQL or not ?

and showing product with no word contains “build”

You’ve provided the create table. After that the table is empty. Please provide the commands you used to populate the table. Best if you can reproduce the issue with just a single document in the table and provide as many details that will help us reproduce it on our end as possible.

Hello @Nick , @Sergey
MySQL is required or compulsory for Manticore search implementation with asp.net client ?
Anyone please give reply on this, I have confusion about this.

Mysql is not required at all.

Manticore does have its own SQL based dialect, used for running queries, and is also required to do so some ddl commands. E.g. the ‘create table’ command is in manticores own SQL dialect

It kinda looks similar to mysql but is not mysql.

So the various API clients can’t avoid exposing you to the SQL dialect at times. But many clients can avoid using SQL directly and issue search queries with custom http/JSON protocol under the hood

@Nick , @barryhunter , @Sergey

Below is my json object for single record.
Index name : “products1”

{"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"}

Now I want to search with word “build” using c# (asp.net)
So what should be a search request ?

I used below search search request but I got error.
var searchRequest = new SearchRequest(index: "products1", query: new { match = new { Name = "build" } }, limit: 100);

Error:
ManticoreSearch.Client.ApiException: 'Cannot deserialize the current JSON array (e.g. [1,2,3]) into type ‘ManticoreSearch.Model.SearchResponse’ because the type requires a JSON object (e.g. {“name”:“value”}) to deserialize correctly.

Please help me and suggest solution for this.

Hi,
Your initialization of SearchRequest is correct and should work fine.
Can you please specify the versions of Manticore and the C# client you use?
Also, providing the schema of your index would be helpful too.

I am using Manticore 6.0.4

Assembly ManticoreSearch, Version=0.0.0.0

Here is my created table

var utilsApi = new UtilsApi();
			string tableBody = "create table if not exists products (ProductId text, Name text,Sku text,ShortDescription text,FullDescription text,Price float,Published bool,ManufacturerPartNumber text,CreatedOnUtc timestamp,VendorId integer,Vendor text)";
			utilsApi.Sql(tableBody, true);

Can you please run this simple example and see if it produces any error? It has the same data you’ve provided to us. Just change, if necessary, config.BasePath to the one used in your Manticore config.

Hello team Manticore,

How to search from list of string ?
I have list of product’s categories name.
Example, I have one product as mentioned in above questions and it has two categories.
var categoryList = new List<string>{ "Computer", "Desktop" }

Now, I want to add one fields in my index (or table) for “CategoryList”
So what should be data type for it ? and how to search from that list ?

I checked there is data type “Multi-value integer (MVA)” but I think it is for lists of 32-bit unsigned integers.
But I want to list of strings, so which data type I have to use ?

Can you please suggest and give me an example.
Thank you.

Please help me for this

Manticore does not explicitly support string list types, but you can use a workaround with the any function. Assuming that you’ve defined CategoryList as a string attribute in your index, create a document:

var doc = new Dictionary<string, Object> { 
                {"Name", "test-build-your-own-computer 2"},
                {"CategoryList", "Computer Desktop SomeOtherCategory"}
};
var insertDocumentRequest = new InsertDocumentRequest(index: "products1", doc: doc);

After that, you can run a search request like this:

var equalsQuery = new Dictionary<string, Object> { {"any(CategoryList)", new List<string> {"Desktop"} } };
var searchRequest = new SearchRequest(index: "products1", query: new { equals = equalsQuery }, limit: 100);

Yaa, it is ok.
But I want to search in both(Name and CategoryList) or more than 2 fields than what should be search request ?
I have to use “match” condition or use “equals” condition ?
If both at same time then how ? Give me an example please.

How to use search and filter at same time in search request ?
Give me an example for this too please.

Hello team Manticore,

var match = "{\"bool\":{\"must\":[" +
		"{\"match\": { \"name,sku\": { \"query\": \"" + keywords + "\", \"operator\":\"or\" }}}" +
		"{\"in\": { \"all(categoryids)\": " + [1] + " }}," +
		"{\"range\": {\"price\":{\"gte\":" + priceMin + ",\"lte\":" + priceMax + "}}}" +
		"]}}";

I want to search with keywords = lenovo in my category Id = 1 and
I passed priceMin = 0 and priceMax = 10000 in above code

I tried this but getting error.
What is wrong with this query ?
Please help me

If my category name contains white space then it will work ?
I have categories name like “8 GB Pen drive”, “16 GB RAM”, “32 GB RAM”, “256 GB SSD”, “1 TB Hard drive”

Then how to pass value in query in search request ?

Hi,

{
 "bool": {
   "must": [
      {
        "match": { 
          "name,sku": {
           "query":  keywords, 
           "operator": "or" 
          }
        }
      }
      {
        "in": {
          "all(categoryids)": [1]
         }
      },
      {
        "range": {
          "price": {
            "gte": priceMin,
            "lte": priceMax
           }
         }
       }
   ]
 }
}

At first glance, your request object may miss a comma after the match filter sub-object. Apart from that, it looks correct.

In this case, you’ll have to use the json type for your category field and add the expressions field to your search requests like in the example below:

create table if not exists products1 (Name string indexed attribute, CategoryList json)
var doc = new Dictionary<string, Object> { 
                {"Name", "test-build-your-own-computer 2"},
                {"CategoryList",  "['16 GB RAM', '32 GB RAM', 'Some other category]"}
};
var insertDocumentRequest = new InsertDocumentRequest(index: "products1", doc: doc);

var expressions =  new Dictionary<string, Object> { { "expr1", "any(x='32 GB RAM' for x in CategoryList)" } };
var equalsQuery = new Dictionary<string, Object> { { "expr1", 1 } };
var searchRequest = new SearchRequest(index: "products1", expressions: expressions, query: equalsQuery);

what should be the value for “expr1” ?
match or equals or in ?
or some thing different ?