mirror of
https://github.com/icereed/paperless-gpt.git
synced 2025-03-14 05:38:01 -05:00
Tag query change (#44)
* Tag query change --------- Co-authored-by: Icereed <domi@icereed.net>
This commit is contained in:
parent
6d4683c9a3
commit
d1f23de5a6
2 changed files with 4 additions and 4 deletions
|
@ -108,10 +108,10 @@ func (c *PaperlessClient) GetAllTags(ctx context.Context) (map[string]int, error
|
||||||
func (c *PaperlessClient) GetDocumentsByTags(ctx context.Context, tags []string) ([]Document, error) {
|
func (c *PaperlessClient) GetDocumentsByTags(ctx context.Context, tags []string) ([]Document, error) {
|
||||||
tagQueries := make([]string, len(tags))
|
tagQueries := make([]string, len(tags))
|
||||||
for i, tag := range tags {
|
for i, tag := range tags {
|
||||||
tagQueries[i] = fmt.Sprintf("tag:%s", tag)
|
tagQueries[i] = fmt.Sprintf("tags__name__iexact=%s", tag)
|
||||||
}
|
}
|
||||||
searchQuery := strings.Join(tagQueries, " ")
|
searchQuery := strings.Join(tagQueries, "&")
|
||||||
path := fmt.Sprintf("api/documents/?query=%s", urlEncode(searchQuery))
|
path := fmt.Sprintf("api/documents/?%s", urlEncode(searchQuery))
|
||||||
|
|
||||||
resp, err := c.Do(ctx, "GET", path, nil)
|
resp, err := c.Do(ctx, "GET", path, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -203,7 +203,7 @@ func TestGetDocumentsByTags(t *testing.T) {
|
||||||
// Set mock responses
|
// Set mock responses
|
||||||
env.setMockResponse("/api/documents/", func(w http.ResponseWriter, r *http.Request) {
|
env.setMockResponse("/api/documents/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
// Verify query parameters
|
// Verify query parameters
|
||||||
expectedQuery := "query=tag:tag1+tag:tag2"
|
expectedQuery := "tags__name__iexact=tag1&tags__name__iexact=tag2"
|
||||||
assert.Equal(t, expectedQuery, r.URL.RawQuery)
|
assert.Equal(t, expectedQuery, r.URL.RawQuery)
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(documentsResponse)
|
json.NewEncoder(w).Encode(documentsResponse)
|
||||||
|
|
Loading…
Reference in a new issue