server

Restful json CherryPy server.

CherryPy and Lucene VM integration issues:
  • Monitors (such as autoreload) are not compatible with the VM unless threads are attached.
  • WorkerThreads must be also attached to the VM.
  • Recommended that the VM ignores keyboard interrupts (-Xrs) for clean server shutdown.

Usage: python server.py [index_directory ...]

Options:
-h, --help show this help message and exit
-r, --read-only
 expose only read methods; no write lock
-c CONFIG, --config=CONFIG
 optional configuration file or json object of global params
-p FILE, --pidfile=FILE
 store the process id in the given file
-d, --daemonize
 run the server as a daemon
--autoreload=SECONDS
 automatically reload modules; replacement for engine.autoreload
--autorefresh=SECONDS
 automatically refresh index

WebSearcher

class server.WebSearcher(*directories, **kwargs)

Dispatch root with a delegated Searcher.

docs(id=None, fields=None, multifields='')

Return ids or documents.

GET /docs

Return list of doc ids.

return:[int,... ]
GET /docs/int?

Return document mappings, optionally selected unique or multi-valued fields.

&fields=chars,...

&multifields=chars,...

return:{string: string|array,... }
index()

Return index information.

GET /

Return a mapping of the directory to the document count.

return:{string: int}
refresh(**caches)

Reopen searcher.

POST /refresh

search(q=None, count=None, start=0, fields=None, multifields='', sort=None, facets='', hl='', mlt=None, spellcheck=0, **options)

Run query and return documents.

GET /search?

Return list of document objects and total doc count.

&q=chars&q.chars=...,
query and optional parser settings: q.field, q.op,...
&count=int&start=0
maximum number of docs to return and offset to start at
&fields=chars,...
only include selected fields
&multifields=chars,...
multi-valued fields returned in an array
&sort=[-]chars[:chars],...
field name, optional type, minus sign indicates descending
&facets=chars,...
include facet counts for given field names; facets filters are cached
&hl=chars,... &hl.count=1&hl.tag=strong&hl.enable=[fields|terms]
stored fields to return highlighted
optional maximum fragment count and html tag name
optionally enable matching any field or any term
&mlt=int&mlt.fields=chars,... &mlt.chars=...,
doc index (or id without a query) to find MoreLikeThis
optional document fields to match
optional MoreLikeThis settings: mlt.minTermFreq, mlt.minDocFreq,...
&spellcheck=int
maximum number of spelling corrections to return for each query term, grouped by field
original query is still run; use q.spellcheck=true to affect query parsing
return:
{
“query”: string,
“count”: int,
“docs”: [{“__id__”: int, “__score__”: number, “__highlights__”: {string: array,... }, string: string|array,... },... ],
“facets”: {string: {string: int,... },... },
“spellcheck”: {string: {string: [string,... ],... },... },
}
terms(name='', value=':', docs='', counts='', **options)

Return data about indexed terms.

GET /terms?

Return field names, with optional selection.

&option=chars

return:[string,... ]
GET /terms/chars

Return term values for given field name.

return:[string,... ]
GET /terms/chars/chars[*|?|:chars|~float]

Return term values (wildcards, slices, or fuzzy terms) for given field name.

return:[string,... ]
GET /terms/chars/chars[*|~]?count=int

Return spellchecked term values ordered by decreasing document frequency. Prefixes (*) are optimized to be suitable for real-time query suggestions; all terms are cached.

return:[string,... ]
GET /terms/chars/chars

Return document count with given term.

return:int
GET /terms/chars/chars/docs

Return document ids with given term.

return:[int,... ]
GET /terms/chars/chars/docs/counts

Return document ids and frequency counts for given term.

return:[[int, int],... ]
GET /terms/chars/chars/docs/positions

Return document ids and positions for given term.

return:[[int, [int,... ]],... ]

WebIndexer

class server.WebIndexer(*args, **kwargs)

Bases: server.WebSearcher

Dispatch root which extends searcher to include write methods.

commit(**caches)

Commit write operations.

POST /commit

docs(id=None, fields=None, multifields='', docs='[], ')

Add or return documents. See WebSearcher.docs() for GET method.

POST /docs

Add documents to index.

docs=[{string: string|array,... },... ]

fields(name='', **params)

Return or store a field’s parameters.

GET /fields

Return known field names.

return:[string,... ]
GET, PUT /fields/chars

Set and return parameters for given field name.

store=chars

index=chars

termvector=chars

return:{“store”: string, “index”: string, “termvector”: string}
search(q=None, **options)

Run or delete a query. See WebSearcher.search() for GET method.

DELETE /search?q=chars
Delete documents which match query.

start

server.start(root, path='', config=None, pidfile='', daemonize=False, autoreload=0, autorefresh=0)
Attach root, subscribe to plugins, and start server. See cherrypy.quickstart and command-line options for documentation.

Table Of Contents

Previous topic

engine

Next topic

client

This Page