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

Small search improvement. #724

Merged
merged 9 commits into from
Mar 29, 2022
Merged

Small search improvement. #724

merged 9 commits into from
Mar 29, 2022

Conversation

mgautierfr
Copy link
Member

@mgautierfr mgautierfr commented Mar 9, 2022

This PR fixes small issues found on search handling on the server.
It is somehow a preparatory work for openSearch feature coming soon.

Fixes #723

Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second commit (the one titled "Introduce SearchInfo.") is a little two big and a little too different to validate. It will benefit from being split into smaller changes.

src/server/internalServer.cpp Outdated Show resolved Hide resolved
<h1>Invalid request</h1>
{{#url}}
<p>
The requested URL "{{.}}" is not a valid request.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The {.} mustache syntax is a revelation for me. Is it documented?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot find it in the mustache manual (https://mustache.github.io/mustache.5.html)
But it is in kainjow mustache library : https://github.com/kainjow/Mustache/blob/master/tests/tests.cpp#L273-L281

test/server.cpp Outdated Show resolved Hide resolved
src/server/internalServer.cpp Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 9, 2022

Codecov Report

Merging #724 (701a416) into master (574c1ad) will increase coverage by 0.66%.
The diff coverage is 70.87%.

❗ Current head 701a416 differs from pull request most recent head 311f783. Consider uploading reports for the commit 311f783 to get more accurate results

@@            Coverage Diff             @@
##           master     #724      +/-   ##
==========================================
+ Coverage   58.31%   58.98%   +0.66%     
==========================================
  Files          56       56              
  Lines        3697     3735      +38     
  Branches     2069     2083      +14     
==========================================
+ Hits         2156     2203      +47     
+ Misses       1540     1531       -9     
  Partials        1        1              
Impacted Files Coverage Δ
src/server/internalServer.cpp 79.13% <59.72%> (-2.07%) ⬇️
src/server/internalServer.h 88.88% <93.75%> (+55.55%) ⬆️
src/server/response.cpp 88.65% <100.00%> (+0.70%) ⬆️
src/server/response.h 100.00% <100.00%> (ø)
src/tools/stringTools.cpp 50.00% <0.00%> (+1.00%) ⬆️
src/search_renderer.cpp 89.33% <0.00%> (+24.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 574c1ad...311f783. Read the comment docs.

@veloman-yunkan
Copy link
Collaborator

@mgautierfr I reviewed the PR again before realizing that you forgot to push your changes.

@kelson42
Copy link
Collaborator

@mgautierfr Can we move one please with this PR?

@veloman-yunkan
Copy link
Collaborator

@mgautierfr Can we move one please with this PR?

@kelson42 I would like to bring to your attention the situation with this PR described in #727 (comment). If we postpone this PR until the preparatory work for internationalizing kiwix-serve is completed, then it can be rewritten in a slightly cleaner way (while at the same time minimizing the need for addressing conflicts in a larger WIP PR #679).

@kelson42
Copy link
Collaborator

kelson42 commented Mar 23, 2022

@veloman-yunkan Not against the principle, but concerned about the overall timelime and interdependences. Considering that we have an XSS issue in the field with kiwix-serve... I would like that we consider a minor release within the next 2-3 weeks.

@mgautierfr
Copy link
Member Author

The "problem" is that this PR is somehow a preparatory work for other PRs introducing opensearch feature.
And I'm affraid #679 will not be merged soon. But we will have merge conflicts and we must minimize them. I can rebase this PR on #727 easyily.
@veloman-yunkan will it be enough ? If not, can you extract another preparatory PR from #679 (And rebase this PR on your newly created PR) ?

@veloman-yunkan
Copy link
Collaborator

I can rebase this PR on #727 easyily. @veloman-yunkan will it be enough ?

No

If not, can you extract another preparatory PR from #679 (And rebase this PR on your newly created PR) ?

I will do it tomorrow.

@mgautierfr
Copy link
Member Author

mgautierfr commented Mar 23, 2022

Rebased on last master (with #727 merged)
(The interesting commit the review are the two "fixup!" commit and the last one)

@veloman-yunkan
Copy link
Collaborator

If not, can you extract another preparatory PR from #679 (And rebase this PR on your newly created PR) ?

I will do it tomorrow.

The new PR extracted from #679 is #732. Unfortunately, a few changes that I intended to include in #732 were too tightly coupled with internationalization of kiwix-serve so I left them for another smaller follow-up PR.

@kelson42
Copy link
Collaborator

@mgautierfr I guess this is now ready to fix/merge.

HTTP400HtmlResponse is build on the same design than HTTP404HtmlResponse.
@mgautierfr
Copy link
Member Author

Rebased on master (with #732 merged)

Copy link
Collaborator

@veloman-yunkan veloman-yunkan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. But I am also including couple of optional suggestions for minor improvements that could be made while moving the code around.

src/server/internalServer.cpp Outdated Show resolved Hide resolved
src/server/internalServer.cpp Outdated Show resolved Hide resolved
src/server/internalServer.h Outdated Show resolved Hide resolved
@mgautierfr
Copy link
Member Author

I've fixed your comment in two fixup commits

}

public: //data
std::string pattern;
bool has_geo_query;
GeoQuery geo_query;
std::pair<bool, GeoQuery> geoQuery;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this. A better solution is to take advantage of the fact that GeoQuery can have an invalid state (for example when distance < 0) without adding a new data field to it. Add a proper default constructor to GeoQuery and a bool isValid() const member function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with a operator bool operator

src/server/internalServer.h Outdated Show resolved Hide resolved
SearchInfo is a small helper structure to store information about the
queried search. It regroup already existing information (`patternString`,
geo query, ...) in one structure.
It is also used as key in the cache instead of using a generated string.
It is better to directly try to get the `Search` from the cache instead
of getting the `Searcher` first which could be useless in Search already
exist.
If user request for a non existent book, we must return a 400 page.
(This is done by throwing a `std::invalid_argument` and let the catch
handle it)
The `searchPattern` is already "diples encoded".
So we can simply using it without protecting us from script injection.

Fix #723
There is no reason to not use the pattern if there is a geo_query.
If both the pattern and the qeo_query are provided, we must use both.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong html entities in kiwix-serve ft result page
3 participants