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

improve search #749

Merged
merged 7 commits into from
Sep 4, 2024
Merged

improve search #749

merged 7 commits into from
Sep 4, 2024

Conversation

asuworks
Copy link
Contributor

@asuworks asuworks commented Aug 2, 2024

@asuworks asuworks requested review from alee and sgfost August 2, 2024 21:15
@@ -45,5 +45,12 @@
{% endblock %}

{% block js %}
<script nonce="{{ request.csp_nonce }}" >
{% if language_facets %}
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be passed in as a data attribute on the sidebar div instead? theres a function extractDataParams to help with this on the js side

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean without attaching language_facets to window global variable?

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah like

<div id="sidebar" {% if language_facets %} data-language-facets="{{ language_facets }}" {% endif %} />

mostly for consistency, not sure if there's any meaningful practical difference

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In what file would you do this? As I understand this, we'd need to do this in jinja, but we need the data in the vue component... I am lost here.. help, please!

Copy link
Contributor

Choose a reason for hiding this comment

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

this one, the js side parses it with extractDataParams before mounting the component and passing the extracted stuff as props. Most mounting scripts in /apps do it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, got it! thanks!

@alee alee changed the title 21 search improvements improve search Aug 3, 2024
Copy link
Member

@alee alee left a comment

Choose a reason for hiding this comment

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

thanks @asuworks this looks great! still need to test & deploy locally but some minor coding style recommendations.

I think we should try to keep our logging formats consistent throughout the codebase but the format strings are definitely easier to read with lots of parameters...

placeholder="{{ placeholder }}">
<button type="submit" class="btn btn-primary">
<i class="fas fa-search px-1"></i>
</button>
</div>
{% if query_params %}
{% set params = query_params.split('&') %}
Copy link
Member

Choose a reason for hiding this comment

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

think we can move this param splitting logic out of the template and into Python? Perhaps as a method in jinja globals that takes search params and generates a set of name/value hidden input pairs.

if key == "tags":
elif key == "ordering":
for v in values:
if v == "":
Copy link
Member

Choose a reason for hiding this comment

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

should this first condition be an else clause fallback instead?

filters.append("Sort by: Publish date: oldest")
elif v == "-last_modified":
filters.append("Sort by: Recently Modified")
elif key == "tags":
filters.extend(tag for tag in values)
Copy link
Member

Choose a reason for hiding this comment

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

isn't this the same as filters.extend(values)

for v in values:
if v == "":
filters.append("Sort by: Relevance")
elif v == "-first_published_at":
Copy link
Member

Choose a reason for hiding this comment

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

this conditional mapping might be better organized as a defaultdict data structure like

from collections import defaultdict

SORT_BY_FILTERS = defaultdict(
        lambda v: return "Sort by: Relevance",
        {
            "-first_published_at": "Sort by: Publish date: newest",
            "first_published_at": "Sort by: Publish date: oldest",
            ...
        }
    )

Then this turns into filters.append(SORT_BY_FILTERS[v])

Args:
query: request query
data: results from Elasticsearch
current_page_number: request parameter
Copy link
Member

Choose a reason for hiding this comment

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

args docstring should be renamed to page as well? also not sure what request parameter means, is this the integer page value from the query params?

if criteria:
logger.debug(f"criteria={criteria}")
Copy link
Member

Choose a reason for hiding this comment

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

This is a very minor note but for codebase consistency make sure logger statements are of the form

logger.debug("criteria=%s", criteria)

See https://pylint.readthedocs.io/en/stable/user_guide/messages/warning/logging-fstring-interpolation.html for more context but there's also this rabbit hole pylint-dev/pylint#2395

except FieldError:
logger.warning("Invalid filter criteria: %s", criteria)
except FieldError as e:
logger.warning(f"Invalid filter criteria: {criteria}. Error: {str(e)}")
Copy link
Member

Choose a reason for hiding this comment

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

use exc_info=e instead of converting the exception into a string and missing out on the entire stack trace

@@ -3,10 +3,12 @@ import { useAxios, type RequestOptions } from "@/composables/api";

interface CodebaseQueryParams {
query?: string;
publishedAfter?: string;
publishedBefore?: string;
published_after?: string;
Copy link
Member

@alee alee Aug 3, 2024

Choose a reason for hiding this comment

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

is this to line up with the incoming query parameters? otherwise camelCase would be preferred

@asuworks asuworks marked this pull request as draft August 5, 2024 18:01
@asuworks asuworks self-assigned this Aug 5, 2024
Copy link
Contributor

@sgfost sgfost left a comment

Choose a reason for hiding this comment

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

Nice. Filter sidebar looks great and the search querying anecdotally seems a lot better

The default query should probably go back to ordering things by publish date descending though

I like the new selected filter terms display better than the one that comes from the paginator macro at the top. In the case of codebases should we disable those and just use the sidebar ones so we aren't showing that information in two places? If so it could:

  1. get moved to the top of the sidebar
  2. only show up when those filters are applied
  3. have a button to clear all

@asuworks
Copy link
Contributor Author

asuworks commented Aug 5, 2024

thanks @asuworks this looks great! still need to test & deploy locally but some minor coding style recommendations.

I think we should try to keep our logging formats consistent throughout the codebase but the format strings are definitely easier to read with lots of parameters...

thanks @alee! fixed it!

@asuworks
Copy link
Contributor Author

asuworks commented Aug 5, 2024

@sgfost

  1. agree about the default ordering by Publish date: newest
  2. agree about removing the filter tags and the red clear button from under the searchbar. Leave only the text: Displaying 4 of 4 results for 'lala' @alee ?
  3. moving selected filters in the sidebar to the top would make the filtering ui elements jump up and down.. I'd say it's better to keep the selected filter tags at the bottom.

@sgfost
Copy link
Contributor

sgfost commented Aug 5, 2024

the issue I have is that the whole sidebar is like 1000px tall without filters so you have to scroll up and down to do stuff, maybe it can be shrunk down to something more manageable? If the selected filters only appear when applied (which I think is what should happen) it may be less of an issue since the page would reload anyways.

Could also just apply on selection, I don't think we have nearly enough different filters to make that a problem, even without AJAX searching

@asuworks
Copy link
Contributor Author

asuworks commented Aug 5, 2024

how about programming languages in 2 columns?

image

@asuworks
Copy link
Contributor Author

asuworks commented Aug 5, 2024

we could also remove the "Publish a model" button (I think it is not very necessary there)

@sgfost
Copy link
Contributor

sgfost commented Aug 5, 2024

the publish button should be somewhere on that page, maybe gets moved to whatever we replace that blue alert box with. The counts wrapping over looks a bit odd, what about collapsing it by default? Or showing just a few with a show more button.

Other stuff could probably be shrunk down too, padding, margins, text size, etc. The publish date filters can be together in one row

@asuworks
Copy link
Contributor Author

asuworks commented Aug 5, 2024

image

@asuworks
Copy link
Contributor Author

asuworks commented Aug 5, 2024

much nicer and shorter :)

@asuworks
Copy link
Contributor Author

asuworks commented Aug 5, 2024

the wrapping is not nice, agree... maybe back to single column? The collapsing of the programming languages would complicate the ui I think...
image

@sgfost
Copy link
Contributor

sgfost commented Aug 6, 2024

pretty sure thats the only link to publishing a model, I wouldn't want to suddenly move it. Regardless it still hardly fits on my screen

How does this UI look? I squished things down a bit and removed the apply button assuming we can apply everything on selection. If not, then the selected filters can sit at the bottom with the apply button since most screens should have the full thing in view. There should at least be a way to clear them from the top though

Screenshot 2024-08-05 at 17-02-34 CoMSES Net Computational Model Library

@asuworks
Copy link
Contributor Author

asuworks commented Aug 6, 2024

@sgfost I implemented your version. When selecting a checkbox or a radio in the sidebar, the ui jumps down because the selected filters are populated at the top... not so nice... maybe put them back at the bottom?

@sgfost
Copy link
Contributor

sgfost commented Aug 6, 2024

I had in mind only displaying them when they are actually applied. I suppose that may still pose an issue if things are applied on selection.. Its probably fine at the bottom as long as the whole thing isn't too tall

@asuworks
Copy link
Contributor Author

asuworks commented Aug 8, 2024

Today we talked about showing selected filter badges in the sidebar on page load...
I decided to get rid of them completely, since it seemed like an unnecessary duplication of the badges we display under the searchbar. What do you think?

@alee alee force-pushed the 21-search-improvements branch from b155636 to b5cd979 Compare August 30, 2024 21:32
@alee alee marked this pull request as ready for review August 30, 2024 22:05
@alee alee force-pushed the 21-search-improvements branch from b5cd979 to 42c2760 Compare August 30, 2024 23:44
@alee
Copy link
Member

alee commented Aug 30, 2024

@all-contributors please add @sgfost for doc, review, maintenance, mentoring

Copy link
Contributor

@alee

This project's configuration file has malformed JSON: .all-contributorsrc. Error:: Unexpected token ] in JSON at position 2854

@alee alee force-pushed the 21-search-improvements branch from 42c2760 to 096bce2 Compare August 30, 2024 23:56
@alee
Copy link
Member

alee commented Aug 30, 2024

@all-contributors please add @asuworks for code, doc

Copy link
Contributor

@alee

This project's configuration file has malformed JSON: .all-contributorsrc. Error:: Unexpected token ] in JSON at position 2854

@alee alee force-pushed the 21-search-improvements branch from 096bce2 to 52da007 Compare August 31, 2024 01:13
@alee alee force-pushed the 21-search-improvements branch 4 times, most recently from 1c053ac to 4a18fb0 Compare September 4, 2024 00:00
asuworks and others added 7 commits September 3, 2024 17:01
set `max_result_window` and guard bad `page` parameter requests for
/codebases/ and /search/
add programming languages and better search queries for codebases
- enhance elasticsearch query
- remove excessive logging
- use data attribute to pass props to vue component instead of attaching
to the global window object
- minor refactoring and cleanup
- set initial ordering of codebases to published date: newest
- add stopwords for codebase library search
- rearrange codebase filtering sidebar ui
1. On initial page load, codebases are sorted by date: newest.
2. On first search, results are sorted by relevance
3. Disable buttons in the sidebar when loading
4. Disable "Apply filters" button if filters are unchanged
- add basic test for codebase search
- use lodash instead of rolling our own deep equality function,
  https://lodash.com/docs#isEqual

- add programming language facets to query string directly if selected
- could also switch back to @asuwork's original implementation that
  generated ran a second query, e.g.,

```
codebases = Codebase.objects.filter(releases__programming_languages__name__in=programming_languages)
criteria.update(id__in=codebases.values_list('pk', flat=True))
```

to avoid filter on related fields limitations in wagtailsearch
```
Cannot filter search results with field "name". Please add index.FilterField('name') to Codebase.search_fields.
```
@alee alee force-pushed the 21-search-improvements branch from 4a18fb0 to c20ee16 Compare September 4, 2024 00:04
@alee alee merged commit e5eab87 into comses:main Sep 4, 2024
7 checks passed
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.

3 participants