# encoding: utf-8
import json
import os
import re
import shutil
import threading
import warnings
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.utils.datetime_safe import date, datetime
from django.utils.encoding import force_str
from haystack.backends import (
BaseEngine,
BaseSearchBackend,
BaseSearchQuery,
EmptyResults,
log_query,
)
from haystack.constants import (
DJANGO_CT,
DJANGO_ID,
FUZZY_WHOOSH_MAX_EDITS,
FUZZY_WHOOSH_MIN_PREFIX,
ID,
)
from haystack.exceptions import MissingDependency, SearchBackendError, SkipDocument
from haystack.inputs import Clean, Exact, PythonData, Raw
from haystack.models import SearchResult
from haystack.utils import get_identifier, get_model_ct
from haystack.utils import log as logging
from haystack.utils.app_loading import haystack_get_model
from jieba.analyse import ChineseAnalyzer
try:
import whoosh
except ImportError:
raise MissingDependency(
"The 'whoosh' backend requires the installation of 'Whoosh'. Please refer to the documentation."
)
# Handle minimum requirement.
if not hasattr(whoosh, "__version__") or whoosh.__version__ < (2, 5, 0):
raise MissingDependency("The 'whoosh' backend requires version 2.5.0 or greater.")
# Bubble up the correct error.
from whoosh import index
from whoosh.analysis import StemmingAnalyzer
from whoosh.fields import BOOLEAN, DATETIME
from whoosh.fields import ID as WHOOSH_ID
from whoosh.fields import IDLIST, KEYWORD, NGRAM, NGRAMWORDS, NUMERIC, TEXT, Schema
from whoosh.filedb.filestore import FileStorage, RamStorage
from whoosh.highlight import ContextFragmenter, HtmlFormatter
from whoosh.highlight import highlight as whoosh_highlight
from whoosh.qparser import FuzzyTermPlugin, QueryParser
from whoosh.searching import ResultsPage
from whoosh.sorting import Count, DateRangeFacet, FieldFacet
from whoosh.support.relativedelta import relativedelta as RelativeDelta
from whoosh.writing import AsyncWriter
DATETIME_REGEX = re.compile(
r"^(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})T(?P<hour>\d{2}):(?P<minute>\d{2}):(?P<second>\d{2})(\.\d{3,6}Z?)?$"
)
LOCALS = threading.local()
LOCALS.RAM_STORE = None
class WhooshHtmlFormatter(HtmlFormatter):
"""
This is a HtmlFormatter simpler than the whoosh.HtmlFormatter.
We use it to have consistent results across backends. Specifically,
Solr, Xapian and Elasticsearch are using this formatting.
"""
template = "<%(tag)s>%(t)s</%(tag)s>"
class WhooshSearchBackend(BaseSearchBackend):
# Word reserved by Whoosh for special use.
RESERVED_WORDS = ("AND", "NOT", "OR", "TO")
# Characters reserved by Whoosh for special use.
# The '\\' must come first, so as not to overwrite the other slash replacements.
RESERVED_CHARACTERS = (
"\\",
"+",
"-",
"&&",
"||",
"!",
"(",
")",
"{",
"}",
"[",
"]",
"^",
'"',
"~",
"*",
"?",
":",
".",
)
def __init__(self, connection_alias, **connection_options):
super().__init__(connection_alias, **connection_options)
self.setup_complete = False
self.use_file_storage = True
self.post_limit = getattr(connection_options, "POST_LIMIT", 128 * 1024 * 1024)
self.path = connection_options.get("PATH")
if connection_options.get("STORAGE", "file") != "file":
self.use_file_storage = False
if self.use_file_storage and not self.path:
raise ImproperlyConfigured(
"You must specify a 'PATH' in your settings for connection '%s'."
% connection_alias
)
self.log = logging.getLogger("haystack")
def setup(self):
"""
Defers loading until needed.
"""
from haystack import connections
new_index = False
# Make sure the index is there.
if self.use_file_storage and not os.path.exists(self.path):
os.makedirs(self.path)
new_index = True
if self.use_file_storage and not os.access(self.path, os.W_OK):
raise IOError(
"The path to your Whoosh index '%s' is not writable for the current user/group."
% self.path
)
if self.use_file_storage:
self.storage = FileStorage(self.path)
else:
global LOCALS
if getattr(LOCALS, "RAM_STORE", None) is None:
LOCALS.RAM_STORE = RamStorage()
self.storage = LOCALS.RAM_STORE
self.content_field_name, self.schema = self.build_schema(
connections[self.connection_alias].get_unified_index().all_searchfields()
)
self.parser = QueryParser(self.content_field_name, schema=self.schema)
self.parser.add_plugins([FuzzyTermPlugin])
if new_index is True:
self.index = self.storage.create_index(self.schema)
else:
try:
self.index = self.storage.open_index(schema=self.schema)
except index.EmptyIndexError:
self.index = self.storage.create_index(self.schema)
self.setup_complete = True
def build_schema(self, fields):
schema_fields = {
ID: WHOOSH_ID(stored=True, unique=True),
DJANGO_CT: WHOOSH_ID(stored=True),
DJANGO_ID: WHOOSH_ID(stored=True),
}
# Grab the number of keys that are hard-coded into Haystack.
# We'll use this to (possibly) fail slightly more gracefully later.
initial_key_count = len(schema_fields)
content_field_name = ""
for _, field_class in fields.items():
if field_class.is_multivalued:
if field_class.indexed is False:
schema_fields[field_class.index_fieldname] = IDLIST(
stored=True, analyzer=ChineseAnalyzer(), field_boost=field_class.boost, sortable=True
)
else:
schema_fields[field_class.index_fieldname] = KEYWORD(
stored=True,
commas=True,
scorable=True,
field_boost=field_class.boost,
)
elif field_class.field_type in ["date", "datetime"]:
schema_fields[field_class.index_fieldname] = DATETIME(
stored=field_class.stored, sortable=True
)
elif field_class.field_type == "integer":
schema_fields[field_class.index_fieldname] = NUMERIC(
stored=field_class.stored,
numtype=int,
field_boost=field_class.boost,
)
elif field_class.field_type == "float":
schema_fields[field_class.index_fieldname] = NUMERIC(
stored=field_class.stored,
numtype=float,
field_boost=field_class.boost,
)
elif field_class.field_type == "boolean":
# Field boost isn't supported on BOOLEAN as of 1.8.2.
schema_fields[field_class.index_fieldname] = BOOLEAN(
stored=field_class.stored
)
elif field_class.field_type == "ngram":
schema_fields[field_class.index_fieldname] = NGRAM(
minsize=3,
maxsize=15,
stored=field_class.stored,
field_boost=field_class.boost,
)
elif field_class.field_type == "edge_ngram":
schema_fields[field_class.index_fieldname] = NGRAMWORDS(
minsize=2,
maxsize=15,
at="start",
stored=field_class.stored,
field_boost=field_c
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【资源说明】 数据库课程设计基于Django框架开发的论坛系统源码.zip数据库课程设计基于Django框架开发的论坛系统源码.zip数据库课程设计基于Django框架开发的论坛系统源码.zip数据库课程设计基于Django框架开发的论坛系统源码.zip数据库课程设计基于Django框架开发的论坛系统源码.zip数据库课程设计基于Django框架开发的论坛系统源码.zip数据库课程设计基于Django框架开发的论坛系统源码.zip数据库课程设计基于Django框架开发的论坛系统源码.zip 数据库课程设计基于Django框架开发的论坛系统源码.zip 数据库课程设计基于Django框架开发的论坛系统源码.zip 【备注】 1、该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的,请放心下载使用!有问题请及时沟通交流。 2、适用人群:计算机相关专业(如计科、信息安全、数据科学与大数据技术、人工智能、通信、物联网、自动化、电子信息等)在校学生、专业老师或者企业员工下载使用。 3、用途:项目具有较高的学习借鉴价值,不仅适用于小白学习入门进阶。也可作为毕设项目、课程设计、大作业、初期项目立项演示等。 4、如果基础还行,或热爱钻研,亦可在此项目代码基础上进行修改添加,实现其他不同功能。 欢迎下载,沟通交流,互相学习,共同进步!
资源推荐
资源详情
资源评论
收起资源包目录
数据库课程设计基于Django框架开发的论坛系统源码.zip (548个子文件)
activate 2KB
config.js.bak 2KB
post_detail.css.bak 930B
activate.bat 581B
deactivate.bat 347B
pyvenv.cfg 92B
bootstrap.min.css 114KB
bootstrap.min.css 106KB
style_21_common.css 91KB
samples.css 64KB
style_21_forum_viewthread.css 45KB
editor_ie7.css 43KB
editor_iequirks.css 42KB
editor_ie8.css 42KB
editor_ie.css 41KB
editor_gecko.css 40KB
editor.css 40KB
bootstrap-responsive.min.css 16KB
dialog_ie7.css 15KB
dialog_ie8.css 14KB
dialog_iequirks.css 14KB
dialog_ie.css 14KB
dialog.css 13KB
style_21_forum_index.css 9KB
codemirror.css 8KB
sample.css 5KB
style_21_forum_moderator.css 3KB
jquery.Jcrop.min.css 2KB
outputxhtml.css 2KB
contents.css 2KB
fontello.css 2KB
templates.css 1KB
toolbar.css 1KB
blogstyle.css 1KB
wsc.css 1KB
post_detail.css 917B
neo.css 815B
show-hint.css 662B
style.css 234B
python36.dll 3.44MB
fontello.eot 5KB
python.exe 98KB
pythonw.exe 97KB
outputforflash.fla 84KB
spinner.gif 3KB
angel_smile.gif 1KB
devil_smile.gif 1KB
shades_smile.gif 1KB
angry_smile.gif 1KB
tongue_smile.gif 1KB
tounge_smile.gif 1KB
regular_smile.gif 1KB
wink_smile.gif 1KB
confused_smile.gif 1KB
teeth_smile.gif 1KB
omg_smile.gif 820B
cry_smile.gif 795B
embarrassed_smile.gif 786B
embaressed_smile.gif 786B
sad_smile.gif 782B
whatchutalkingabout_smile.gif 775B
broken_heart.gif 732B
thumbs_down.gif 715B
thumbs_up.gif 714B
heart.gif 692B
kiss.gif 683B
lightbulb.gif 660B
envelope.gif 506B
template3.gif 422B
template1.gif 375B
template2.gif 333B
image-20211029204419-1_thumb.gif 285B
hiddenfield.gif 178B
pagebreak.gif 99B
image-20211029204419-1.gif 70B
datafiltering.html 46KB
index.html 15KB
base.html 11KB
inlineall.html 10KB
outputforflash.html 10KB
toolbar.html 8KB
magicline.html 8KB
fullpage.html 8KB
jquery.html 7KB
detail.html 7KB
dialog.html 7KB
outputhtml.html 7KB
api.html 7KB
base_old.html 7KB
replacebyclass.html 7KB
replacebycode.html 7KB
xhtmlstyle.html 7KB
index.html 6KB
inlinebycode.html 6KB
index.html 6KB
registe.html 5KB
inlinetextarea.html 5KB
divreplace.html 4KB
uilanguages.html 4KB
enterkey.html 4KB
共 548 条
- 1
- 2
- 3
- 4
- 5
- 6
资源评论
onnx
- 粉丝: 9320
- 资源: 4801
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功