Created
December 22, 2011 15:43
-
-
Save shirou/1510730 to your computer and use it in GitHub Desktop.
sphinx websupport with NGRAM schema
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sphinx.websupport import WebSupport | |
from sphinx.websupport.errors import DocumentNotFoundError | |
from sphinx.websupport.search import whooshsearch | |
from whoosh.fields import Schema, ID, TEXT, NGRAM | |
import os | |
import shutil | |
ROOT = '/absoulte/path/to/sampledoc' | |
SRCDIR = ROOT + '/source/' | |
BUILDDIR = ROOT +'/build/web' | |
INDEXDIR = os.path.join(BUILDDIR, "data", "db") | |
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) # make the instance | |
support = WebSupport(SRCDIR, BUILDDIR, search=search) | |
support.build() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### sphinx part. same as build.py | |
from sphinx.websupport import WebSupport | |
from sphinx.websupport.errors import DocumentNotFoundError | |
from sphinx.websupport.search import whooshsearch | |
from whoosh.fields import Schema, ID, TEXT, NGRAM | |
import os | |
ROOT = '/absoulte/path/to/sampledoc' | |
SRCDIR = ROOT + '/source/' | |
BUILDDIR = ROOT +'/build/web' | |
INDEXDIR = os.path.join(BUILDDIR, "data", "db") | |
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, BUILDDIR, search=search) | |
support.build() | |
#### flask part | |
from flask import Flask, render_template, abort, g, request, jsonify | |
from jinja2 import Environment, FileSystemLoader | |
app = Flask(__name__) | |
# app.debug = True # | |
## あとは省略… |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment