mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
chore: update tag search
This commit is contained in:
@ -92,7 +92,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
|||||||
}
|
}
|
||||||
if len(v.TagSearch) != 0 {
|
if len(v.TagSearch) != 0 {
|
||||||
for _, tag := range v.TagSearch {
|
for _, tag := range v.TagSearch {
|
||||||
where, args = append(where, "JSON_CONTAINS(JSON_EXTRACT(`memo`.`payload`, '$.property.tags'), ?)"), append(args, fmt.Sprintf(`"%s"`, tag))
|
where, args = append(where, "(JSON_CONTAINS(JSON_EXTRACT(`memo`.`payload`, '$.property.tags'), ?) OR JSON_CONTAINS(JSON_EXTRACT(`memo`.`payload`, '$.property.tags'), ?))"), append(args, fmt.Sprintf(`"%s"`, tag), fmt.Sprintf(`"%s/`, tag))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if v.HasLink {
|
if v.HasLink {
|
||||||
|
@ -83,7 +83,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
|||||||
}
|
}
|
||||||
if len(v.TagSearch) != 0 {
|
if len(v.TagSearch) != 0 {
|
||||||
for _, tag := range v.TagSearch {
|
for _, tag := range v.TagSearch {
|
||||||
where, args = append(where, "memo.payload->'property'->'tags' @> "+placeholder(len(args)+1)), append(args, fmt.Sprintf(`["%s"]`, tag))
|
where, args = append(where, "EXISTS (SELECT 1 FROM jsonb_array_elements(memo.payload->'property'->'tags') AS tag WHERE tag::text = "+placeholder(len(args)+1)+" OR tag::text LIKE "+placeholder(len(args)+2)+")"), append(args, fmt.Sprintf(`"%s"`, tag), fmt.Sprintf(`"%s/%%"`, tag))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if v.HasLink {
|
if v.HasLink {
|
||||||
|
@ -84,7 +84,7 @@ func (d *DB) ListMemos(ctx context.Context, find *store.FindMemo) ([]*store.Memo
|
|||||||
}
|
}
|
||||||
if len(v.TagSearch) != 0 {
|
if len(v.TagSearch) != 0 {
|
||||||
for _, tag := range v.TagSearch {
|
for _, tag := range v.TagSearch {
|
||||||
where, args = append(where, "JSON_EXTRACT(`memo`.`payload`, '$.property.tags') LIKE ?"), append(args, fmt.Sprintf(`%%"%s"%%`, tag))
|
where, args = append(where, "(JSON_EXTRACT(`memo`.`payload`, '$.property.tags') LIKE ? OR JSON_EXTRACT(`memo`.`payload`, '$.property.tags') LIKE ?)"), append(args, fmt.Sprintf(`%%"%s"%%`, tag), fmt.Sprintf(`%%"%s/%%`, tag))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if v.HasLink {
|
if v.HasLink {
|
||||||
|
@ -33,12 +33,12 @@ const PagedMemoList = (props: Props) => {
|
|||||||
setState((state) => ({ ...state, isRequesting }));
|
setState((state) => ({ ...state, isRequesting }));
|
||||||
};
|
};
|
||||||
|
|
||||||
const fetchMoreMemos = async () => {
|
const fetchMoreMemos = async (nextPageToken: string) => {
|
||||||
setIsRequesting(true);
|
setIsRequesting(true);
|
||||||
const response = await memoStore.fetchMemos({
|
const response = await memoStore.fetchMemos({
|
||||||
filter: props.filter || "",
|
filter: props.filter || "",
|
||||||
pageSize: props.pageSize || DEFAULT_LIST_MEMOS_PAGE_SIZE,
|
pageSize: props.pageSize || DEFAULT_LIST_MEMOS_PAGE_SIZE,
|
||||||
pageToken: state.nextPageToken,
|
pageToken: nextPageToken,
|
||||||
});
|
});
|
||||||
setState(() => ({
|
setState(() => ({
|
||||||
isRequesting: false,
|
isRequesting: false,
|
||||||
@ -49,7 +49,7 @@ const PagedMemoList = (props: Props) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
memoList.reset();
|
memoList.reset();
|
||||||
setState((state) => ({ ...state, nextPageToken: "" }));
|
setState((state) => ({ ...state, nextPageToken: "" }));
|
||||||
fetchMoreMemos();
|
fetchMoreMemos("");
|
||||||
}, [props.filter, props.pageSize]);
|
}, [props.filter, props.pageSize]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -67,7 +67,7 @@ const PagedMemoList = (props: Props) => {
|
|||||||
color="neutral"
|
color="neutral"
|
||||||
loading={state.isRequesting}
|
loading={state.isRequesting}
|
||||||
endDecorator={<ArrowDownIcon className="w-4 h-auto" />}
|
endDecorator={<ArrowDownIcon className="w-4 h-auto" />}
|
||||||
onClick={() => fetchMoreMemos()}
|
onClick={() => fetchMoreMemos(state.nextPageToken)}
|
||||||
>
|
>
|
||||||
{t("memo.load-more")}
|
{t("memo.load-more")}
|
||||||
</Button>
|
</Button>
|
||||||
|
Reference in New Issue
Block a user