Skip to content

Commit

Permalink
docs: add docs for list options builder (#380)
Browse files Browse the repository at this point in the history
### What this PR does?
添加 ListOptions builder 的文档说明

see also halo-dev/halo#6148

```release-note
None
```
  • Loading branch information
guqing committed Jul 2, 2024
1 parent 59096a9 commit 9b87090
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ public class ListOptions {
`FieldSelector` 支持比自动生成的 APIs 中更多的查询条件,可以通过 `run.halo.app.extension.index.query.QueryFactory` 来构建。

```java
FieldSelector.of(QueryFactory.and(
QueryFactory.equal("name", "test"),
QueryFactory.equal("age", 18)
))
ListOptions.builder()
.fieldQuery(QueryFactory.and(
QueryFactory.equal("name", "test"),
QueryFactory.equal("age", 18)
))
.build();
```

支持的查询条件如下:
Expand Down Expand Up @@ -166,9 +168,27 @@ Query query = and(
or(equal("dept", "A"), equal("dept", "B")),
or(equal("age", "19"), equal("age", "18"))
);
FieldSelector.of(query);
ListOptions.builder()
.fieldQuery(query)
.build();
```

### 构建 ListOptions

ListOptions 提供了 `builder` 方法用于构建查询条件,`fieldQuery` 方法用于传递字段查询条件,`labelSelector` 方法用于传递标签查询条件。

```java
ListOptions.builder()
.labelSelector()
.eq("key-1", "value-1")
.end()
.fieldQuery(QueryFactory.equal("key-2", "value-2"))
.build();
```

- `labelSelector` 之后使用 `end` 方法结束标签查询条件的构建。
- `andQuery``orQuery` 用于组合多个 `FieldSelector` 查询条件。

### 排序

`listBy``listAll` 方法都支持传递 `Sort` 参数,用于传递排序条件。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@ public class ListOptions {
`FieldSelector` 支持比自动生成的 APIs 中更多的查询条件,可以通过 `run.halo.app.extension.index.query.QueryFactory` 来构建。

```java
FieldSelector.of(QueryFactory.and(
QueryFactory.equal("name", "test"),
QueryFactory.equal("age", 18)
))
ListOptions.builder()
.fieldQuery(QueryFactory.and(
QueryFactory.equal("name", "test"),
QueryFactory.equal("age", 18)
))
.build();
```

支持的查询条件如下:
Expand Down Expand Up @@ -166,9 +168,27 @@ Query query = and(
or(equal("dept", "A"), equal("dept", "B")),
or(equal("age", "19"), equal("age", "18"))
);
FieldSelector.of(query);
ListOptions.builder()
.fieldQuery(query)
.build();
```

### 构建 ListOptions

ListOptions 提供了 `builder` 方法用于构建查询条件,`fieldQuery` 方法用于传递字段查询条件,`labelSelector` 方法用于传递标签查询条件。

```java
ListOptions.builder()
.labelSelector()
.eq("key-1", "value-1")
.end()
.fieldQuery(QueryFactory.equal("key-2", "value-2"))
.build();
```

- `labelSelector` 之后使用 `end` 方法结束标签查询条件的构建。
- `andQuery``orQuery` 用于组合多个 `FieldSelector` 查询条件。

### 排序

`listBy``listAll` 方法都支持传递 `Sort` 参数,用于传递排序条件。
Expand Down

0 comments on commit 9b87090

Please sign in to comment.