Skip to content

Commit 086550c

Browse files
authored
Merge branch 'gsoc-19-indoc-search' into use-attrgetter
2 parents 60deec2 + c4bdddd commit 086550c

File tree

19 files changed

+745
-306
lines changed

19 files changed

+745
-306
lines changed

readthedocs/rtd_tests/tests/test_search_json_parsing.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ def test_h2_parsing(self):
1717
'files/api.fjson',
1818
),
1919
)
20+
self.assertEqual(data['path'], 'api')
2021
self.assertEqual(data['sections'][1]['id'], 'a-basic-api-client-using-slumber')
21-
# Only capture h2's after the first section
22-
for obj in data['sections'][1:]:
23-
self.assertEqual(obj['content'][:5], '\n<h2>')
22+
self.assertTrue(data['sections'][1]['content'].startswith(
23+
'You can use Slumber'
24+
))
25+
self.assertEqual(data['title'], 'Read the Docs Public API')
26+
self.assertTrue(len(data['sections']) > 0, 'There are many sections for the processed file')
27+
28+
# There should be no new line character present
29+
for section in data['sections']:
30+
self.assertFalse('\n' in section['content'])

readthedocs/search/faceted_search.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,16 @@ class PageSearchBase(RTDFacetedSearch):
114114
# the score of and should be higher as it satisfies both or and and
115115
operators = ['and', 'or']
116116

117+
def count(self):
118+
"""Overriding ``count`` method to return the count of the results after post_filter."""
119+
s = self.build_search()
120+
121+
# setting size=0 so that no results are returned,
122+
# we are only interested in the total count
123+
s = s.extra(size=0)
124+
s = s.execute()
125+
return s.hits.total
126+
117127
def query(self, search, query):
118128
"""Manipulates query to support nested query."""
119129
search = search.highlight_options(encoder='html', number_of_fragments=1)
@@ -128,6 +138,7 @@ def query(self, search, query):
128138
fields=self._section_fields,
129139
inner_hits={
130140
'highlight': {
141+
'encoder': 'html',
131142
'number_of_fragments': 1,
132143
'fields': {
133144
'sections.title': {},
@@ -144,6 +155,7 @@ def query(self, search, query):
144155
fields=self._domain_fields,
145156
inner_hits={
146157
'highlight': {
158+
'encoder': 'html',
147159
'number_of_fragments': 1,
148160
'fields': {
149161
'domains.type_display': {},

readthedocs/search/tests/conftest.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
from readthedocs.projects.models import Project, HTMLFile
1010
from readthedocs.search.documents import PageDocument
11+
from readthedocs.sphinx_domains.models import SphinxDomain
12+
1113
from .dummy_data import ALL_PROJECTS, PROJECT_DATA_FILES
1214

1315

@@ -32,6 +34,28 @@ def all_projects(es_index, mock_processed_json, db, settings):
3234
file_name = file_basename + '.html'
3335
version = project.versions.all()[0]
3436
html_file = G(HTMLFile, project=project, version=version, name=file_name)
37+
38+
# creating sphinx domain test objects
39+
file_path = get_json_file_path(project.slug, file_basename)
40+
if os.path.exists(file_path):
41+
with open (file_path) as f:
42+
data = json.load(f)
43+
domains = data['domains']
44+
45+
for domain_data in domains:
46+
domain_role_name = domain_data.pop('role_name')
47+
domain, type_ = domain_role_name.split(':')
48+
49+
G(
50+
SphinxDomain,
51+
project=project,
52+
version=version,
53+
html_file=html_file,
54+
domain=domain,
55+
type=type_,
56+
**domain_data
57+
)
58+
3559
PageDocument().update(html_file)
3660

3761
projects_list.append(project)
@@ -46,12 +70,17 @@ def project(all_projects):
4670
return all_projects[0]
4771

4872

73+
def get_json_file_path(project_slug, basename):
74+
current_path = os.path.abspath(os.path.dirname(__file__))
75+
file_name = f'{basename}.json'
76+
file_path = os.path.join(current_path, 'data', project_slug, file_name)
77+
return file_path
78+
79+
4980
def get_dummy_processed_json(instance):
5081
project_slug = instance.project.slug
5182
basename = os.path.splitext(instance.name)[0]
52-
file_name = basename + '.json'
53-
current_path = os.path.abspath(os.path.dirname(__file__))
54-
file_path = os.path.join(current_path, "data", project_slug, file_name)
83+
file_path = get_json_file_path(project_slug, basename)
5584

5685
if os.path.exists(file_path):
5786
with open(file_path) as f:

readthedocs/search/tests/data/docs/story.json

Lines changed: 0 additions & 31 deletions
This file was deleted.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"path": "support",
3+
"title": "Support",
4+
"sections": [
5+
{
6+
"id": "usage-questions",
7+
"title": "Usage Questions",
8+
"content": "If you have questions about how to use Read the Docs, or have an issue that isn’t related to a bug, Stack Overflow is the best place to ask. Tag questions with read-the-docs so other folks can find them easily.. Good questions for Stack Overflow would be:. “What is the best way to structure the table of contents across a project?”. “How do I structure translations inside of my project for easiest contribution from users?”. “How do I use Sphinx to use SVG images in HTML output but PNG in PDF output?”"
9+
},
10+
{
11+
"id": "community-support",
12+
"title": "Community Support",
13+
"content": "Read the Docs is supported by community contributions and advertising. We hope to bring in enough money with our Gold and Ethical Ads programs to keep Read the Docs sustainable.. All people answering your questions are doing it with their own time, so please be kind and provide as much information as possible.. Bugs & Support Issues. You can file bug reports on our GitHub issue tracker, and they will be addressed as soon as possible. Support is a volunteer effort, and there is no guaranteed response time. If you need answers quickly, you can buy commercial support below.. Reporting Issues. When reporting a bug, please include as much information as possible that will help us solve this issue. This includes:. Project name. URL. Action taken. Expected result. Actual result. Specific Requests. If you need a specific request for your project or account, like more resources, change of the project’s slug or username. Send an email to [email protected]."
14+
},
15+
{
16+
"id": "commercial-support",
17+
"title": "Commercial Support",
18+
"content": "We offer commercial support for Read the Docs, <h3>XSS exploit</h3> commercial hosting, as well as consulting around all documentation systems. You can contact us at [email protected] to learn more, or read more at https://readthedocs.com/services/#open-source-support."
19+
}
20+
],
21+
"domains": [
22+
{
23+
"role_name": "http:post",
24+
"doc_name": "api/v3.html",
25+
"anchor": "post--api-v3-projects-(string-project_slug)-versions-(string-version_slug)-builds-",
26+
"type_display": "post",
27+
"doc_display": "API v3",
28+
"name": "/api/v3/projects/(string:project_slug)/versions/(string:version_slug)/builds/",
29+
"display_name": ""
30+
},
31+
{
32+
"role_name": "http:patch",
33+
"doc_name": "api/v3.html",
34+
"anchor": "patch--api-v3-projects-(string-project_slug)-version-(string-version_slug)-",
35+
"type_display": "patch",
36+
"doc_display": "API v3",
37+
"name": "/api/v3/projects/(string:project_slug)/version/(string:version_slug)/",
38+
"display_name": ""
39+
}
40+
]
41+
}
Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,49 @@
11
{
2-
"content": "ReadtheDocsWiping a Build Environment\nSometimes it happen that your Builds start failing because the build environment where the is created is stale or broken. This could happen for a couple of different reasons like pip not upgrading a package properly or a corrupted cached Python package.\nIn any of these cases (and many others), the solution could be just wiping out the existing build environment files and allow Read the Docs to create a new fresh one.\nFollow these steps to wipe the build environment:\nGo to Versions\nClick on the Edit button of the version you want to wipe on the right side of the page\nGo to the bottom of the page and click the wipe link, next to the \u201cSave\u201d button\nNote\nBy wiping the build environment, all the rst, md, and code files associated with it will be removed but not the already built (HTML and PDF files). Your will still online after wiping the build environment.\nNow you can re-build the version with a fresh build environment!",
3-
"headers": [
4-
"Wiping a Build Environment"
5-
],
6-
"title": "Wiping a Build Environment",
7-
"sections": [
8-
{
9-
"content": "\nSometimes it happen that your Builds start failing because the build\nenvironment where the is created is stale or\nbroken. This could happen for a couple of different reasons like <code class=\"xref py py-obj docutils literal notranslate\"><span class=\"pre\">pip</span></code>\nnot upgrading a package properly or a corrupted cached Python package.\n\nIn any of these cases (and many others), the solution could be just\nwiping out the existing build environment files and allow Read the\nDocs to create a new fresh one.\n\nFollow these steps to wipe the build environment:\n\n\n<li>Go to <strong>Versions</strong></li>\n<li>Click on the <strong>Edit</strong> button of the version you want to wipe on the\nright side of the page</li>\n<li>Go to the bottom of the page and click the <strong>wipe</strong> link, next to\nthe \u201cSave\u201d button</li>\n\n\n\n<p class=\"first admonition-title\">Note</p>\n<p class=\"last\">By wiping the build environment, all the <code class=\"xref py py-obj docutils literal notranslate\"><span class=\"pre\">rst</span></code>, <code class=\"xref py py-obj docutils literal notranslate\"><span class=\"pre\">md</span></code>,\nand code files associated with it will be removed but not the\n already built (<code class=\"xref py py-obj docutils literal notranslate\"><span class=\"pre\">HTML</span></code> and <code class=\"xref py py-obj docutils literal notranslate\"><span class=\"pre\">PDF</span></code> files). Your\n will still online after wiping the build environment.</p>\n\n\nNow you can re-build the version with a fresh build environment!\n",
10-
"id": "wiping-a-build-environment",
11-
"title": "Wiping a Build Environment"
12-
}
13-
],
14-
"path": "guides/wipe-environment"
2+
"path": "guides/wipe-environment",
3+
"title": "Wiping a Build Environment",
4+
"sections": [
5+
{
6+
"id": "wiping-a-build-environment",
7+
"title": "Wiping a Build Environment",
8+
"content": "Sometimes it happen that your Builds start failing because the build environment where the documentation is created is stale or broken. This could happen for a couple of different reasons like pip not upgrading a package properly or a corrupted cached Python package.In any of these cases (and many others), the solution could be just wiping out the existing build environment files and allow Read the Docs to create a new fresh one.Follow these steps to wipe the build environment:Click on the Edit button of the version you want to wipe on the right side of the page. Go to the bottom of the page and click the wipe link, next to the “Save” buttonBy wiping the documentation build environment, all the rst, md, and code files associated with it will be removed but not the documentation already built (HTML and PDF files). Your documentation will still online after wiping the build environment.Now you can re-build the version with a fresh build environment! This is a test line which contains the word 'Elasticsearch Query'."
9+
}
10+
],
11+
"domains": [
12+
{
13+
"role_name": "http:get",
14+
"doc_name": "api/v3.html",
15+
"anchor": "get--api-v3-users-(str-username)",
16+
"type_display": "get",
17+
"doc_display": "API v3",
18+
"name": "/api/v3/users/(str:username)",
19+
"display_name": ""
20+
},
21+
{
22+
"role_name": "http:get",
23+
"doc_name": "api/v3.html",
24+
"anchor": "get--api-v3-projects-(string-project_slug)-versions-(string-version_slug)-",
25+
"type_display": "get",
26+
"doc_display": "API v3",
27+
"name": "/api/v3/projects/(string:project_slug)/versions/(string:version_slug)/",
28+
"display_name": ""
29+
},
30+
{
31+
"role_name": "http:get",
32+
"doc_name": "api/v3.html",
33+
"anchor": "get--api-v3-projects-(string-project_slug)-versions-",
34+
"type_display": "get",
35+
"doc_display": "API v3",
36+
"name": "/api/v3/projects/(string:project_slug)/versions/",
37+
"display_name": ""
38+
},
39+
{
40+
"role_name": "http:get",
41+
"doc_name": "api/v3.html",
42+
"anchor": "get--api-v3-projects-(string-project_slug)-",
43+
"type_display": "get",
44+
"doc_display": "API v3",
45+
"name": "/api/v3/projects/(string:project_slug)/",
46+
"display_name": ""
47+
}
48+
]
1549
}

0 commit comments

Comments
 (0)