query

package
v0.0.0-...-d727afa Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: MIT Imports: 1 Imported by: 1

Documentation

Overview

Package query defines a structured builder for search query strings.

Example
package main

import (
	"fmt"

	"github.com/creachadair/twitter/query"
)

func main() {
	b := query.New()
	q := b.And(
		b.Or(
			b.All("red", "green", "blue"),
			b.Some("black", "white"),
		),
		b.HasImages(),
		b.Not(b.IsRetweet()),
		b.IsReply(),
	)

	fmt.Printf("Valid: %v\nQuery: %s\n", q.Valid(), q.String())
}
Output:

Valid: true
Query: ((red green blue) OR black OR white) has:images -is:retweet is:reply

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

type Builder struct{}

A Builder exports methods to construct query terms. A zero value is ready for use.

func New

func New() Builder

New returns a new query builder.

func (Builder) All

func (Builder) All(ss ...string) Query

All matches a conjunction of words, equivalent to And(Word(s) ...).

func (Builder) And

func (Builder) And(qs ...Query) Query

And matches the conjunction of the specified queries.

func (Builder) Entity

func (Builder) Entity(s string) Query

Entity matches tweets containing an entity with the given value.

func (Builder) From

func (Builder) From(s string) Query

From matches tweets from the specified user.

func (Builder) HasHashtags

func (Builder) HasHashtags() Query

HasHashtags matches tweets that contain at least one hashtag.

func (Builder) HasImages

func (Builder) HasImages() Query

HasImages matches tweets that contain a recognized image URL.

func (Builder) HasLinks() Query

HasLinks matches tweets that contain at least one link in its body.

func (Builder) HasMedia

func (Builder) HasMedia() Query

HasMedia matches tweets that contain a recognized media URL.

func (Builder) HasMentions

func (Builder) HasMentions() Query

HasMentions matches tweets that contain at least one mention.

func (Builder) HasVideos

func (Builder) HasVideos() Query

HasVideos matches tweets that contain "native" twitter videos. This does not include links to video on other sites.

func (Builder) Hashtag

func (Builder) Hashtag(s string) Query

Hashtag matches tweets that contain the specified hashtag.

func (Builder) InThread

func (Builder) InThread(s string) Query

InThread matches tweets with the specified conversation ID.

func (Builder) IsReply

func (Builder) IsReply() Query

IsReply matches only tweets that are replies (without specifying to whom).

func (Builder) IsRetweet

func (Builder) IsRetweet() Query

IsRetweet matches "natural" retweets (not quoted).

func (Builder) IsVerified

func (Builder) IsVerified() Query

IsVerified matches tweets whose authors are verified.

func (Builder) Lang

func (Builder) Lang(s string) Query

Lang matches tweets marked as being in the specified language. A tweet will have at most one language tag assigned.

func (Builder) Mention

func (Builder) Mention(s string) Query

Mention matches tweets that mention the specified username.

func (Builder) Not

func (Builder) Not(q Query) Query

Not matches the negation of the specified query.

func (Builder) Or

func (Builder) Or(qs ...Query) Query

Or matches the disjunction of the specified queries.

func (Builder) RetweetOf

func (Builder) RetweetOf(s string) Query

RetweetOf matches retweets of the specified user.

func (Builder) Some

func (Builder) Some(ss ...string) Query

Some matches a disjunction of words, equivalent to Or(Word(s) ...).

func (Builder) To

func (Builder) To(s string) Query

To matches tweets that reply to the specified user.

func (Builder) URL

func (Builder) URL(s string) Query

URL matches tweets that contain the specified URL. The match applies to both the plain and expanded URL.

func (Builder) Word

func (Builder) Word(s string) Query

Word converts a string into a keyword term. If s contains spaces it will be quoted.

type Query

type Query interface {
	// Query returns the query in string format.
	String() string

	// Valid reports whether the query is valid, meaning it contains at least
	// one standalone query term. A valid query may contain invalid subqueries.
	Valid() bool
}

A Query represents a query structure that can be rendered into a query string and checked for validity.

Jump to

Keyboard shortcuts

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