-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient_search.go
More file actions
99 lines (87 loc) · 2.74 KB
/
client_search.go
File metadata and controls
99 lines (87 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package epo_ops
import (
"context"
"net/http"
"github.com/patent-dev/epo-ops/cql"
"github.com/patent-dev/epo-ops/generated"
)
//
// This file contains methods for searching patents using CQL queries.
// Search performs a bibliographic search using CQL (Contextual Query Language).
//
// Parameters:
// - query: CQL query string (e.g., "ti=plastic", "pa=Siemens and de")
// - rangeStr: Optional range in format "1-25" (default: "1-25")
//
// Returns the search results as XML containing matching patents.
//
// Example queries:
// - "ti=plastic" - Title contains "plastic"
// - "pa=Siemens" - Applicant is Siemens
// - "de" - Country code DE
// - "ti=plastic and pa=Siemens" - Combined search
//
// See OPS documentation for full CQL syntax.
func (c *Client) Search(ctx context.Context, query string, rangeStr string) (*SearchResultData, error) {
xmlData, err := c.SearchRaw(ctx, query, rangeStr)
if err != nil {
return nil, err
}
return ParseSearch(xmlData)
}
// SearchRaw performs a bibliographic search and returns raw XML.
// For parsed data, use Search() instead.
func (c *Client) SearchRaw(ctx context.Context, query string, rangeStr string) (string, error) {
// Validate CQL query
cqlQuery, err := cql.ParseCQL(query)
if err != nil {
return "", err
}
if err := cqlQuery.Validate(); err != nil {
return "", err
}
if rangeStr == "" {
rangeStr = "1-25"
}
params := &generated.PublishedDataKeywordsSearchWithoutConsituentsParams{
Q: query,
Range: &rangeStr,
}
return c.makeRequest(ctx, func() (*http.Response, error) {
return c.generated.PublishedDataKeywordsSearchWithoutConsituents(ctx, params)
})
}
// SearchWithConstituent performs a bibliographic search with specific constituent.
//
// Parameters:
// - constituent: The constituent to retrieve (e.g., "biblio", "abstract", "full-cycle")
// - query: CQL query string
// - rangeStr: Optional range in format "1-25"
//
// Returns parsed search results with the requested constituent data.
func (c *Client) SearchWithConstituent(ctx context.Context, constituent, query string, rangeStr string) (*SearchResultData, error) {
// Validate CQL query
cqlQuery, err := cql.ParseCQL(query)
if err != nil {
return nil, err
}
if err := cqlQuery.Validate(); err != nil {
return nil, err
}
if rangeStr == "" {
rangeStr = "1-25"
}
params := &generated.PublishedDataKeywordsSearchWithVariableConstituentsParams{
Q: query,
Range: &rangeStr,
}
xmlData, err := c.makeRequest(ctx, func() (*http.Response, error) {
return c.generated.PublishedDataKeywordsSearchWithVariableConstituents(ctx,
generated.PublishedDataKeywordsSearchWithVariableConstituentsParamsConstituent(constituent),
params)
})
if err != nil {
return nil, err
}
return ParseSearch(xmlData)
}