search

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package search parses GitHub's search query mini-language into the structured form the domain resolves and the store filters on. It is pure: it touches no store, no git, and no HTTP, so the same raw query string always parses to the same Query. The domain layer turns the parsed qualifiers into store filters (resolving logins and repo names to ids); this package only tokenizes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NormalizeOrder

func NormalizeOrder(order string) string

NormalizeOrder maps a direction query parameter to "asc" or "desc", defaulting to descending, which is GitHub's default for every sort.

func Score

func Score() float64

Score is the relevance value attached to a result item. The portable-scan backend does not rank, so every match scores the same 1.0; the field exists so the wire shape carries GitHub's score and a ranking backend can fill it without a contract change.

Types

type Field

type Field int

Field is a target a free-text term matches against. The in: qualifier selects it; with no in: qualifier a term matches the default fields for the search kind (title and body for issues, name and description for repositories).

const (
	FieldTitle Field = iota
	FieldBody
	FieldComments
)

The fields a term can match: an issue's title or body, or its comment text.

func Fields

func Fields(q Query, def ...Field) []Field

Fields reads the in: qualifiers into the set of fields a term must match, falling back to def when none are given. An unrecognized in: value is ignored, the way GitHub drops a qualifier value it does not understand.

type Query

type Query struct {
	Terms      []string
	Qualifiers map[string][]string
}

Query is a parsed search string: the free-text terms a result must contain and the qualifier:value pairs that narrow the set. A qualifier may repeat (label:bug label:urgent), so its values are a slice. Keys are lowercased; the values keep their original case because logins and repo names are matched case-insensitively downstream but rendered as written.

func Parse

func Parse(raw string) Query

Parse splits a raw search string into terms and qualifiers. A token shaped key:value whose key is a recognized qualifier becomes a qualifier; every other token is a free-text term. Double quotes group spaces into one token, so `label:"help wanted"` and `"exact phrase"` parse as a single value or term. An unterminated quote runs to the end of the string, matching how GitHub tolerates a trailing quote.

func (Query) First

func (q Query) First(key string) (string, bool)

First returns the first value of a qualifier and whether it was present.

func (Query) Text

func (q Query) Text() string

Text joins the free-text terms back into a single space-separated string, the form a free-text-only backend wants.

func (Query) Values

func (q Query) Values(key string) []string

Values returns every value given for a qualifier, in query order.

Jump to

Keyboard shortcuts

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