示例#1
0
def test_start(tempdir, servers):
    "Server run options."
    port = servers.ports[0]
    pidfile = os.path.join(tempdir, 'pid')
    servers.start(port, '-dp', pidfile)
    time.sleep(1)
    os.kill(int(open(pidfile).read()), signal.SIGTERM)
    del servers[port]
    assert subprocess.call((sys.executable, '-m', 'lupyne.server', '-c', __file__), stderr=subprocess.PIPE)
    assert subprocess.call((sys.executable, 'lupyne/server.py', '-x'), env={'PYTHONPATH': '.'}, stderr=subprocess.PIPE) == 2
    assert cherrypy.tree.mount(None)
    server.init(vmargs=None)
    with pytest.raises(AttributeError):
        server.start(config=True)
示例#2
0
def test_start(tempdir, servers):
    port = servers.ports[0]
    pidfile = os.path.join(tempdir, 'pid')
    servers.start(port, '-dp', pidfile)
    time.sleep(1)
    os.kill(int(open(pidfile).read()), signal.SIGTERM)
    del servers[port]
    assert subprocess.call(
        (sys.executable, '-m', 'lupyne.server', '-c', __file__),
        stderr=subprocess.PIPE)
    assert cherrypy.tree.mount(None)
    server.init(vmargs=None)
    with pytest.raises(AttributeError):
        server.start(config=True)
示例#3
0
"""

import lucene
from lupyne import engine, server
from tests import conftest

Q = engine.Query

if __name__ == '__main__':
    assert lucene.getVMEnv() or lucene.initVM(vmargs='-Xrs')
    root = server.WebIndexer()
    # assign field settings
    root.indexer.set('amendment', engine.Field.String, stored=True)
    root.indexer.set('date',
                     engine.Field.String,
                     stored=True,
                     docValuesType='sorted')
    root.indexer.set('text', engine.Field.Text)
    # populate index
    for doc in conftest.constitution.__wrapped__():
        if 'amendment' in doc:
            root.indexer.add(amendment=doc['amendment'],
                             date=doc['date'],
                             text=doc['text'])
    root.update()
    # assign custom facet queries based on year
    years = {date.split('-')[0] for date in root.searcher.terms('date')}
    root.query_map['year'] = {year: Q.prefix('date', year) for year in years}
    # start server
    server.start(root)
示例#4
0
文件: server.py 项目: prepor/lupyne
Example queries:
 * http://localhost:8080/search?q=date:17*&group=year
 * http://localhost:8080/search?q=date:17*&group=year&sort=-year
 * http://localhost:8080/search?count=0&facets=year
 * http://localhost:8080/search?q=text:right&count=3&facets=year
"""

import os
import lucene
from lupyne import engine, server
from test import fixture

if __name__ == '__main__':
    lucene.initVM(vmargs='-Xrs')
    root = server.WebIndexer()
    # assign field settings
    root.indexer.set('amendment', store=True, index=True)
    root.indexer.set('date', store=True, index=True)
    root.indexer.set('text')
    # populate index
    for doc in fixture.constitution.docs():
        if 'amendment' in doc:
            root.indexer.add(doc)
    root.update()
    # assign custom filter and sorter based on year
    root.searcher.sorters['year'] = engine.SortField('date', int, lambda date: int(date.split('-')[0]))
    years = set(date.split('-')[0] for date in root.searcher.terms('date'))
    root.searcher.filters['year'] = dict((year, engine.Query.prefix('date', year).filter()) for year in years)
    # start with pretty-printing
    server.start(root, config={'global': {'tools.json.indent': 2}})