Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
StackExchange.Redis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
StackExchange.Redis
Commits
e0343c18
Commit
e0343c18
authored
Jun 13, 2017
by
rsubhank
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sorting Feature Added
parent
1a541b7f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
4 deletions
+64
-4
Query.cs
NRediSearch/Query.cs
+30
-0
Schema.cs
NRediSearch/Schema.cs
+34
-4
No files found.
NRediSearch/Query.cs
View file @
e0343c18
...
...
@@ -161,6 +161,16 @@ public Paging(int offset, int count)
/// </summary>
public
byte
[]
Payload
{
get
;
set
;
}
/// <summary>
/// Set the query parameter to sort by
/// </summary>
public
string
_sortBy
{
get
;
set
;
}
/// <summary>
/// Set the query parameter to sort by ASC by default
/// </summary>
public
bool
_sortAsc
=
true
;
/// <summary>
/// Create a new index
/// </summary>
...
...
@@ -205,6 +215,13 @@ internal void SerializeRedisArgs(List<object> args)
args
.
AddRange
(
_fields
);
}
if
(
_sortBy
!=
null
)
{
args
.
Add
(
"SORTBY"
.
Literal
());
args
.
Add
(
_sortBy
.
Literal
());
args
.
Add
((
_sortAsc
?
"ASC"
:
"DESC"
).
Literal
());
}
if
(
Payload
!=
null
)
{
args
.
Add
(
"PAYLOAD"
.
Literal
());
...
...
@@ -260,5 +277,18 @@ public Query LimitFields(params string[] fields)
this
.
_fields
=
fields
;
return
this
;
}
/// <summary>
/// Set the query to be sorted by a sortable field defined in the schema
/// </summary>
/// <param name="field">the sorting field's name</param>
/// <param name="ascending">if set to true, the sorting order is ascending, else descending</param>
/// <returns>the query object itself</returns>
public
Query
SetSortBy
(
string
field
,
bool
ascending
)
{
_sortBy
=
field
;
_sortAsc
=
ascending
;
return
this
;
}
}
}
NRediSearch/Schema.cs
View file @
e0343c18
...
...
@@ -22,11 +22,13 @@ public class Field
{
public
String
Name
{
get
;
}
public
FieldType
Type
{
get
;
}
public
bool
Sortable
{
get
;}
internal
Field
(
string
name
,
FieldType
type
)
internal
Field
(
string
name
,
FieldType
type
,
bool
sortable
)
{
Name
=
name
;
Type
=
type
;
Sortable
=
sortable
;
}
internal
virtual
void
SerializeRedisArgs
(
List
<
object
>
args
)
...
...
@@ -43,12 +45,17 @@ object GetForRedis(FieldType type)
}
args
.
Add
(
Name
);
args
.
Add
(
GetForRedis
(
Type
));
if
(
Sortable
){
args
.
Add
(
"SORTABLE"
);}
}
}
public
class
TextField
:
Field
{
public
double
Weight
{
get
;
}
internal
TextField
(
string
name
,
double
weight
=
1.0
)
:
base
(
name
,
FieldType
.
FullText
)
internal
TextField
(
string
name
,
double
weight
=
1.0
)
:
base
(
name
,
FieldType
.
FullText
,
false
)
{
Weight
=
weight
;
}
internal
TextField
(
string
name
,
bool
sortable
,
double
weight
=
1.0
)
:
base
(
name
,
FieldType
.
FullText
,
sortable
)
{
Weight
=
weight
;
}
...
...
@@ -77,6 +84,18 @@ public Schema AddTextField(string name, double weight = 1.0)
return
this
;
}
/// <summary>
/// Add a text field that can be sorted on
/// </summary>
/// <param name="name">the field's name</param>
/// <param name="weight">its weight, a positive floating point number</param>
/// <returns>the schema object</returns>
public
Schema
AddSortableTextField
(
string
name
,
double
weight
=
1.0
)
{
Fields
.
Add
(
new
TextField
(
name
,
true
,
weight
));
return
this
;
}
/// <summary>
/// Add a numeric field to the schema
/// </summary>
...
...
@@ -84,7 +103,7 @@ public Schema AddTextField(string name, double weight = 1.0)
/// <returns>the schema object</returns>
public
Schema
AddGeoField
(
string
name
)
{
Fields
.
Add
(
new
Field
(
name
,
FieldType
.
Geo
));
Fields
.
Add
(
new
Field
(
name
,
FieldType
.
Geo
,
false
));
return
this
;
}
...
...
@@ -95,7 +114,18 @@ public Schema AddGeoField(string name)
/// <returns>the schema object</returns>
public
Schema
AddNumericField
(
string
name
)
{
Fields
.
Add
(
new
Field
(
name
,
FieldType
.
Numeric
));
Fields
.
Add
(
new
Field
(
name
,
FieldType
.
Numeric
,
false
));
return
this
;
}
/// <summary>
/// Add a numeric field that can be sorted on
/// </summary>
/// <param name="name">the field's name</param>
/// <returns>the schema object</returns>
public
Schema
AddSortableNumericField
(
string
name
)
{
Fields
.
Add
(
new
Field
(
name
,
FieldType
.
Numeric
,
true
));
return
this
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment