Set page and page size (pagination) and sorting

How to set pagination for return list using asp.net or json ?
If I have 100 matched records then I have to show only 10 records on first page.
If I set limit to 10 then I will get 10 records
But for get next 10 records, what I have to do ? (For 11 to 20, 21 to 30 and upto 91 to 100)
I means which properties is used for page index ? in search request

Thanks!

Pagination issue fixed, there is parameter “offset” and it working fine.

Now I want to sort my result by
Id (ascending) relevance
Name (ascending)
Name (descending)
Price (ascending)
Price (descending)

So how to pass value in List sort = null in search request
Can you please give an example ???

You can do it, for example, in the following way:

var searchRequest = new SearchRequest(index: "your_index", query: "your_query", sort: new List<Object>() { new { id = "asc"}, new { Name = "asc"}, new { Price = "desc"} });

You can add as much fields to the sort list as you need.

Thanks a lot @Nick
It’s working fine

Sort with string not supported by Manticore ?
I checked sort with Id (int) ascending/descending, price (float/decimal) ascending/descending working fine, while sort with name (string/text) not working and it sort by relevance.

Can you please help me about this.

Hi,
Sorting works with attribute fields only. I.e., you can use a string type field to be sorted by, but not text fields.

Is it possible to search with string ?
Can I set one field for sort and search both ?
I mean I have one field “name”, so can I make it searchable and sortable at same Index ?

Hi @Kamlesh ,
Yes, if your field has the string type, you can search and sort by it. E.g.:

var searchRequest = new SearchRequest(index: "your_index", query: new  { equals = { Name = "build" } }, sort: new List<Object>() { new { Name = "asc"} });

You can find more details on searching here

Hi @Nick ,
I tried this but “equals” condition checked full text.
If I have product name with “build your own computer” and I search with


var searchRequest = new SearchRequest(index: "your_index", query: new  { equals = { Name = "build" } });

then I got Zero results.

If I search with full text then I got result


var searchRequest = new SearchRequest(index: "your_index", query: new  { equals = { Name = "build your own computer" } });

But I want to search all products which name contains “build” so what I have to do ?

If I have type “text” then I can used “match” condition but I have type is “string” for name fields.

So what I have to do ?

If you still want to do full-text search on the Name field, you’ll have to redefine it as an indexed attribute, e.g.:

create table if not exists products1 (ProductUrl text, Name string indexed attribute)

Thanks @Nick
Now I can both search and sort on same attribute

Hello Nick,
I have “name” fields in two language as name_english and name_hindi,
Now I want to sort by name on working language.

I want like below
var working language = english
var sort = new List { new { name_english = “asc” } };

if working language = hindi
var sort = new List { new { name_hindi = “asc” } };

So what should be sort object and how to prepare it ?

you can sort only on weight or attribute value - there is no way to sort based on matched language

Okay. Thanks

I did from my side using json string

var obj = "{\"name_" + your_language_name + "\" : \"asc\"}";
var sort = new List<object> { JsonConvert.DeserializeObject(obj) };
var searchRequest = new SearchRequest(index: "your_index", query: "your_query", sort: sort);

SELECT *, IF(name.en IS NULL OR name.en = '', 1, 0) AS cond FROM myproducts WHERE REGEX(name.en, 'Apple') OR (cond=1 AND REGEX(name.standard, 'Apple') ) ORDER BY cond ASC, name.en ASC, name.standard ASC

Can you please suggest how to use this as a JSON ?
Can anyone please help me it to convert into JSON.

here is my table
CREATE TABLE myproducts(name json)

insert into myproducts(name) values(‘{“standard”: “Apple iphone 14 pro”, “en”: “”, “hi”: “”}’)
insert into myproducts(name) values(‘{“standard”: “Apple iphone 14 plus”, “en”: “”, “hi”: “”}’)

Hello,
You mean, how to perform the same query with Manticore HTTP JSON?

Yes, how to perform the same query with Manticore HTTP JSON?

Hello, @Kamlesh

You can use a query like this:

'{   
    "index" : "myproducts",
    "query": {
	"bool": {
	  "should": [
		{
		  "equals": {
		      "REGEX(name.en, \"Apple\")": 1
		  }
		},
		{
		  "bool": {
		    "must": [
		      {
		        "equals": {
		          "cond": 1
		        }
		      },
		      {
		        "equals": {
		          "REGEX(name.standard, \"Apple\")": 1
		        }
		      }
		    ]
		  }
		}
	  ]
	}
    },
    "script_fields":{
        "cond":{
            "script":{
                "inline": "IF(name.en IS NULL OR name.en = \"\", 1, 0)"
            }
        }
    },
    "sort":[
        {
            "cond":"asc"
        },
        {
            "name.en":"asc"
        },
        {
            "name.standard":"asc"
        }
    ]
}'

If you need, you can find more details on searching in our Manual

Okay thank you…
Now its working for me