query

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package query provides a query parser and validator for DPMAregister expert search syntax.

DPMAregister uses an expert search syntax with field codes like TI=Elektrofahrzeug, Boolean operators (AND/UND, OR/ODER, NOT/NICHT), comparison operators (=, >=, <=, >, <), wildcards (? any chars, ! one char, # one or no char), quoted values, and parentheses.

Procedure data searches use curly braces: {VST=pub-offenlegungschrift UND VSTT=05.01.2011}

Each DPMA service (Patent, Design, Trademark) supports different field codes. Use ParseQuery to parse and validate queries, optionally scoped to a specific service.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetValidFields

func GetValidFields(svc Service) []string

GetValidFields returns all valid field codes for a service. If service is ServiceAny, returns fields from all services (deduplicated).

func IsValidField

func IsValidField(field string, svc Service) bool

IsValidField checks if a field code is valid for the given service. If service is ServiceAny, the field is checked against all services.

func IsValidOperator

func IsValidOperator(op string) bool

IsValidOperator checks if a string is a recognized Boolean operator. Matching is case-insensitive: "AND", "and", and "And" are all recognized.

Types

type Field

type Field struct {
	// Code is the field abbreviation used in queries (e.g. "TI", "INH").
	Code string

	// Name is the German field name (e.g. "Bezeichnung/Titel").
	Name string

	// Description is a brief English description.
	Description string

	// Input is the expected input type (text or date).
	Input InputType

	// Services lists which services support this field.
	Services []Service
}

Field describes a DPMAregister search field.

func GetField

func GetField(code string, svc Service) (Field, bool)

GetField returns the field definition for a code and service. Returns the Field and true if found, or zero value and false if not.

type InputType

type InputType string

InputType describes the expected input format for a field.

const (
	InputText InputType = "text"
	InputDate InputType = "date" // dd.mm.yyyy format
)

InputType constants for DPMAregister field input formats.

type Query

type Query struct {
	// Raw is the original query string.
	Raw string

	// Tokens is the parsed token stream.
	Tokens []Token

	// Valid indicates whether the query passed validation.
	Valid bool

	// Errors contains any validation errors.
	Errors []string

	// Service is the service context used for field validation.
	Service Service
}

Query represents a parsed DPMAregister expert search query.

func ParseQuery

func ParseQuery(queryStr string, service Service) (*Query, error)

ParseQuery parses a DPMAregister expert search query string and returns a Query with tokens and validation results.

If service is not ServiceAny, field names are validated against that service's known field codes.

Example queries:

  • "TI=Elektrofahrzeug"
  • "TI=Elektrofahrzeug AND INH=Siemens"
  • "(TI=Motor OR TI=Antrieb) AND IC=H02K?"
  • "INH=\"München\" AND AT>=01.01.2024"
  • "{VST=pub-offenlegungschrift UND VSTT=05.01.2011}"
  • "MARKE=?brain?"
  • "exists INH"

func (*Query) GetFields

func (q *Query) GetFields() []string

GetFields returns all unique field codes used in the query.

func (*Query) HasField

func (q *Query) HasField(field string) bool

HasField checks if the query references a specific field code.

func (*Query) String

func (q *Query) String() string

String returns the raw query string.

func (*Query) TokenCount

func (q *Query) TokenCount() int

TokenCount returns the number of tokens in the parsed query.

func (*Query) Validate

func (q *Query) Validate() error

Validate returns an error if the query is invalid, or nil if valid.

type Service

type Service string

Service represents a DPMAregister service type for field validation.

const (
	// ServicePatent validates against patent and utility model fields (Schutzrechtsart P, G).
	ServicePatent Service = "patent"

	// ServiceDesign validates against design fields (Schutzrechtsart G for Geschmacksmuster).
	ServiceDesign Service = "design"

	// ServiceTrademark validates against trademark fields (Marke).
	ServiceTrademark Service = "trademark"

	// ServiceAny accepts fields from any service (no service-specific validation).
	ServiceAny Service = ""
)

type Token

type Token struct {
	Type  TokenType
	Value string
	Pos   int
}

Token represents a token in a DPMAregister query.

type TokenType

type TokenType int

TokenType represents the type of a query token.

const (
	TokenField      TokenType = iota // Field name (before =)
	TokenOperator                    // Boolean operator (AND, OR, NOT, UND, ODER, NICHT)
	TokenValue                       // Search value
	TokenEquals                      // Comparison operator (=, >=, <=, >, <)
	TokenLParen                      // (
	TokenRParen                      // )
	TokenLBrace                      // { (procedure data)
	TokenRBrace                      // } (procedure data)
	TokenQuote                       // "
	TokenWhitespace                  // Whitespace (stripped during tokenization)
	TokenUnknown                     // Unrecognized
)

TokenType constants for DPMAregister query tokens.

func (TokenType) String

func (t TokenType) String() string

String returns a human-readable name for a token type.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL