parsesearch

package module
v0.0.0-...-6be8c77 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2015 License: MIT Imports: 18 Imported by: 1

README

parsesearch

Deploy

This project shows example use of Cloud Code Webhooks to implement full text search for Parse objects.

Actual use will likey involve customizations.

Getting Started

The easiest way to get started is by using the 'Deploy to Heroku' button above to start running this project in a new Heroku dyno.

You will be prompted for your Parse Application's keys and the Parse Class you would like to index.

To auto-create the necessary triggers and webhook functions you must set the dyno url as an environment variable for your dyno.

After your app deploys successfully configure the endpoint URL like so:

  • Manage App -> Settings -> Reveal Config Vars

Add a new environment variable named 'URL' and set its value to the URL of the Heroku dyno.

For example, you would set it to a string of the form 'https://DYNO_NAME_HERE.herokuapp.com/'

The dyno will restart and register the appropriate webhooks in your Parse app. You can confirm this by looking at your Webhooks page in the Parse web interface. If you set this to the incorrect value at first remove the webhooks in the Parse web interface and restart your dyno.

Querying

parsesearch installs a webhook called 'search'

You can test a search by curling your Cloud Code Webhook like so:

$ curl -X POST https://${PARSE_APPLICATION_ID}:javascript-key:${PARSE_JAVASCRIPT_KEY}@api.parse.com/1/functions/search -d '{"q":"hello"}' 
{"result":["gKCRJ0tzgA","yWpBOZj4UB"]}

How it works

On startup parsesearch iterates over all the objects in your specified class and indexes them (their full JSON representation). It registers an afterSave and afterDelete triggers to maintain the index.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Indexer

type Indexer struct {
	// contains filtered or unexported fields
}

Indexer manages the search index for a Parse app.

func NewIndexer

func NewIndexer(webhookKey, masterKey, appID string) (*Indexer, error)

NewIndexer prepares a new Indexer given the necessary Parse App credentials.

func (*Indexer) Index

func (i *Indexer) Index(w http.ResponseWriter, r *http.Request)

Index is an http.HandlerFunc that accepts a parse afterSave webhook request.

It adds or updates the provided objet in the search index.

func (*Indexer) IndexStatus

func (i *Indexer) IndexStatus(w http.ResponseWriter, r *http.Request)

IndexStatus lists the status of all current Reindexing processes.

func (*Indexer) RegisterHooks

func (i *Indexer) RegisterHooks(className string) error

RegisterHooks auto-registers the search service with a Parse Application.

func (*Indexer) Reindex

func (i *Indexer) Reindex(className string) error

Reindex fetches all objects for a class and indexes them. Could be long-running.

func (*Indexer) Search

func (i *Indexer) Search(w http.ResponseWriter, r *http.Request)

Search is an http.HandlerFunc that accepts a Parse Cloud Code Webhook request.

The expected query parameter is 'q'

func (*Indexer) Unindex

func (i *Indexer) Unindex(w http.ResponseWriter, r *http.Request)

Unindex is an http.HandlerFunc that accepts a parse afterDelete webhook request.

It removes the provided object from the index.

type Response

type Response struct {
	Error   interface{} `json:"error,omitempty"`
	Success interface{} `json:"success,omitempty"`
}

Response is a Parse Cloud Code Webhook response

type UI

type UI struct {
	ClassName     string
	JavascriptKey string
	AppID         string
}

func NewUI

func NewUI(appID, javascriptKey, className string) (*UI, error)

func (*UI) ServeHTTP

func (ui *UI) ServeHTTP(w http.ResponseWriter, r *http.Request)

type WebhookRequest

type WebhookRequest struct {
	InstallationID string                 `json:"installationId,omitempty"`
	Master         bool                   `json:"master,omitempty"`
	Object         interface{}            `json:"object,omitempty"`
	Params         map[string]interface{} `json:"params,omitempty"`
	TriggerName    string                 `json:"triggerName,omitempty"`
}

WebhookRequest is a Parse Cloud Code Webhook request.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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