Skip to content

Commit 5d82f4f

Browse files
committed
Merge branch 'master' into develop
2 parents 278d757 + 27cf1d0 commit 5d82f4f

29 files changed

+675
-135
lines changed

_elastic/indexer.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import json
2+
import os
3+
4+
import boto3
5+
import elasticsearch
6+
from elasticsearch import Elasticsearch, RequestsHttpConnection
7+
from elasticsearch.helpers import bulk
8+
from requests_aws4auth import AWS4Auth
9+
10+
11+
def build_documents(version, build_folder):
12+
for root, _, files in os.walk(build_folder):
13+
for filename in files:
14+
if not filename.endswith(".fjson"):
15+
continue
16+
abs_path = os.path.join(root, filename)
17+
with open(abs_path, "r") as f:
18+
data = json.load(f)
19+
if not data.get("title"):
20+
continue
21+
title = data["title"]
22+
slug = data["current_page_name"] + ".html"
23+
parent_title = data["parents"][0]["title"] if data["parents"] else ""
24+
html = data["body"]
25+
element = {"version": version, "title": title, "parent_title": parent_title,
26+
"slug": slug, "html": html}
27+
yield element
28+
29+
30+
class ElasticManager(object):
31+
32+
def __init__(self, host, region):
33+
credentials = boto3.Session().get_credentials()
34+
awsauth = AWS4Auth(credentials.access_key, credentials.secret_key, region, "es")
35+
36+
es = Elasticsearch(
37+
hosts=[{'host': host, 'port': 443}],
38+
http_auth=awsauth,
39+
use_ssl=True,
40+
verify_certs=True,
41+
connection_class=RequestsHttpConnection
42+
)
43+
44+
self.es = es
45+
46+
def _gendata(self, version, folder):
47+
data = build_documents(version, folder)
48+
for doc in data:
49+
doc["_index"] = "docs"
50+
doc["_type"] = "docs"
51+
yield doc
52+
53+
def create_index(self):
54+
doc = """
55+
{
56+
"settings": {
57+
"analysis": {
58+
"analyzer": {
59+
"htmlStripAnalyzer": {
60+
"type": "custom",
61+
"tokenizer": "standard",
62+
"filter": ["standard","lowercase"],
63+
"char_filter": [
64+
"html_strip"
65+
]
66+
}
67+
}
68+
}
69+
},
70+
"mappings": {
71+
"docs": {
72+
"properties": {
73+
"html": {"type": "text", "analyzer": "htmlStripAnalyzer"},
74+
"title" : { "type" : "text" },
75+
"parent_title" : { "type" : "text" },
76+
"version": {"type": "text"},
77+
"url" : { "type" : "text" }
78+
}
79+
}
80+
}
81+
}
82+
"""
83+
self.es.indices.create(index="docs", body=doc)
84+
85+
def remove_index(self):
86+
try:
87+
self.es.indices.delete(index="docs")
88+
except elasticsearch.exceptions.NotFoundError:
89+
pass
90+
91+
def index(self, version, folder):
92+
bulk(self.es, self._gendata(version, folder))
93+
94+
def ping(self):
95+
return self.es.info()

_elastic/query_examples/index.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
curl -X DELETE "localhost:9200/docs"
2+
3+
curl -X PUT "localhost:9200/docs" -H 'Content-Type: application/json' -d'
4+
{
5+
"settings": {
6+
"analysis": {
7+
"analyzer": {
8+
"htmlStripAnalyzer": {
9+
"type": "custom",
10+
"tokenizer": "standard",
11+
"filter": ["standard","lowercase"],
12+
"char_filter": [
13+
"html_strip"
14+
]
15+
}
16+
}
17+
}
18+
},
19+
"mappings": {
20+
"docs": {
21+
"properties": {
22+
"html": {"type": "text", "analyzer": "htmlStripAnalyzer"},
23+
"title" : { "type" : "text" },
24+
"parent_title" : { "type" : "text" },
25+
"version": {"type": "text"},
26+
"url" : { "type" : "text" }
27+
}
28+
}
29+
}
30+
}'
31+
32+
33+
34+
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
curl -X POST "localhost:9200/docs/_doc/integrations\/custom" -H 'Content-Type: application/json' -d'
2+
{
3+
"version": "1.15",
4+
"parent_title" : "Integrations",
5+
"url": "integrations/custom",
6+
"title" : "Custom integrations",
7+
"html" : "trying out Elasticsearch"
8+
}
9+
'
10+
11+
12+
13+
curl -X POST "localhost:9200/docs/_doc/" -H 'Content-Type: application/json' -d'
14+
{
15+
"version": "1.15",
16+
"parent_title" : "Integrations",
17+
"url": "integrations/custom",
18+
"title" : "Custom integrations",
19+
"html" : "trying out integrations"
20+
}
21+
'
22+
23+
24+
25+
curl -X POST "localhost:9200/docs/_doc/" -H 'Content-Type: application/json' -d'
26+
{
27+
"version": "1.15",
28+
"parent_title" : "Integrations",
29+
"url": "integrations/custom",
30+
"title" : "Patata",
31+
"html" : "trying out integrations"
32+
}
33+
'
34+
35+
36+
curl -X POST "localhost:9200/docs/_doc/" -H 'Content-Type: application/json' -d'
37+
{
38+
"version": "1.15",
39+
"parent_title" : "Integrations",
40+
"url": "integrations/custom",
41+
"title" : "Other title",
42+
"html" : "trying out integrations patata"
43+
}
44+
'
45+

_elastic/query_examples/query.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
curl -X GET "localhost:9200/docs/_search" -H 'Content-Type: application/json' -d'
2+
{
3+
"from" : 0, "size" : 5,
4+
"query": {
5+
"bool": {
6+
"filter": [
7+
{ "match": { "version": "1.15"}}
8+
],
9+
"should": [
10+
{ "match": {
11+
"html": {
12+
"query": "patata",
13+
"boost": 1
14+
}
15+
}},
16+
{ "match": {
17+
"title": {
18+
"query": "patata",
19+
"boost": 4
20+
}
21+
}}
22+
]
23+
}
24+
}
25+
}
26+
'
27+
28+
29+
30+
curl -X GET "localhost:9200/docs/_search" -H 'Content-Type: application/json' -d'
31+
{
32+
"query": {
33+
"match" : {
34+
"version" : "1.15"
35+
}
36+
}
37+
}
38+
'

_themes/conan/breadcrumbs.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
{% set display_gitlab = True %}
2525
{% endif %}
2626

27-
<div role="navigation" aria-label="breadcrumbs navigation">
27+
<div role="navigation" aria-label="breadcrumbs navigation" id="breadcrumbs">
2828

2929
<ul class="wy-breadcrumbs">
3030
{% block breadcrumbs %}
@@ -78,5 +78,4 @@
7878
{% endif %}
7979
</div>
8080
{% endif %}
81-
<hr/>
8281
</div>

_themes/conan/layout.html

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@
4949
<link rel="stylesheet" href="{{ pathto(cssfile, 1) }}" type="text/css" />
5050
{% endfor %}
5151

52+
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/css/select2.min.css" rel="stylesheet" />
53+
<link rel="stylesheet" href="{{ pathto('_static/css/' +'search.css', 1) }}" type="text/css" />
54+
5255
{%- block linktags %}
5356
{%- if hasdoc('about') %}
5457
<link rel="author" title="{{ _('About these documents') }}"
@@ -78,7 +81,6 @@
7881
{%- block extrahead %} {% endblock %}
7982

8083
{# Keep modernizr in head - http://modernizr.com/docs/#installing #}
81-
<script src="{{ pathto('_static/js/modernizr.min.js', 1) }}"></script>
8284

8385
</head>
8486

@@ -148,9 +150,14 @@
148150

149151

150152
{# PAGE CONTENT #}
153+
<script>
154+
var reldir = "{{ pathto("index") }}".replace("index.html","").replace("#", "");
155+
</script>
151156
<div class="wy-nav-content">
152157
<div class="rst-content">
153158
{% include "breadcrumbs.html" %}
159+
<select id="search" name="state" multiple="true" onchange="window.location = reldir + this.value;" style="width:90%"></select>
160+
<hr/>
154161
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
155162
<div itemprop="articleBody">
156163
{% block body %}{% endblock %}
@@ -191,6 +198,14 @@
191198
<script type="text/javascript" src="{{ pathto('_static/js/theme.js', 1) }}"></script>
192199
{% endif %}
193200

201+
<script
202+
src="https://code.jquery.com/jquery-3.4.1.min.js"
203+
integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
204+
crossorigin="anonymous"></script>
205+
<script src="{{ pathto('_static/js/modernizr.min.js', 1) }}"></script>
206+
<script src="{{ pathto('_static/js/search.js', 1) }}"></script>
207+
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.7/js/select2.min.js"></script>
208+
194209
{# STICKY NAVIGATION #}
195210
{% if theme_sticky_navigation %}
196211
<script type="text/javascript">
@@ -200,6 +215,11 @@
200215
</script>
201216
{% endif %}
202217

218+
219+
<script>
220+
initSearch("{{ current_version }}");
221+
</script>
222+
203223
{%- block footer %} {% endblock %}
204224

205225
</body>

_themes/conan/searchbox.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{%- if builder != 'singlehtml' %}
2-
<div role="search">
2+
<!--<div role="search">
33
<form id="rtd-search-form" class="wy-form" action="{{ pathto('search') }}" method="get">
44
<input type="text" name="q" placeholder="{{ _('Search docs') }}" />
55
<input type="hidden" name="check_keywords" value="yes" />
66
<input type="hidden" name="area" value="default" />
77
</form>
8-
</div>
8+
</div>-->
99
{%- endif %}

0 commit comments

Comments
 (0)