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

Added switch based mapping for filters in searchbar #448

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ShashaankS
Copy link
Contributor

Resolves #305

  • Added filters functionality to the projects index, with some filters like contributors>10, stars<100, is:tool, is:documentation.

There is a provision for other indexes also but github like filters may be not meaningful.

Screenshot from 2025-01-13 17-35-31

Screenshot from 2025-01-13 17-35-22

there are some configs to bet set on algolia app:
Screenshot from 2025-01-13 14-38-42

Copy link
Collaborator

@arkid15r arkid15r left a comment

Choose a reason for hiding this comment

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

This works!

Please add some tests for your code.
Also you can change the index settings programmatically.

Comment on lines +6 to +15
case /^contributors([><]=?|=)(\d+)$/.test(filter):
return filter.replace(/^contributors([><]=?|=)(\d+)$/, 'idx_contributors_count$1$2')
case /^stars([><]=?|=)(\d+)$/.test(filter):
return filter.replace(/^stars([><]=?|=)(\d+)$/, 'idx_stars_count$1$2')
case /^forks([><]=?|=)(\d+)$/.test(filter):
return filter.replace(/^forks([><]=?|=)(\d+)$/, 'idx_forks_count$1$2')
case /^is:([a-zA-Z]+)$/.test(filter):
return filter.replace(/^is:([a-zA-Z]+)$/, 'idx_type:$1')
default:
return filter
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we extend it to datetime fields (created/updated) too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arkid15r We can do that, how the user will input the dates?
Is it like 1sep24 or 01092024 or ?
As the index contains the that flied in UNIX timestamp

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ShashaankS we can always convert the dates into desirable format.

export const getParamsForFilters = (indexName: string, filter: string) => {
filter = filter.trim()
switch (indexName) {
case 'projects':
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about contribute page (issues), will it be addressed in a separate PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have gone through the issues index, its most of the attributes are seachable,
only attribute we can use was comments<10 or is:open is:close
Even there is no attribute for open and close

Copy link
Collaborator

@Rajgupta36 Rajgupta36 Jan 15, 2025

Choose a reason for hiding this comment

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

I think we can also add languages and topics based filtering in contribute page

Copy link
Collaborator

@Rajgupta36 Rajgupta36 left a comment

Choose a reason for hiding this comment

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

1.is: documentation is working but for this is:documentation no result same as in case of project. can we trim space and add one space automatically

2.also when I write dual query in search bar is: documentation, stars<10 or is: documentation stars<10 or is: documentation,star>10 the result is something like second param override first one can we add multiple query support together

3.suppose this is the query stars<10@ it throws error on page but i think it should return no project found something. look at filters
image

i think there are some regex error pls fix that

let filters = ''
let searchQuery = query

const filterRegex = /(\w+)([:><=!]+)([^ ]+)/g
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we put this logic in another function

@@ -17,17 +18,37 @@ export const fetchAlgoliaData = async <T>(
}
try {
const params = getParamsForIndexName(indexName)

let filters = ''
let searchQuery = query
Copy link
Collaborator

@Rajgupta36 Rajgupta36 Jan 15, 2025

Choose a reason for hiding this comment

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

Could you please define the types for this? Otherwise, we may unintentionally mutate the variable from a string to another type, which could lead to unexpected behavior.

Copy link
Collaborator

@harsh3dev harsh3dev left a comment

Choose a reason for hiding this comment

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

@arkid15r @ShashaankS I think Raj has already suggested some changes.
I think there should be more parameters across pages to use.
Also please include tests for this PR.

I have a question: Currently there is no way users can know what are all the available options for filters. So should that be tackled in the new issue?

Thanks.

@kasya
Copy link
Collaborator

kasya commented Jan 18, 2025

I have a question: Currently there is no way users can know what are all the available options for filters. So should that be tackled in the new issue?

This was also my concern. We could do something like a sample of possible options bellow the search bar or a link with a modal to look those up. Anything like that should help. Without it it's super unclear how to use search this way if person never had experience with this type of search before.
Example from task management tool that I've used:
Screenshot 2025-01-18 at 2 22 06 PM

Copy link
Collaborator

@kasya kasya left a comment

Choose a reason for hiding this comment

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

@arkid15r @ShashaankS Should we proceed as is and add possible options later on?
I still need to review it on the frontend, just wanted to make sure it's not still work in progress.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend search bar to accept filter queries
5 participants