Exemplo n.º 1
0
def build_sphinx_data(settings, quiet=True):
    sphinx_dst = settings['sphinx_build']
    if not os.path.exists(sphinx_dst):
        os.makedirs(sphinx_dst)
    sphinx = WebSupport(srcdir=settings['sphinx_src'], builddir=sphinx_dst,
                        status=None)
    sphinx.build()
def search_adapter_helper(adapter):
    settings = {'srcdir': rootdir / 'root',
                'builddir': tempdir / 'websupport',
                'status': StringIO(),
                'warning': StringIO(),
                'search': adapter}
    support = WebSupport(**settings)
    support.build()

    s = support.search

    # Test the adapters query method. A search for "Epigraph" should return
    # one result.
    results = s.query(u'Epigraph')
    assert len(results) == 1, \
        '%s search adapter returned %s search result(s), should have been 1'\
        % (adapter, len(results))

    # Make sure documents are properly updated by the search adapter.
    s.init_indexing(changed=['markup'])
    s.add_document(u'markup', u'title', u'SomeLongRandomWord')
    s.finish_indexing()
    # Now a search for "Epigraph" should return zero results.
    results = s.query(u'Epigraph')
    assert len(results) == 0, \
        '%s search adapter returned %s search result(s), should have been 0'\
        % (adapter, len(results))
    # A search for "SomeLongRandomWord" should return one result.
    results = s.query(u'SomeLongRandomWord')
    assert len(results) == 1, \
        '%s search adapter returned %s search result(s), should have been 1'\
        % (adapter, len(results))
    # Make sure it works through the WebSupport API
    support.get_search_results(u'SomeLongRandomWord')
Exemplo n.º 3
0
def search_adapter_helper(adapter):
    settings = {'srcdir': rootdir / 'roots' / 'test-searchadapters',
                'builddir': tempdir / 'websupport',
                'status': StringIO(),
                'warning': StringIO(),
                'search': adapter}
    support = WebSupport(**settings)
    support.build()

    s = support.search

    # Test the adapters query method. A search for "Epigraph" should return
    # one result.
    results = s.query(u'Epigraph')
    assert len(results) == 1, \
        '%s search adapter returned %s search result(s), should have been 1'\
        % (adapter, len(results))

    # Make sure documents are properly updated by the search adapter.
    s.init_indexing(changed=['markup'])
    s.add_document(u'markup', u'filename', u'title', u'SomeLongRandomWord')
    s.finish_indexing()
    # Now a search for "Epigraph" should return zero results.
    results = s.query(u'Epigraph')
    assert len(results) == 0, \
        '%s search adapter returned %s search result(s), should have been 0'\
        % (adapter, len(results))
    # A search for "SomeLongRandomWord" should return one result.
    results = s.query(u'SomeLongRandomWord')
    assert len(results) == 1, \
        '%s search adapter returned %s search result(s), should have been 1'\
        % (adapter, len(results))
    # Make sure it works through the WebSupport API
    support.get_search_results(u'SomeLongRandomWord')
Exemplo n.º 4
0
def main():
    init_db()

    support = WebSupport(srcdir=app.config['SOURCE_DIR'],
                         builddir=app.config['BUILD_DIR'],
                         search=app.config['SEARCH'],
                         storage=app.config['DATABASE_URI'])
    support.build()
Exemplo n.º 5
0
def docs_build():
    """创建文档"""

    docs_dir = current_app.config['DOCS_DIR']
    from os.path import join
    support = WebSupport(srcdir=docs_dir,
                         builddir=docs_dir,
                         staticroot='docs/static')
    support.build()
Exemplo n.º 6
0
def test_build(request, rootdir, sphinx_test_tempdir):
    settings = {
        'srcdir': rootdir / 'test-basic',
        # to use same directory for 'builddir' in each 'support' fixture, using
        # 'sphinx_test_tempdir' (static) value instead of 'tempdir' fixture value.
        # each test expect result of db value at previous test case.
        'builddir': sphinx_test_tempdir / 'websupport'
    }
    marker = request.node.get_marker('support')
    if marker:
        settings.update(marker.kwargs)

    support = WebSupport(**settings)
    support.build()
Exemplo n.º 7
0
def test_build(request, rootdir, sphinx_test_tempdir):
    settings = {
        'srcdir': rootdir / 'test-basic',
        # to use same directory for 'builddir' in each 'support' fixture, using
        # 'sphinx_test_tempdir' (static) value instead of 'tempdir' fixture value.
        # each test expect result of db value at previous test case.
        'builddir': sphinx_test_tempdir / 'websupport'
    }
    marker = request.node.get_marker('support')
    if marker:
        settings.update(marker.kwargs)

    support = WebSupport(**settings)
    support.build()
Exemplo n.º 8
0
def search_adapter_helper(adapter):
    settings = {
        "srcdir": rootdir / "root",
        "builddir": tempdir / "websupport",
        "status": StringIO(),
        "warning": StringIO(),
        "search": adapter,
    }
    support = WebSupport(**settings)
    support.build()

    s = support.search

    # Test the adapters query method. A search for "Epigraph" should return
    # one result.
    results = s.query(u"Epigraph")
    assert len(results) == 1, "%s search adapter returned %s search result(s), should have been 1" % (
        adapter,
        len(results),
    )

    # Make sure documents are properly updated by the search adapter.
    s.init_indexing(changed=["markup"])
    s.add_document(u"markup", u"title", u"SomeLongRandomWord")
    s.finish_indexing()
    # Now a search for "Epigraph" should return zero results.
    results = s.query(u"Epigraph")
    assert len(results) == 0, "%s search adapter returned %s search result(s), should have been 0" % (
        adapter,
        len(results),
    )
    # A search for "SomeLongRandomWord" should return one result.
    results = s.query(u"SomeLongRandomWord")
    assert len(results) == 1, "%s search adapter returned %s search result(s), should have been 1" % (
        adapter,
        len(results),
    )
    # Make sure it works through the WebSupport API
    support.get_search_results(u"SomeLongRandomWord")
Exemplo n.º 9
0
from sphinx.websupport import WebSupport

import os

ROOT = os.path.dirname(os.path.abspath(__file__))
SRCDIR = os.path.join(ROOT, '.')
BUILDDIR = os.path.join(ROOT, '_build')
INDEXDIR = os.path.join(BUILDDIR, "data", "db")


support = WebSupport(srcdir=SRCDIR,
                     builddir=BUILDDIR)

support.build()

#from sphinx.websupport.errors import *

#@app.route('/<path:docname>')
#def doc(docname):
    #username = g.user.name if g.user else ''
    #moderator = g.user.moderator if g.user else False
    #try:
        #document = support.get_document(docname, username, moderator)
    #except DocumentNotFoundError:
        #abort(404)
    #return render_template('doc.html', document=document)


#@app.route('/search')
#def search():
    #q = request.args.get('q')
from sphinx.websupport import WebSupport
from sphinx.websupport.errors import DocumentNotFoundError
from sphinx.websupport.search import whooshsearch
from sphinx.websupport.storage.sqlalchemystorage import SQLAlchemyStorage

from whoosh.fields import Schema, ID, TEXT, NGRAM

import os

ROOT = os.path.dirname(os.path.abspath(__file__))
SRCDIR = os.path.join(ROOT, 'source')
BUILDDIR = os.path.join(ROOT, 'build', 'web')
INDEXDIR = os.path.join(BUILDDIR, "data", "db")

uri = os.environ.get('DATABASE_URL')  # DATABSE_URL is given
storage = SQLAlchemyStorage(uri)

whoosh = whooshsearch.WhooshSearch
whoosh.schema = Schema(path=ID(stored=True, unique=True),
                       title=TEXT(field_boost=2.0, stored=True),
                       text=NGRAM(stored=True))

search = whoosh(INDEXDIR)

support = WebSupport(srcdir=SRCDIR,
                     builddir=BUILDDIR,
                     search=search,
                     storage=storage)
support.build()