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
3e949794
Commit
3e949794
authored
Mar 12, 2018
by
Nick Craver
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup: extensionsCleanup: NRediSearch
parent
4196a130
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
33 deletions
+26
-33
Literals.cs
NRediSearch/Literals.cs
+3
-2
Query.cs
NRediSearch/Query.cs
+14
-19
Schema.cs
NRediSearch/Schema.cs
+4
-2
SearchResult.cs
NRediSearch/SearchResult.cs
+5
-10
No files found.
NRediSearch/Literals.cs
View file @
3e949794
...
@@ -7,11 +7,12 @@ namespace NRediSearch
...
@@ -7,11 +7,12 @@ namespace NRediSearch
/// </summary>
/// </summary>
internal
static
class
Literals
internal
static
class
Literals
{
{
private
static
Hashtable
_boxed
=
new
Hashtable
();
private
static
readonly
Hashtable
_boxed
=
new
Hashtable
();
private
static
object
_null
=
RedisValue
.
Null
;
private
static
readonly
object
_null
=
RedisValue
.
Null
;
/// <summary>
/// <summary>
/// Obtain a lazily-cached pre-encoded and boxed representation of a string
/// Obtain a lazily-cached pre-encoded and boxed representation of a string
/// </summary>
/// </summary>
/// <param name="value">The value to get a literal representation for.</param>
/// <remarks>This shoul donly be used for fixed values, not user data (the cache is never reclaimed, so it will be a memory leak)</remarks>
/// <remarks>This shoul donly be used for fixed values, not user data (the cache is never reclaimed, so it will be a memory leak)</remarks>
public
static
object
Literal
(
this
string
value
)
public
static
object
Literal
(
this
string
value
)
{
{
...
...
NRediSearch/Query.cs
View file @
3e949794
// .NET port of https://github.com/RedisLabs/JRediSearch/
// .NET port of https://github.com/RedisLabs/JRediSearch/
using
StackExchange.Redis
;
using
StackExchange.Redis
;
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
...
@@ -17,7 +16,6 @@ public class Query
...
@@ -17,7 +16,6 @@ public class Query
/// </summary>
/// </summary>
public
abstract
class
Filter
public
abstract
class
Filter
{
{
public
string
Property
{
get
;
}
public
string
Property
{
get
;
}
internal
abstract
void
SerializeRedisArgs
(
List
<
object
>
args
);
internal
abstract
void
SerializeRedisArgs
(
List
<
object
>
args
);
...
@@ -26,7 +24,6 @@ internal Filter(string property)
...
@@ -26,7 +24,6 @@ internal Filter(string property)
{
{
Property
=
property
;
Property
=
property
;
}
}
}
}
/// <summary>
/// <summary>
...
@@ -34,7 +31,6 @@ internal Filter(string property)
...
@@ -34,7 +31,6 @@ internal Filter(string property)
/// </summary>
/// </summary>
public
class
NumericFilter
:
Filter
public
class
NumericFilter
:
Filter
{
{
private
readonly
double
min
,
max
;
private
readonly
double
min
,
max
;
private
readonly
bool
exclusiveMin
,
exclusiveMax
;
private
readonly
bool
exclusiveMin
,
exclusiveMax
;
...
@@ -48,7 +44,6 @@ public NumericFilter(string property, double min, bool exclusiveMin, double max,
...
@@ -48,7 +44,6 @@ public NumericFilter(string property, double min, bool exclusiveMin, double max,
public
NumericFilter
(
string
property
,
double
min
,
double
max
)
:
this
(
property
,
min
,
false
,
max
,
false
)
{
}
public
NumericFilter
(
string
property
,
double
min
,
double
max
)
:
this
(
property
,
min
,
false
,
max
,
false
)
{
}
internal
override
void
SerializeRedisArgs
(
List
<
object
>
args
)
internal
override
void
SerializeRedisArgs
(
List
<
object
>
args
)
{
{
RedisValue
FormatNum
(
double
num
,
bool
exclude
)
RedisValue
FormatNum
(
double
num
,
bool
exclude
)
...
@@ -72,9 +67,8 @@ RedisValue FormatNum(double num, bool exclude)
...
@@ -72,9 +67,8 @@ RedisValue FormatNum(double num, bool exclude)
/// </summary>
/// </summary>
public
class
GeoFilter
:
Filter
public
class
GeoFilter
:
Filter
{
{
private
readonly
double
lon
,
lat
,
radius
;
private
readonly
double
lon
,
lat
,
radius
;
private
GeoUnit
unit
;
private
readonly
GeoUnit
unit
;
public
GeoFilter
(
string
property
,
double
lon
,
double
lat
,
double
radius
,
GeoUnit
unit
)
:
base
(
property
)
public
GeoFilter
(
string
property
,
double
lon
,
double
lat
,
double
radius
,
GeoUnit
unit
)
:
base
(
property
)
{
{
...
@@ -118,17 +112,17 @@ public Paging(int offset, int count)
...
@@ -118,17 +112,17 @@ public Paging(int offset, int count)
/// <summary>
/// <summary>
/// The query's filter list. We only support AND operation on all those filters
/// The query's filter list. We only support AND operation on all those filters
/// </summary>
/// </summary>
List
<
Filter
>
_filters
=
new
List
<
Filter
>();
private
readonly
List
<
Filter
>
_filters
=
new
List
<
Filter
>();
/// <summary>
/// <summary>
/// The textual part of the query
/// The textual part of the query
/// </summary>
/// </summary>
public
string
QueryString
{
get
;
}
public
string
QueryString
{
get
;
}
/// <summary>
/// <summary>
/// The sorting parameters
/// The sorting parameters
/// </summary>
/// </summary>
Paging
_paging
=
new
Paging
(
0
,
10
);
private
Paging
_paging
=
new
Paging
(
0
,
10
);
/// <summary>
/// <summary>
/// Set the query to verbatim mode, disabling stemming and query expansion
/// Set the query to verbatim mode, disabling stemming and query expansion
...
@@ -169,12 +163,13 @@ public Paging(int offset, int count)
...
@@ -169,12 +163,13 @@ public Paging(int offset, int count)
/// <summary>
/// <summary>
/// Set the query parameter to sort by ASC by default
/// Set the query parameter to sort by ASC by default
/// </summary>
/// </summary>
public
bool
SortAscending
{
get
;
set
;
}
=
true
;
public
bool
SortAscending
{
get
;
set
;
}
=
true
;
/// <summary>
/// <summary>
/// Create a new index
/// Create a new index
/// </summary>
/// </summary>
public
Query
(
String
queryString
)
/// <param name="queryString">The query string to use for this query.</param>
public
Query
(
string
queryString
)
{
{
QueryString
=
queryString
;
QueryString
=
queryString
;
}
}
...
@@ -208,14 +203,14 @@ internal void SerializeRedisArgs(List<object> args)
...
@@ -208,14 +203,14 @@ internal void SerializeRedisArgs(List<object> args)
args
.
Add
(
"LANGUAGE"
.
Literal
());
args
.
Add
(
"LANGUAGE"
.
Literal
());
args
.
Add
(
Language
);
args
.
Add
(
Language
);
}
}
if
(
_fields
!=
null
&&
_fields
.
Length
>
0
)
if
(
_fields
?
.
Length
>
0
)
{
{
args
.
Add
(
"INFIELDS"
.
Literal
());
args
.
Add
(
"INFIELDS"
.
Literal
());
args
.
Add
(
_fields
.
Length
);
args
.
Add
(
_fields
.
Length
);
args
.
AddRange
(
_fields
);
args
.
AddRange
(
_fields
);
}
}
if
(
SortBy
!=
null
)
if
(
SortBy
!=
null
)
{
{
args
.
Add
(
"SORTBY"
.
Literal
());
args
.
Add
(
"SORTBY"
.
Literal
());
args
.
Add
(
SortBy
);
args
.
Add
(
SortBy
);
...
@@ -235,7 +230,7 @@ internal void SerializeRedisArgs(List<object> args)
...
@@ -235,7 +230,7 @@ internal void SerializeRedisArgs(List<object> args)
args
.
Add
(
_paging
.
Count
);
args
.
Add
(
_paging
.
Count
);
}
}
if
(
_filters
!=
null
&&
_filters
.
Count
>
0
)
if
(
_filters
?
.
Count
>
0
)
{
{
foreach
(
var
f
in
_filters
)
foreach
(
var
f
in
_filters
)
{
{
...
@@ -243,12 +238,12 @@ internal void SerializeRedisArgs(List<object> args)
...
@@ -243,12 +238,12 @@ internal void SerializeRedisArgs(List<object> args)
}
}
}
}
}
}
/// <summary>
/// <summary>
/// Limit the results to a certain offset and limit
/// Limit the results to a certain offset and limit
/// </summary>
/// </summary>
/// <param name="offset">the first result to show, zero based indexing</param>
/// <param name="offset">the first result to show, zero based indexing</param>
/// <param name="
limi
t">how many results we want to show</param>
/// <param name="
coun
t">how many results we want to show</param>
/// <returns>the query itself, for builder-style syntax</returns>
/// <returns>the query itself, for builder-style syntax</returns>
public
Query
Limit
(
int
offset
,
int
count
)
public
Query
Limit
(
int
offset
,
int
count
)
{
{
...
@@ -274,7 +269,7 @@ public Query AddFilter(Filter f)
...
@@ -274,7 +269,7 @@ public Query AddFilter(Filter f)
/// <returns>the query object itself</returns>
/// <returns>the query object itself</returns>
public
Query
LimitFields
(
params
string
[]
fields
)
public
Query
LimitFields
(
params
string
[]
fields
)
{
{
this
.
_fields
=
fields
;
_fields
=
fields
;
return
this
;
return
this
;
}
}
...
@@ -291,4 +286,4 @@ public Query SetSortBy(string field, bool ascending = true)
...
@@ -291,4 +286,4 @@ public Query SetSortBy(string field, bool ascending = true)
return
this
;
return
this
;
}
}
}
}
}
}
\ No newline at end of file
NRediSearch/Schema.cs
View file @
3e949794
...
@@ -50,6 +50,7 @@ object GetForRedis(FieldType type)
...
@@ -50,6 +50,7 @@ object GetForRedis(FieldType type)
if
(
Sortable
){
args
.
Add
(
"SORTABLE"
);}
if
(
Sortable
){
args
.
Add
(
"SORTABLE"
);}
}
}
}
}
public
class
TextField
:
Field
public
class
TextField
:
Field
{
{
public
double
Weight
{
get
;
}
public
double
Weight
{
get
;
}
...
@@ -57,10 +58,12 @@ internal TextField(string name, double weight = 1.0) : base(name, FieldType.Full
...
@@ -57,10 +58,12 @@ internal TextField(string name, double weight = 1.0) : base(name, FieldType.Full
{
{
Weight
=
weight
;
Weight
=
weight
;
}
}
internal
TextField
(
string
name
,
bool
sortable
,
double
weight
=
1.0
)
:
base
(
name
,
FieldType
.
FullText
,
sortable
)
internal
TextField
(
string
name
,
bool
sortable
,
double
weight
=
1.0
)
:
base
(
name
,
FieldType
.
FullText
,
sortable
)
{
{
Weight
=
weight
;
Weight
=
weight
;
}
}
internal
override
void
SerializeRedisArgs
(
List
<
object
>
args
)
internal
override
void
SerializeRedisArgs
(
List
<
object
>
args
)
{
{
base
.
SerializeRedisArgs
(
args
);
base
.
SerializeRedisArgs
(
args
);
...
@@ -138,6 +141,7 @@ internal TagField(string name, string separator = ",") : base(name, FieldType.Ta
...
@@ -138,6 +141,7 @@ internal TagField(string name, string separator = ",") : base(name, FieldType.Ta
{
{
Separator
=
separator
;
Separator
=
separator
;
}
}
internal
override
void
SerializeRedisArgs
(
List
<
object
>
args
)
internal
override
void
SerializeRedisArgs
(
List
<
object
>
args
)
{
{
base
.
SerializeRedisArgs
(
args
);
base
.
SerializeRedisArgs
(
args
);
...
@@ -160,7 +164,5 @@ public Schema AddTagField(string name, string separator = ",")
...
@@ -160,7 +164,5 @@ public Schema AddTagField(string name, string separator = ",")
Fields
.
Add
(
new
TagField
(
name
,
separator
));
Fields
.
Add
(
new
TagField
(
name
,
separator
));
return
this
;
return
this
;
}
}
}
}
}
}
NRediSearch/SearchResult.cs
View file @
3e949794
// .NET port of https://github.com/RedisLabs/JRediSearch/
// .NET port of https://github.com/RedisLabs/JRediSearch/
using
StackExchange.Redis
;
using
StackExchange.Redis
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
...
@@ -15,7 +14,6 @@ public class SearchResult
...
@@ -15,7 +14,6 @@ public class SearchResult
public
long
TotalResults
{
get
;
}
public
long
TotalResults
{
get
;
}
public
List
<
Document
>
Documents
{
get
;
}
public
List
<
Document
>
Documents
{
get
;
}
internal
SearchResult
(
RedisResult
[]
resp
,
bool
hasContent
,
bool
hasScores
,
bool
hasPayloads
)
internal
SearchResult
(
RedisResult
[]
resp
,
bool
hasContent
,
bool
hasScores
,
bool
hasPayloads
)
{
{
// Calculate the step distance to walk over the results.
// Calculate the step distance to walk over the results.
...
@@ -26,18 +24,18 @@ internal SearchResult(RedisResult[] resp, bool hasContent, bool hasScores, bool
...
@@ -26,18 +24,18 @@ internal SearchResult(RedisResult[] resp, bool hasContent, bool hasScores, bool
int
payloadOffset
=
0
;
int
payloadOffset
=
0
;
if
(
hasScores
)
if
(
hasScores
)
{
{
step
+=
1
;
step
++
;
scoreOffset
=
1
;
scoreOffset
=
1
;
contentOffset
+=
1
;
contentOffset
++
;
}
}
if
(
hasContent
)
if
(
hasContent
)
{
{
step
+=
1
;
step
++
;
if
(
hasPayloads
)
if
(
hasPayloads
)
{
{
payloadOffset
=
scoreOffset
+
1
;
payloadOffset
=
scoreOffset
+
1
;
step
+=
1
;
step
++
;
contentOffset
+=
1
;
contentOffset
++
;
}
}
}
}
...
@@ -47,7 +45,6 @@ internal SearchResult(RedisResult[] resp, bool hasContent, bool hasScores, bool
...
@@ -47,7 +45,6 @@ internal SearchResult(RedisResult[] resp, bool hasContent, bool hasScores, bool
Documents
=
docs
;
Documents
=
docs
;
for
(
int
i
=
1
;
i
<
resp
.
Length
;
i
+=
step
)
for
(
int
i
=
1
;
i
<
resp
.
Length
;
i
+=
step
)
{
{
var
id
=
(
string
)
resp
[
i
];
var
id
=
(
string
)
resp
[
i
];
double
score
=
1.0
;
double
score
=
1.0
;
byte
[]
payload
=
null
;
byte
[]
payload
=
null
;
...
@@ -68,8 +65,6 @@ internal SearchResult(RedisResult[] resp, bool hasContent, bool hasScores, bool
...
@@ -68,8 +65,6 @@ internal SearchResult(RedisResult[] resp, bool hasContent, bool hasScores, bool
docs
.
Add
(
Document
.
Load
(
id
,
score
,
payload
,
fields
));
docs
.
Add
(
Document
.
Load
(
id
,
score
,
payload
,
fields
));
}
}
}
}
}
}
}
}
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