Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The addition of partial search support in the HTML builds has a logic error #6824

Closed
JustinMaxwell opened this issue Nov 15, 2019 · 3 comments

Comments

@JustinMaxwell
Copy link

Describe the bug
In certain edge cases, the 'Search module' in searchtools.js will exit the 'performTermsSearch' method early (in the 'check if all requirements are matched' section), resulting in no results being returned, when there should be results returned.

To Reproduce
Steps to reproduce the behavior:
There may be other ways that this error manifest, but I'll give the simplest steps that I'm aware of.

  1. quick-start a project
  2. add a directory ('foo') and a page ('bar.rst') within foo directory
  3. add foo to the index.rst, and change the max depth to 1
  4. in bar.rst, add a title ('test title')
  5. add some paragraph text containing the term 'mysql' and no other terms that include 'sql'
  6. add a section title containing the term 'sql' and no other terms that include 'sql'
  7. finally do a search for sql. It should return no results if the bug manifest.

Expected behavior
A clear and concise description of what you expected to happen.
The 'performTermsSearch' method was created before 'support for partial matching' was added earlier this year. The partial matching allows for a condition where a partial match can exist in the 'titleterms' and a full match can exist in the 'terms'. Whereas the performTermsSearch method is coded expecting for this condition of matches in both titleterms and terms to never be able to occur.

Additional context
I think the fix is within these two code blocks.

        // set score for the word in each file to Scorer.term
        for (j = 0; j < _files.length; j++) {
          file = _files[j];
          if (!(file in scoreMap))
            scoreMap[file] = {}
--------->else if (word in scoreMap[file])
----------->scoreMap[file][word] += o.score;
--------->else
----------->scoreMap[file][word] = o.score;
        }
      });

      // create the mapping
      for (j = 0; j < files.length; j++) {
        file = files[j];
        if (file in fileMap) {
--------->if (!(fileMap[file].includes(word)))
              fileMap[file].push(word);
        }
        else
          fileMap[file] = [word];
      }
    }


@JustinMaxwell
Copy link
Author

This is almost certainly related to Issue #6783.
Partial matched added by @TimKam.

@tk0miya
Copy link
Member

tk0miya commented Nov 16, 2019

@TimKam Could you check this please?

@TimKam
Copy link
Member

TimKam commented Nov 17, 2019

Thanks for reporting. I will check.

TimKam added a commit that referenced this issue Nov 17, 2019
Prevent duplicate additions of terms to a file in ``fileMap``
TimKam added a commit that referenced this issue Nov 17, 2019
TimKam added a commit that referenced this issue Nov 20, 2019
Prevent duplicate additions of terms to a file in ``fileMap``
TimKam added a commit that referenced this issue Nov 20, 2019
TimKam added a commit that referenced this issue Nov 20, 2019
* #6824: Fix search logic (front end)

Prevent duplicate additions of terms to a file in ``fileMap``, document search fix in change log
@TimKam TimKam closed this as completed Nov 20, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants