Git Product home page Git Product logo

readthedocs-sphinx-search's Introduction

readthedocs-sphinx-search's People

Contributors

astrojuanlu avatar dependabot[bot] avatar dojutsu-user avatar ericholscher avatar flying-sheep avatar nienn avatar stsewd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

readthedocs-sphinx-search's Issues

Use `CTRL+f` to open the search box?

In #31 we added / as a hotfix to open the search box which is good.

Today I found that Stripe docs goes a step further here and uses CTRL+f which I thought immediately it was a bad decision because "I want to use just the regular search of my browser", but then I saw it says that you can hit CTRL+f again to switch to the default search feature ๐Ÿ’ฏ

Screenshot_2021-03-15_10-35-25

NOTE the message and checkbox at the bottom right

You can try it by yourself at https://stripe.com/docs/api/events/types

Release 0.1.1?

Several small fixes have been merged since the last release, namely #83, #89, #93, and #94. In particular, I think #89 and #93 are good developer and user experience improvements. Is there a chance to cut a release?

Don't clear old search term when entering new search term

When searching for a certain term, that term is displayed in the search bar.
When clicking the search bar, a search window pops up with a new empty search input.
The old search term is not in the input anymore.

This is annoying when the new search term is very similar to the old search term; for example when you made a typo in the old search term and you want to correct that.
There is no way to change the search term without completely re-entering the search term.

My prefered solution would be to show the old search term in the search input field by default.
Clearing the field manually is only a minimal effort.
If the text is selected then clearing it is usually only one keypress of any key except an arrow key.
Search inputs for all other websites that I know of work like this.

(original issue)

Search popup is unwieldy on desktop (considere using a drop down menu)

Searching is not a pleasant experience, and it's mainly because of a slow, (assumably) mobile-first search popup. While I can't speak for every documentation website, at least for the repository I'm working with (Godot Engine), desktop monitors should be the primary device to target for user experience. Example in the Godot Engine docs:

search_godot

A better instant search would only take up a modest amount of space under the search bar, and not take away the ability to use the current page. This would likely imply different search UI on mobile and desktop devices.

pypi release?

Hi!

would you mind making a PyPI release for this (could even be an alpha/beta version, such as v0.1.0a1)?
Besides reserving the name, this would also make using the extension a bit easier in some contexts.

Support default filters

It would be very useful to have the ability to have a default search query that users get when they open. This would be configurable at the integration point for the extension, perhaps adding a config option:

rtd_sphinx_search_default_filters = 'subprojects:docs'

The use case here is:

  • I am a project on RTD that has subprojects
  • We want users to be able to search across all the subprojects easily
  • When they launch search, it should already have subprojects:<slug> prepended to the search in some fashion

Parallel reading warning

After enabling the sphinx_search.extension module, we've started to see the following warnings in our Sphinx logs:

WARNING: the sphinx_search.extension extension does not declare if it is safe for parallel reading, assuming it isn't - please ask the extension author to check and make it explicit

WARNING: doing serial read

Looking at the Sphinx docs, it seems that Sphinx expects the extension metadata to specify whether it's safe to read / write files in parallel:

https://www.sphinx-doc.org/en/master/extdev/index.html#extension-metadata

These warnings can get quite noisy in our CI/CD pipeline, so it would be great to your thoughts on whether this is something that can be added to this extension's metadata.

Unable to get sphinx_search.extension to work

I've tried to make this work in a small test case. Everything I've tried has failed to load the extension.

I tried copying your conf.py and requirements.txt verbatim used in this repository. That didn't help. It failed on import sphinx_search. Here are build failure links (if RTD permits you to follow them...)

  • Attempt 1
    • Just added 'sphinx_search.extension' to conf.py extensions variable
  • Attempt 2
    • Included import sphinx_search in conf.py
  • Attempt 3
    • Added identical requirements.txt file

Can you suggest what I am doing wrong?

Blurry text on chrome with some screen sizes.

Currently modal is positioned at the center of the page with this css:
https://github.com/rtfd/readthedocs-sphinx-search/blob/358d30f80c8f6c56d21c0d58e63f71fcd6d930c4/sphinx_search/_static/css/rtd_sphinx_search.css#L30-L36

But in some screen sizes (like: 914x669), the text become blurry. Eg -

Blurry Text:
Screenshot from 2019-06-15 20-02-55

Clear Text:
Screenshot from 2019-06-15 20-03-08

This can be due to transform property because at some screen sizes it will result in fractions of pixels.
We don't want blurry text, so we have two options -

  • adjust current css to remove this glitch.
  • position the modal at the center with some other css properties.

Note: Can't use flex-box because it was acting weird with IE 11

Flaky tests

This test will fail sometimes

body = selenium.find_element_by_css_selector('body')
body.send_keys('/')
assert (
search_outer_wrapper.is_displayed() == True
), 'search__outer__wrapper should be displayed when forward slash button is pressed'

It probably needs to wait some time till the search popup is shown, maybe similar to

WebDriverWait(selenium, 10).until(
EC.text_to_be_present_in_element(
(By.CLASS_NAME, 'search__result__box'),
'No results found'
)
)

Hitting enter redirects to the Sphinx search page

It's pretty common to hit enter at the end of the search query and expect the search query to be submitted, but instead the user is redirected to the Sphinx search page. I've noted this UX issue in the past and I've had feedback that this UX is confusing as well.

This is probably more of an issue for the addons implementation, which probably won't repeat this pattern either way. But noting here in case for now.

Use an inline html template for search results and search result customization

In #116 Underscore was removed, and the pattern was shifted to native DOM manipulation.

One potential pattern to consider for future releases could be to use an HTML template inline in the output, as a Sphinx template. Effectively:

<html>
  <head>
    <script type="text/html" id="search-template">
      <div class="search__header">
        {{ _("Search results") }}
      <div class="outer__html">
        <div class="header">
          ...
        </div>
        ...
      </div>
    </script>
  </head>
</html>

This gives a template that can be targeted by our search JS, and manipulation of the template would happen with some data binding logic, or a more simple DOM search and replace.

The benefit here is that it is customizable at the Sphinx theme/template level, and can incorporate localization during the Sphinx build. Currently the search window will always be English. Localization is also possible in the JS now, but would have to be an additional step to be hooked into during building.

Empty search results have styles inlined

Over at Godot Docs we have an issue setting up our custom dark theme with this extensions because there are inlined styles, which is making them harder to override. The specific issue is with empty search results, setup here:

style: "color: black; min-width: 300px; font-weight: 700"

image

I would appreciate if you've changed those three inlined rules to a stylesheet class.

ModuleNotFoundError: No module named 'sphinx_search'

Thanks for this great looking enhancement to docs search. I've followed the install docs. This is very possibly a rookie error, but what am I doing wrong here when rebuilding our docs on ReadTheDocs?

conf.py:

extensions = [
    'sphinx.ext.autosectionlabel',
    'sphinx_search.extension',
]

Build command:

python -m sphinx -T -E -b html -d _build/doctrees -D language=en . $READTHEDOCS_OUTPUT/html

Error:

Running Sphinx v1.8.6
loading translations [en]... done

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/research-handbook-security-force-monitor/envs/latest/lib/python3.11/site-packages/sphinx/registry.py", line 472, in load_extension
    mod = __import__(extname, None, None, ['setup'])
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'sphinx_search'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/research-handbook-security-force-monitor/envs/latest/lib/python3.11/site-packages/sphinx/cmd/build.py", line 300, in build_main
    app = Sphinx(args.sourcedir, args.confdir, args.outputdir,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/docs/checkouts/readthedocs.org/user_builds/research-handbook-security-force-monitor/envs/latest/lib/python3.11/site-packages/sphinx/application.py", line 228, in __init__
    self.setup_extension(extension)
  File "/home/docs/checkouts/readthedocs.org/user_builds/research-handbook-security-force-monitor/envs/latest/lib/python3.11/site-packages/sphinx/application.py", line 449, in setup_extension
    self.registry.load_extension(self, extname)
  File "/home/docs/checkouts/readthedocs.org/user_builds/research-handbook-security-force-monitor/envs/latest/lib/python3.11/site-packages/sphinx/registry.py", line 475, in load_extension
    raise ExtensionError(__('Could not import extension %s') % extname, err)
sphinx.errors.ExtensionError: Could not import extension sphinx_search.extension (exception: No module named 'sphinx_search')

Extension error:
Could not import extension sphinx_search.extension (exception: No module named 'sphinx_search')

Search as you type

A few issues that I have been hitting consistently:

  • When I target the search box to type a search query, I'm always too early typing. The delay introduced by the transition fade in is too slow and this usually results in my vim keybindings closing the window or doing something unwanted. Delay should be removed or reduced to resolve this issue. Ideally, the normal search box should be reused for this purpose, and perhaps a popup only occurs on key press events.
  • If you hit enter on the search popup, which I inevitably do, you are brought to the default search page. On this page, the search query is in the search box, but if you select the search box to search again, the search query is not in the popup search box

image

  • Escape key could close the popup

Give the ability to run tests for selected browser via command line args

Currently, either the tests for both -- chrome and firefox -- will run or none will run.
We want to select the browser for tests.
Like:

pytest -v --chrome (runs the tests with chrome driver)
pytest -v --firefox (runs the tests with geckodriver)
pytest -v (runs the tests with both drivers)

Use unique variable names in documentation and configuration

We are currently suggesting the following configuration:

# https://docs.readthedocs.io/page/reference/environment-variables.html
project = os.environ["READTHEDOCS_PROJECT"]
version = os.environ["READTHEDOCS_VERSION"]

# Include results from subprojects by default.
rtd_sphinx_search_default_filter = f"subprojects:{project}/{version}"

But these variables collide with the Sphinx configuration variables project and version, which aren't always the project/version slug -- they can be a verbose name established by the documentation author.

We should prefix our variables in documentation to make them unique, but it also looks like the default configuration uses project directly, which will have side effects if the project name is not the RTD slug.

https://github.com/readthedocs/readthedocs-sphinx-search/blob/main/docs/configuration.rst?plain=1#L25

Figure out section-based searching

It would be neat to be able to search a subset of the docs. An example:

if I did a search at https://docs.readthedocs.io/en/latest/development/install.html -- I had the option to only search inside development inside the docs. This would work similarly well with /guides/ and other "sections".

I think the best option here will be to enable authors to define sections that they want to be able to search within. We have HTMLFile's, so we could see what sections of files users have, and let them create a config that sets these sections as searchable. This could look like:

# .readthedocs.yml

search:
  sections:
    - /development/: Developer docs
    - /guides/: User Guides
 

We could also in theory auto-generate this from the toctree caption argument, or other similar automatic approaches.

@dojutsu-user has an initial demo of this that parses the URL directly from the current page. This is one possible option, but we likely want to let users have a bit more knowledge and UX around sections. Need to think about this more.

Switch to webpack

We don't want to use gulp, it would be better if we can switch everything to webpack.

sphinx-search and sphinx-intersphinx

If I use intersphinx to link other sphinx instances e.g.

intersphinx_mapping = {
    'ewb': ('https://ewb.readthedocs.io/en/latest/', None),
    'rdf': ('https://rdfabout.readthedocs.io/en/latest/', None),
}

how to configure sphinx-search to search those instances for a specified string?

For example, looking here: https://readthedocs-sphinx-search.readthedocs.io/en/latest/customization.html#custom-styles

<a href="/api-v2?highlight=api">
              <h2 class="search__result__title">
                     API v2
                     <br />
              </h2>
 </a>

Search is relative to the page from which the search is launched.

Is it possible to specify other search domains - following the intersphinx method to :ref: another sphinx instance?

How to change the search box color according to the system color

For instance, if my system is dark mode , the search box will change its color to dark, And when the system is in light mode, the search box will change its color to a light one. l know that dark reader can do this , but is there any method to support it originally, l believe not everyone will install dark reader on their laptop. l have noticed that l can achieve this through custom.css , but how can l change the color automatically? Or has any already done that and would you please share your custom.css? Thanks!

Best
Daniel

Re-structure HTML of the results

This would be a more simple structure and use CSS for spacing instead of br elements, and use the html tag a little more "semantically" (don't know if this is a word p: what I mean is for example we are using span tags for titles, and even we have a div inside span tags).

The current structure is

<div class="search__outer__wrapper search__backdrop">
<div class="search__outer">
<div class="search__cross" title="Close">
<!--?xml version="1.0" encoding="UTF-8"?-->
<svg
class="search__cross__img"
width="15px"
height="15px"
enable-background="new 0 0 612 612"
version="1.1"
viewBox="0 0 612 612"
xml:space="preserve"
xmlns="http://www.w3.org/2000/svg">
<polygon
points="612 36.004 576.52 0.603 306 270.61 35.478 0.603 0 36.004 270.52 306.01 0 576 35.478 611.4 306 341.41 576.52 611.4 612 576 341.46 306.01">
</polygon>
</svg>
</div>
<input class="search__outer__input" placeholder="Search ..." />
<span class="bar"></span>
<div class="rtd__search__credits">
Search by <a href="https://readthedocs.org/">Read the Docs</a> &amp; <a href="https://readthedocs-sphinx-search.readthedocs.io/en/latest/">readthedocs-sphinx-search</a>
<div>
<div class="search__result__box">
<!-- RESULT 1 -->
<div class="search__result__single">
<div>
<!-- Page Link -->
<a href="/api-v2?highlight=api">
<!-- Page Title -->
<h2 class="search__result__title">
API v2
<br />
</h2>
</a>
<!-- Results Inside The Page -->
<!-- HIT 1 (type: "sections") -->
<a href="/api-v2?highlight=api#section-1">
<div class="outer_div_page_results" id="hit__1">
<!-- Section Title -->
<span class="search__result__subheading">
<em>Section</em> One
</span>
<!-- Section Content -->
<p class="search__result__content">
... This is sample text for <em>section</em> one.
</p>
</div>
</a>
<br class="br-for-hits" />
<!-- HIT 2 (type: "sections") -->
<a href="/api-v2?highlight=api#section-2">
<div class="outer_div_page_results" id="hit__2">
<!-- Section Title -->
<span class="search__result__subheading">
<em>Section</em> Two
</span>
<!-- Section Content -->
<p class="search__result__content">
... This is sample text for <em>section</em> two.
</p>
</div>
</a>
<br class="br-for-hits" />
<!-- HIT 3 (type: "domains") -->
<a href="/api-v2?highlight=api#section-1-sphinx-domain">
<div class="outer_div_page_results" id="hit__3">
<!-- Domain name -->
<span class="search__result__subheading">
/api/v2/section/
<!-- Domain role name -->
<div class="search__domain_role_name">
[http:get]
</div>
</span>
<!-- Domain Content -->
<p class="search__result__content">
get -- /api/v2/<em>section</em>/ -- in Section One
</p>
</div>
</a>
<br class="br-for-hits" />
<!-- Other Results From Same Page -->
</div>
</div>
<!-- Other Results From Different Pages -->
<div class="search__result__single"><div>...</div></div>
<div class="search__result__single"><div>...</div></div>
<div class="search__result__single"><div>...</div></div>
</div>
</div>
</div>

ref #116

Hitting Enter uses the default search page

Steps to reproduce it

  1. go to https://docs.readthedocs.io/en/latest/
  2. click on search
  3. type configuration
  4. hit Enter

Actual result

You are redirected to https://docs.readthedocs.io/en/latest/search.html?q=configuration&check_keywords=yes&area=default which is the default search (instead of the Search As You Type)

Expected result

I was expecting that it will just send the current query to the backend and do nothing, basically.

In case we want to have a fallback to the default search result, I think the usage of Enter has to be communicated in the UI.

Automatically "wildcard search"?

Is there a way to configure search to act as if a wildcard (*) is present at the end of the user-entered search string? Based on feedback I've received, this behavior is expected by some and they think the search is broken since it doesn't do that (by default). I didn't see anything about this in the docs, but may have overlooked something.

Results not displayed if search closed/re-opened

If the search screen is closed (by clicking "X", hitting escape, etc.) and then re-opened by clicking in the search input or pressing "/", the search term remains in the input field but no results are displayed unless it is edited. It seems that the search function should be triggered if the screen opens with a search term already defined.

Search results returned after search term typed in:
image

After closing and re-opening the search screen without modify anything:
image

Add filtering UI to search

Our RTD search has a lot of nice filters on it. We should expose this with a a fancier UI element for filters in the extension, along with having them in the query string.

I'm imagining something similar to this:

Screenshot 2023-02-08 at 9 28 58 AM

Having the checkboxes that at least by default includes subprojects.

Not working as specified

Am testing features here and have some observations...

  • Each time I want to adjust a search string, the pop-up window begins with empty text, even though the RTD search text field shows the text I last entered (or there-abouts...it winds up being subtley altered. For example any + is removed).
  • Searching for endian +-silo returns 9 pages which tells me its return pages that include either endian or silo and not pages that contain endian but do not contain silo.
  • + operator seems wholly ignored. In fact, it gets removed when RTD echos the search string back
  • All these search strings return the same result chunk fortran, chunk +fortran chunk + fortran, chunk | fortran
  • -silo returns all pages (silo is used on some pages).

So, either I am wholly mis-understanding how this is supposed to work or the search functionality is not working as documented.

Don't push to history too often

Every time you type a character, the history is updated. This makes it hard to go back to the previous page.

https://docs.readthedocs.io/en/stable/?rtd_search=term
https://docs.readthedocs.io/en/stable/?rtd_search=ter
https://docs.readthedocs.io/en/stable/?rtd_search=te
https://docs.readthedocs.io/en/stable/?rtd_search=t
<actual previous page>

Result on same page does not hide the search box

Steps to reproduce it

  1. search for a term (for example a configuration option)
  2. click on the result to go to the Configuration page
  3. click on the search again
  4. search for another term that has a hit in the configuration page (but different anchor)
  5. click on that result

Expected result

Move to the section of the hit and hide the search box.

Actual result

Search box is not hidden.

NOTE: I'm using "Configuratio page" as example but the required thing is to be the same page in both results

Release 0.1.2?

It's small, but we need the fix from #108 in order to use this extension in our workflow -- if it's possible to do a new release we'd really appreciate it!

Convert to a js library/extension

We should probably remove the sphinx from the name of this extension, because I believe it should work fine with mkdocs. We might just want to name it readthedocs-search or readthedocs-livesearch or something.

Clarify how a downstream theme could support this

I was looking into how the pydata sphinx theme could support this search functionality, but was a bit confused by the documentation so asking questions here to help clarify.

The custom search input docs

Suggest that you need a structure like this:

<div role="search">
   <form action="search.html" method="get">
      <input type="text" name="q" placeholder="Search docs" />
   </form>
</div>

However, in the pydata theme, we have a little button that will pop up a search window, rather than a search field:

Clicking this button, or typing Ctrl+K will cause the search window to pop up:

chrome_5vouqhobec

It has this structure:

<button class="btn btn-sm navbar-btn search-button search-button__button" title="" aria-label="Search" data-toggle="tooltip" data-original-title="Search">
  <i class="fa-solid fa-magnifying-glass"></i>
</button>

Do we need to find some way to put an input in there for this to work? Or can we somehow get the sphinx RTD search to work with the button some other way?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.