Skip to main content

一个 Pelican 插件,提供对 Sphinxsearch 工具的支持,允许用户在使用 Pelican(用 Python 编写的静态站点生成器)生成的网站上建议的文本上搜索关键字。

项目描述

Shinxsearch 寻找鹈鹕

这个 Pelican 插件的目的是提供对Sphinxsearch 工具的支持,允许用户在使用Pelican(用 Python 编写的静态站点生成器)生成的网站上搜索建议的文本上的关键字。

该插件本身受到了这项出色工作的广泛启发:

Github:鹈鹕搜索

以下是改进列表:

  • 支持 Python 3.x
  • 使用 BeautifulSoup 更好地支持 html 文本
  • 用于搜索框和结果页面的 HTML 和 PHP 模板
  • 支持 OR、AND、NOT 查询运算符
  • 您不需要仅用于搜索引擎的 uwsgi 应用程序,一个简单的 PHP 服务器是唯一的要求

Python依赖项的安装

这个插件需要beautifulsoup4模块(如果需要会自动安装)。

安装:

pip install pelican-sphinxsearch

Or locally
python setup.py develop

模板集成

文件夹中提供了示例site_files

搜索框的示例在文件中search_box.html;您可以将此模板包含在您的主题中所需的位置;最好在base.html带有此指令的文件中:

{% include 'search_box.html' %}

文件中提供的 CSS 规则很少search_box.css

如果将它们添加到自己的 CSS 规则中,下面是一个示例:

搜索框截图

对于结果,文件中提供了完整的 PHP 页面search.php。此页面处理表单帖子,对 Sphinxsearch 引擎进行查询,并为用户打印结果。

您可以通过更新以下行来修改 Sphinx 搜索引擎的位置:

$sphinx->setServer('localhost', 9312);

这是您可以期待的示例:

搜索结果截图

文件search.phpsearch_box.html必须放在templates你的主题目录中。

例子:

./pelican-themes/aboutwilson/templates

鹈鹕配置

在您的pelicanconf.py中,请添加/更新这些行:

PLUGIN_PATHS = ['pelican-plugins']
PLUGINS = ['sphinxsearch',]
TEMPLATE_PAGES = {'search.php': 'search.php',}

狮身人面像搜索配置

配置文件

请在服务器中编辑以下文件:

sudo nano /etc/sphinxsearch/sphinx.conf

唯一会被索引的文件是命名的,当你更新它时它会出现在 Pelican 项目sphinxsearch.xml的文件夹中。output

网站部分示例:

source my_blog {
	type = xmlpipe2
	xmlpipe_command = cat /var/www/html/my_own_blog/sphinxsearch.xml
	xmlpipe_fixup_utf8 = 1
	xmlpipe_field = content
	xmlpipe_attr_string = title
	xmlpipe_attr_string = author
	xmlpipe_attr_json = authors
	xmlpipe_attr_string = url
	xmlpipe_attr_string = category
	xmlpipe_attr_string = category_url
	xmlpipe_attr_json = tags
	xmlpipe_attr_string = summary
	xmlpipe_attr_string = slug
	xmlpipe_attr_timestamp = published
}

index my_blog {
	type = plain
	source = my_blog
	path = /var/lib/sphinxsearch/data/
	charset_type = utf-8
	charset_table           = U+FF10..U+FF19->0..9, U+FF21..U+FF3A->a..z\
				, U+FF41..U+FF5A->a..z, 0..9, A..Z->a..z, a..z ,U+00C0->a, U+00C1->a\
				, U+00C2->a, U+00C3->a, U+00C4->a, U+00C5->a, U+00E0->a, U+00E1->a\
				, U+00E2->a, U+00E3->a, U+00E4->a, U+00E5->a, U+0100->a, U+0101->a\
				, U+0102->a, U+0103->a, U+010300->a, U+0104->a, U+0105->a, U+01CD->a\
				, U+01CE->a, U+01DE->a, U+01DF->a, U+01E0->a, U+01E1->a, U+01FA->a\
				, U+01FB->a, U+0200->a, U+0201->a, U+0202->a, U+0203->a, U+0226->a\
				, U+0227->a, U+023A->a, U+0250->a, U+04D0->a, U+04D1->a, U+1D2C->a\
				, U+1D43->a, U+1D44->a, U+1D8F->a, U+1E00->a, U+1E01->a, U+1E9A->a\
				, U+1EA0->a, U+1EA1->a, U+1EA2->a, U+1EA3->a, U+1EA4->a, U+1EA5->a\
				, U+1EA6->a, U+1EA7->a, U+1EA8->a, U+1EA9->a, U+1EAA->a, U+1EAB->a\
				, U+1EAC->a, U+1EAD->a, U+1EAE->a, U+1EAF->a, U+1EB0->a, U+1EB1->a\
				, U+1EB2->a, U+1EB3->a, U+1EB4->a, U+1EB5->a, U+1EB6->a, U+1EB7->a\
				, U+2090->a, U+2C65->a ,U+00C8->e, U+00C9->e, U+00CA->e, U+00CB->e\
				, U+00E8->e, U+00E9->e, U+00EA->e, U+00EB->e, U+0112->e, U+0113->e\
				, U+0114->e, U+0115->e, U+0116->e, U+0117->e, U+0118->e, U+0119->e\
				, U+011A->e, U+011B->e, U+018E->e, U+0190->e, U+01DD->e, U+0204->e\
				, U+0205->e, U+0206->e, U+0207->e, U+0228->e, U+0229->e, U+0246->e\
				, U+0247->e, U+0258->e, U+025B->e, U+025C->e, U+025D->e, U+025E->e\
				, U+029A->e, U+1D07->e, U+1D08->e, U+1D31->e, U+1D32->e, U+1D49->e\
				, U+1D4B->e, U+1D4C->e, U+1D92->e, U+1D93->e, U+1D94->e, U+1D9F->e\
				, U+1E14->e, U+1E15->e, U+1E16->e, U+1E17->e, U+1E18->e, U+1E19->e\
				, U+1E1A->e, U+1E1B->e, U+1E1C->e, U+1E1D->e, U+1EB8->e, U+1EB9->e\
				, U+1EBA->e, U+1EBB->e, U+1EBC->e, U+1EBD->e, U+1EBE->e, U+1EBF->e\
				, U+1EC0->e, U+1EC1->e, U+1EC2->e, U+1EC3->e, U+1EC4->e, U+1EC5->e\
				, U+1EC6->e, U+1EC7->e, U+2091->e ,U+00CC->i, U+00CD->i, U+00CE->i\
				, U+00CF->i, U+00EC->i, U+00ED->i, U+00EE->i, U+00EF->i, U+010309->i\
				, U+0128->i, U+0129->i, U+012A->i, U+012B->i, U+012C->i, U+012D->i\
				, U+012E->i, U+012F->i, U+0130->i, U+0131->i, U+0197->i, U+01CF->i\
				, U+01D0->i, U+0208->i, U+0209->i, U+020A->i, U+020B->i, U+0268->i\
				, U+026A->i, U+040D->i, U+0418->i, U+0419->i, U+1E09->c, U+212D->c\
				, U+2184->c
	mlock = 1
	enable_star = 1
	expand_keywords = 1
	phrase_boundary = ., ?, !, U+2026 # horizontal ellipsis
	preopen = 1
	html_strip = 1
	html_index_attrs = img=alt,title; a=title;
	html_remove_elements    = style, script
	min_word_len = 2
	stopwords = /var/lib/sphinxsearch/data/stopwords_fr.txt
	morphology            = libstemmer_french
}

创建/更新索引

第一次初始化索引的命令是:

sudo indexer --all

下一次,命令将是这样的:

sudo /usr/bin/indexer --rotate --config /etc/sphinxsearch/sphinx.conf --all

您可以Makefile通过添加以下指令来更新 Pelican 项目:

update_sphinxsearch:
	@echo "Update Sphinxsearch index"
	sudo /usr/bin/indexer --rotate --config /etc/sphinxsearch/sphinx.conf --all

...并将其添加到您最喜欢的部署指令中:

$(MAKE) update_sphinxsearch

项目详情


下载文件

下载适用于您平台的文件。如果您不确定要选择哪个,请了解有关安装包的更多信息。

源分布

pelican-sphinxsearch-1.1.tar.gz (6.8 kB 查看哈希)

已上传 source