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

When searching for a story by URL, the parse tree displayed for the search query omits that URL #1270

Open
roryokane opened this issue Apr 7, 2024 · 0 comments

Comments

@roryokane
Copy link

roryokane commented Apr 7, 2024

Bug description

When searching for a story by URL, such as https://lobste.rs/search?q=https%3A%2F%2Fghuntley.com%2Ffracture%2F&what=stories&order=newest, after expanding the “n results for” section, the parse tree that should be below “Search query parsed to:” is empty:

empty parse tree when searching for an existing story by URL

This empty parse tree is visible by default when there are no results:

empty parse tree shown by default when searching by URL with no results

For comparison, search terms that aren’t URLs (as in this search) are described in that section:

parse tree shows descriptions of terms other than the URL

The “Search query parsed to:” section should describe how the URL was parsed from the search, too.

Implementation suggestions

The search parse tree is displayed in this view:

<p>
Search query parsed to:
</p>
<dl class="search_parse">
<%
@search.parse_tree.each do |node|
type, value = node.first
case type
when :commenter %>

That case statement needs a when :url branch.

The chain of code that shows the parse tree should contain a :url key with the URL as its value

@search = Search.new(search_params, @user)

@parse_tree = if params[:q].present?
SearchParser.new.parse(params[:q])

root(:expression)

rule(:url) {
(
str("http") >> str("s").repeat(0, 1) >> str("://") >>
match("[A-Za-z0-9\\-_.:@/()%~?&=#]").repeat(1)
).as(:url) >> space?
}

.as(:url) ensures the resulting parse tree Hash will contain a :url key. See as described in Parslet’s parsing docs.

The ERB inside the new when :url branch should represent a dt element followed by a dd element, the same as all the other branches.

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

No branches or pull requests

1 participant