-
Notifications
You must be signed in to change notification settings - Fork 10
Add ngram updates #189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add ngram updates #189
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,6 +67,7 @@ enum DgraphIndex { | |
term | ||
fulltext | ||
trigram | ||
ngram | ||
regexp | ||
year | ||
month | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -85,15 +85,13 @@ | |||||
|
||||||
```graphql | ||||||
queryAuthor(filter: { name: { eq: "Diggy" } } ) { | ||||||
posts(filter: { title: { anyofterms: "GraphQL" }}) { | ||||||
title | ||||||
} | ||||||
} | ||||||
``` | ||||||
|
||||||
Dgraph can build search types with the ability to search between a range. For | ||||||
example with the above Post type with datePublished field, a query can find | ||||||
publish dates within a range | ||||||
example, with the preceding Post type with the `datePublished` field, a query | ||||||
can find publish dates within a range. | ||||||
|
||||||
```graphql | ||||||
query { | ||||||
|
@@ -104,8 +102,8 @@ | |||||
``` | ||||||
|
||||||
Dgraph can also build GraphQL search ability to find match a value from a list. | ||||||
For example with the above Author type with the name field, a query can return | ||||||
the Authors that match a list | ||||||
For example with the preceding Author type with the name field, a query can | ||||||
return the Authors that match a list | ||||||
|
||||||
```graphql | ||||||
queryAuthor(filter: { name: { in: ["Diggy", "Jarvis"] } } ) { | ||||||
|
@@ -115,13 +113,13 @@ | |||||
|
||||||
There's different search possible for each type as explained below. | ||||||
|
||||||
### Int, Float and DateTime | ||||||
### Int, float and dateTime | ||||||
|
||||||
| argument | constructed filter | | ||||||
| -------- | ------------------------------------------------- | | ||||||
| none | `lt`, `le`, `eq`, `in`, `between`, `ge`, and `gt` | | ||||||
|
||||||
Search for fields of types `Int`, `Float` and `DateTime` is enabled by adding | ||||||
Search for fields of types `Int`, `Float` and `dateTime` is enabled by adding | ||||||
`@search` to the field with no arguments. For example, if a schema contains: | ||||||
|
||||||
```graphql | ||||||
|
@@ -187,7 +185,7 @@ | |||||
} | ||||||
``` | ||||||
|
||||||
### DateTime | ||||||
### dateTime | ||||||
|
||||||
| argument | constructed filters | | ||||||
| --------------------------------- | ------------------------------------------------- | | ||||||
|
@@ -198,14 +196,14 @@ | |||||
defaults to year, but once you understand your data and query patterns, you | ||||||
might want to changes that like `@search(by: [day])`. | ||||||
|
||||||
### Boolean | ||||||
### Boolean fields | ||||||
|
||||||
| argument | constructed filter | | ||||||
| -------- | ------------------ | | ||||||
| none | `true` and `false` | | ||||||
|
||||||
Booleans can only be tested for true or false. If `isPublished: Boolean @search` | ||||||
is in the schema, then the search allows | ||||||
Boolean fields can only be tested for `true` or `false`. If | ||||||
`isPublished: Boolean @search` is in the schema, then the search allows | ||||||
|
||||||
```graphql | ||||||
filter: { isPublished: true } | ||||||
|
@@ -229,6 +227,7 @@ | |||||
| `regexp` | `regexp` (regular expressions) | | ||||||
| `term` | `allofterms` and `anyofterms` | | ||||||
| `fulltext` | `alloftext` and `anyoftext` | | ||||||
| `ngram` | `ngram` | | ||||||
|
||||||
- _Schema rule_: `hash` and `exact` can't be used together. | ||||||
|
||||||
|
@@ -250,7 +249,7 @@ | |||||
} | ||||||
``` | ||||||
|
||||||
to find users with names lexicographically after "Diggy". | ||||||
to find users with names lexicographically after "Diggy." | ||||||
|
||||||
#### String regular expression search | ||||||
|
||||||
|
@@ -283,12 +282,8 @@ | |||||
} | ||||||
``` | ||||||
|
||||||
will match all posts with both "GraphQL and "tutorial" in the title, while | ||||||
`anyofterms: "GraphQL tutorial"` would match posts with either "GraphQL" or | ||||||
"tutorial". | ||||||
|
||||||
`fulltext` search is Google-stye text search with stop words, stemming. etc. So | ||||||
`alloftext: "run woman"` would match "run" as well as "running", etc. For | ||||||
example, to find posts that talk about fantastic GraphQL tutorials: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The removal of the explanation about Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The removal of the explanation about fulltext search behavior (lines 286-288) removes important context about how fulltext search differs from term search, including stemming and stop word handling.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
```graphql | ||||||
|
@@ -297,6 +292,32 @@ | |||||
} | ||||||
``` | ||||||
|
||||||
#### String ngram search | ||||||
|
||||||
The `ngram` index tokenizes a string into contiguous sequences of n words, with | ||||||
support for stop word removal and stemming. N-gram search matches if the indexed | ||||||
string contains the given sequence of terms. | ||||||
|
||||||
If the schema has | ||||||
|
||||||
```graphql | ||||||
type Post { | ||||||
title: String @search(by: [ngram]) | ||||||
... | ||||||
} | ||||||
``` | ||||||
|
||||||
then | ||||||
|
||||||
```graphql | ||||||
query { | ||||||
queryPost(filter: { title: { ngram: "quick brown fox" } } ) { ... } | ||||||
} | ||||||
``` | ||||||
|
||||||
will match all posts that contain the contiguous sequence "quick brown fox" in | ||||||
the title. | ||||||
|
||||||
#### Strings with multiple searches | ||||||
|
||||||
It is possible to add multiple string indexes to a field. For example to search | ||||||
|
@@ -310,7 +331,7 @@ | |||||
} | ||||||
``` | ||||||
|
||||||
### Enums | ||||||
### enums | ||||||
|
||||||
| argument | constructed searches | | ||||||
| -------- | --------------------------------------------------------------------- | | ||||||
|
@@ -319,8 +340,8 @@ | |||||
| `exact` | `lt`, `le`, `eq`, `in`, `between`, `ge`, and `gt` (lexicographically) | | ||||||
| `regexp` | `regexp` (regular expressions) | | ||||||
|
||||||
Enums are serialized in Dgraph as strings. `@search` with no arguments is the | ||||||
same as `@search(by: [hash])` and provides `eq` and `in` searches. Also | ||||||
enum fields are serialized in Dgraph as strings. `@search` with no arguments is | ||||||
the same as `@search(by: [hash])` and provides `eq` and `in` searches. Also | ||||||
available for enums are `exact` and `regexp`. For hash and exact search on | ||||||
enums, the literal enum value, without quotes `"..."`, is used, for regexp, | ||||||
strings are required. For example: | ||||||
|
@@ -387,7 +408,7 @@ | |||||
} | ||||||
``` | ||||||
|
||||||
#### near | ||||||
#### Near | ||||||
|
||||||
The `near` filter matches all entities where the location given by a field is | ||||||
within a distance `meters` from a coordinate. | ||||||
|
@@ -408,7 +429,7 @@ | |||||
} | ||||||
``` | ||||||
|
||||||
#### within | ||||||
#### Within | ||||||
|
||||||
The `within` filter matches all entities where the location given by a field is | ||||||
within a defined `polygon`. | ||||||
|
@@ -441,7 +462,7 @@ | |||||
} | ||||||
``` | ||||||
|
||||||
#### contains | ||||||
#### Contains | ||||||
|
||||||
The `contains` filter matches all entities where the `Polygon` or `MultiPolygon` | ||||||
field contains another given `point` or `polygon`. | ||||||
|
@@ -489,7 +510,7 @@ | |||||
} | ||||||
``` | ||||||
|
||||||
#### intersects | ||||||
#### Intersects | ||||||
|
||||||
The `intersects` filter matches all entities where the `Polygon` or | ||||||
`MultiPolygon` field intersects another given `polygon` or `multiPolygon`. | ||||||
|
@@ -579,8 +600,8 @@ | |||||
but you can filter and paginate them. | ||||||
|
||||||
<Note> | ||||||
Union queries do not support the `order` argument. The results will be ordered | ||||||
by the `uid` of each node in ascending order. | ||||||
Union queries don't support the `order` argument. The results will be ordered | ||||||
by the UID of each node in ascending order. | ||||||
</Note> | ||||||
|
||||||
For example, the following schema will enable to query the `members` union field | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code block is incomplete - it's missing the closing brace and content. The removal of lines 88-89 appears to have left this query example broken.
Copilot uses AI. Check for mistakes.