Skip to content

Commit 7992c8b

Browse files
authored
Merge pull request #5246 from rtfd/hotfix-exclude-files
Remove excluding files on search.
2 parents 70d4cc2 + 1db6f9d commit 7992c8b

File tree

2 files changed

+49
-43
lines changed

2 files changed

+49
-43
lines changed

readthedocs/config/config.py

+20-22
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
# pylint: disable=too-many-lines
23

34
"""Build configuration for rtd."""
@@ -36,7 +37,6 @@
3637
validate_string,
3738
)
3839

39-
4040
__all__ = (
4141
'ALL',
4242
'load',
@@ -64,14 +64,16 @@
6464
INVALID_KEYS_COMBINATION = 'invalid-keys-combination'
6565
INVALID_KEY = 'invalid-key'
6666

67-
DOCKER_DEFAULT_IMAGE = getattr(settings, 'DOCKER_DEFAULT_IMAGE', 'readthedocs/build')
67+
DOCKER_DEFAULT_IMAGE = getattr(
68+
settings, 'DOCKER_DEFAULT_IMAGE', 'readthedocs/build'
69+
)
6870
DOCKER_DEFAULT_VERSION = getattr(settings, 'DOCKER_DEFAULT_VERSION', '2.0')
6971
# These map to corresponding settings in the .org,
7072
# so they haven't been renamed.
7173
DOCKER_IMAGE = getattr(
7274
settings,
7375
'DOCKER_IMAGE',
74-
'{}:{}'.format(DOCKER_DEFAULT_IMAGE, DOCKER_DEFAULT_VERSION)
76+
'{}:{}'.format(DOCKER_DEFAULT_IMAGE, DOCKER_DEFAULT_VERSION),
7577
)
7678
DOCKER_IMAGE_SETTINGS = getattr(settings, 'DOCKER_IMAGE_SETTINGS', {})
7779

@@ -243,9 +245,7 @@ def python_full_version(self):
243245
# Get the highest version of the major series version if user only
244246
# gave us a version of '2', or '3'
245247
ver = max(
246-
v
247-
for v in self.get_valid_python_versions()
248-
if v < ver + 1
248+
v for v in self.get_valid_python_versions() if v < ver + 1
249249
)
250250
return ver
251251

@@ -275,7 +275,6 @@ def get_valid_python_versions_for_image(self, build_image):
275275
Returns supported versions for the ``DOCKER_DEFAULT_VERSION`` if not
276276
``build_image`` found.
277277
"""
278-
279278
if build_image not in DOCKER_IMAGE_SETTINGS:
280279
build_image = '{}:{}'.format(
281280
DOCKER_DEFAULT_IMAGE,
@@ -320,7 +319,9 @@ def get_valid_python_versions(self):
320319
except (KeyError, TypeError):
321320
versions = set()
322321
for _, options in DOCKER_IMAGE_SETTINGS.items():
323-
versions = versions.union(options['python']['supported_versions'])
322+
versions = versions.union(
323+
options['python']['supported_versions']
324+
)
324325
return versions
325326

326327
def get_valid_formats(self): # noqa
@@ -510,7 +511,8 @@ def validate_requirements_file(self):
510511
return None
511512
with self.catch_validation_error('requirements_file'):
512513
requirements_file = validate_file(
513-
requirements_file, self.base_path
514+
requirements_file,
515+
self.base_path,
514516
)
515517
return requirements_file
516518

@@ -546,23 +548,23 @@ def python(self):
546548
python_install.append(
547549
PythonInstallRequirements(
548550
requirements=requirements,
549-
)
551+
),
550552
)
551553
if python['install_with_pip']:
552554
python_install.append(
553555
PythonInstall(
554556
path=self.base_path,
555557
method=PIP,
556558
extra_requirements=python['extra_requirements'],
557-
)
559+
),
558560
)
559561
elif python['install_with_setup']:
560562
python_install.append(
561563
PythonInstall(
562564
path=self.base_path,
563565
method=SETUPTOOLS,
564566
extra_requirements=[],
565-
)
567+
),
566568
)
567569

568570
return Python(
@@ -785,30 +787,30 @@ def validate_python_install(self, index):
785787
with self.catch_validation_error(requirements_key):
786788
requirements = validate_file(
787789
self.pop_config(requirements_key),
788-
self.base_path
790+
self.base_path,
789791
)
790792
python_install['requirements'] = requirements
791793
elif 'path' in raw_install:
792794
path_key = key + '.path'
793795
with self.catch_validation_error(path_key):
794796
path = validate_directory(
795797
self.pop_config(path_key),
796-
self.base_path
798+
self.base_path,
797799
)
798800
python_install['path'] = path
799801

800802
method_key = key + '.method'
801803
with self.catch_validation_error(method_key):
802804
method = validate_choice(
803805
self.pop_config(method_key, PIP),
804-
self.valid_install_method
806+
self.valid_install_method,
805807
)
806808
python_install['method'] = method
807809

808810
extra_req_key = key + '.extra_requirements'
809811
with self.catch_validation_error(extra_req_key):
810812
extra_requirements = validate_list(
811-
self.pop_config(extra_req_key, [])
813+
self.pop_config(extra_req_key, []),
812814
)
813815
if extra_requirements and python_install['method'] != PIP:
814816
self.error(
@@ -1060,13 +1062,9 @@ def python(self):
10601062
python = self._config['python']
10611063
for install in python['install']:
10621064
if 'requirements' in install:
1063-
python_install.append(
1064-
PythonInstallRequirements(**install)
1065-
)
1065+
python_install.append(PythonInstallRequirements(**install),)
10661066
elif 'path' in install:
1067-
python_install.append(
1068-
PythonInstall(**install)
1069-
)
1067+
python_install.append(PythonInstall(**install),)
10701068
return Python(
10711069
version=python['version'],
10721070
install=python_install,

readthedocs/search/documents.py

+29-21
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
# -*- coding: utf-8 -*-
12
import logging
23

34
from django.conf import settings
45
from django_elasticsearch_dsl import DocType, Index, fields
56

6-
from readthedocs.projects.models import Project, HTMLFile
7+
from readthedocs.projects.models import HTMLFile, Project
8+
79

810
project_conf = settings.ES_INDEXES['project']
911
project_index = Index(project_conf['name'])
@@ -13,7 +15,6 @@
1315
page_index = Index(page_conf['name'])
1416
page_index.settings(**page_conf['settings'])
1517

16-
1718
log = logging.getLogger(__name__)
1819

1920

@@ -22,10 +23,12 @@ class ProjectDocument(DocType):
2223

2324
# Metadata
2425
url = fields.TextField(attr='get_absolute_url')
25-
users = fields.NestedField(properties={
26-
'username': fields.TextField(),
27-
'id': fields.IntegerField(),
28-
})
26+
users = fields.NestedField(
27+
properties={
28+
'username': fields.TextField(),
29+
'id': fields.IntegerField(),
30+
}
31+
)
2932
language = fields.KeywordField()
3033

3134
class Meta(object):
@@ -67,7 +70,8 @@ class Meta(object):
6770

6871
@classmethod
6972
def faceted_search(
70-
cls, query, user, projects_list=None, versions_list=None, filter_by_user=True
73+
cls, query, user, projects_list=None, versions_list=None,
74+
filter_by_user=True
7175
):
7276
from readthedocs.search.faceted_search import PageSearch
7377
kwargs = {
@@ -87,22 +91,26 @@ def faceted_search(
8791
return PageSearch(**kwargs)
8892

8993
def get_queryset(self):
90-
"""Overwrite default queryset to filter certain files to index"""
94+
"""Overwrite default queryset to filter certain files to index."""
9195
queryset = super(PageDocument, self).get_queryset()
9296

93-
# Exclude some files to not index
94-
excluded_files = [
95-
'search.html',
96-
'genindex.html',
97-
'py-modindex.html',
98-
'search/index.html',
99-
'genindex/index.html',
100-
'py-modindex/index.html',
101-
]
102-
10397
# Do not index files that belong to non sphinx project
10498
# Also do not index certain files
105-
queryset = queryset.filter(project__documentation_type__contains='sphinx')
106-
for ending in excluded_files:
107-
queryset = queryset.exclude(path__endswith=ending)
99+
queryset = queryset.filter(
100+
project__documentation_type__contains='sphinx'
101+
)
102+
103+
# TODO: Make this smarter
104+
# This was causing issues excluding some valid user documentation pages
105+
# excluded_files = [
106+
# 'search.html',
107+
# 'genindex.html',
108+
# 'py-modindex.html',
109+
# 'search/index.html',
110+
# 'genindex/index.html',
111+
# 'py-modindex/index.html',
112+
# ]
113+
# for ending in excluded_files:
114+
# queryset = queryset.exclude(path=ending)
115+
108116
return queryset

0 commit comments

Comments
 (0)