-
Notifications
You must be signed in to change notification settings - Fork 0
Implement support for local filtering #14
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,9 @@ | |
| */ | ||
| package io.getstream.android.core.api.filter | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated to this PR: I can see that the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember @aleksandar-apostolov not being fully convinced about the
It also suggested other stuff, but I don't think they're fitting
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was not convinced because it was called Here is Codex opinion btw:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to clarify I asked Codex "Is
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I took Petar's first suggestion and moved sort code to its own package, so we avoid the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks good to me! |
||
|
|
||
| import io.getstream.android.core.internal.filter.FilterOperator | ||
| import io.getstream.android.core.annotations.StreamPublishedApi | ||
| import io.getstream.android.core.internal.filter.BinaryOperator | ||
| import io.getstream.android.core.internal.filter.CollectionOperator | ||
|
|
||
| /** Utility class for building filters. */ | ||
| public object Filters { | ||
|
|
@@ -25,17 +27,19 @@ public object Filters { | |
| * @param filters The filters to combine. | ||
| * @return A filter that matches when all provided filters match. | ||
| */ | ||
| public fun <F : FilterField> and(vararg filters: Filter<F>): Filter<F> = | ||
| CollectionOperationFilter(FilterOperator.AND, filters.toSet()) | ||
| @StreamPublishedApi | ||
| public fun <M, F : FilterField<M>> and(vararg filters: Filter<M, F>): Filter<M, F> = | ||
| CollectionOperationFilter(CollectionOperator.AND, filters.toSet()) | ||
|
|
||
| /** | ||
| * Creates a filter that combines multiple filters with a logical OR operation. | ||
| * | ||
| * @param filters The filters to combine. | ||
| * @return A filter that matches when any of the specified filters match. | ||
| */ | ||
| public fun <F : FilterField> or(vararg filters: Filter<F>): Filter<F> = | ||
| CollectionOperationFilter(FilterOperator.OR, filters.toSet()) | ||
| @StreamPublishedApi | ||
| public fun <M, F : FilterField<M>> or(vararg filters: Filter<M, F>): Filter<M, F> = | ||
VelikovPetar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| CollectionOperationFilter(CollectionOperator.OR, filters.toSet()) | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -44,111 +48,124 @@ public object Filters { | |
| * @param value The value to check equality against. | ||
| * @return A filter that matches when this field equals the specified value. | ||
| */ | ||
| public fun <F : FilterField> F.equal(value: Any): Filter<F> = | ||
| BinaryOperationFilter(FilterOperator.EQUAL, this, value) | ||
| @StreamPublishedApi | ||
| public fun <M, F : FilterField<M>> F.equal(value: Any): Filter<M, F> = | ||
| BinaryOperationFilter(BinaryOperator.EQUAL, this, value) | ||
|
|
||
| /** | ||
| * Creates a filter that checks if this field is greater than a specific value. | ||
| * | ||
| * @param value The value to check against. | ||
| * @return A filter that matches when this field is greater than the specified value. | ||
| */ | ||
| public fun <F : FilterField> F.greater(value: Any): Filter<F> = | ||
| BinaryOperationFilter(FilterOperator.GREATER, this, value) | ||
| @StreamPublishedApi | ||
| public fun <M, F : FilterField<M>> F.greater(value: Any): Filter<M, F> = | ||
| BinaryOperationFilter(BinaryOperator.GREATER, this, value) | ||
|
|
||
| /** | ||
| * Creates a filter that checks if this field is greater than or equal to a specific value. | ||
| * | ||
| * @param value The value to check against. | ||
| * @return A filter that matches when this field is greater than or equal to the specified value. | ||
| */ | ||
| public fun <F : FilterField> F.greaterOrEqual(value: Any): Filter<F> = | ||
| BinaryOperationFilter(FilterOperator.GREATER_OR_EQUAL, this, value) | ||
| @StreamPublishedApi | ||
| public fun <M, F : FilterField<M>> F.greaterOrEqual(value: Any): Filter<M, F> = | ||
| BinaryOperationFilter(BinaryOperator.GREATER_OR_EQUAL, this, value) | ||
|
|
||
| /** | ||
| * Creates a filter that checks if this field is less than a specific value. | ||
| * | ||
| * @param value The value to check against. | ||
| * @return A filter that matches when this field is less than the specified value. | ||
| */ | ||
| public fun <F : FilterField> F.less(value: Any): Filter<F> = | ||
| BinaryOperationFilter(FilterOperator.LESS, this, value) | ||
| @StreamPublishedApi | ||
| public fun <M, F : FilterField<M>> F.less(value: Any): Filter<M, F> = | ||
| BinaryOperationFilter(BinaryOperator.LESS, this, value) | ||
|
|
||
| /** | ||
| * Creates a filter that checks if this field is less than or equal to a specific value. | ||
| * | ||
| * @param value The value to check against. | ||
| * @return A filter that matches when this field is less than or equal to the specified value. | ||
| */ | ||
| public fun <F : FilterField> F.lessOrEqual(value: Any): Filter<F> = | ||
| BinaryOperationFilter(FilterOperator.LESS_OR_EQUAL, this, value) | ||
| @StreamPublishedApi | ||
| public fun <M, F : FilterField<M>> F.lessOrEqual(value: Any): Filter<M, F> = | ||
| BinaryOperationFilter(BinaryOperator.LESS_OR_EQUAL, this, value) | ||
|
|
||
| /** | ||
| * Creates a filter that checks if this field's value is in a specific list of values. | ||
| * | ||
| * @param values The list of values to check against. | ||
| * @return A filter that matches when this field's value is in the specified list. | ||
| */ | ||
| public fun <F : FilterField> F.`in`(values: List<Any>): Filter<F> = | ||
| BinaryOperationFilter(FilterOperator.IN, this, values.toSet()) | ||
| @StreamPublishedApi | ||
| public fun <M, F : FilterField<M>> F.`in`(values: List<Any>): Filter<M, F> = | ||
| BinaryOperationFilter(BinaryOperator.IN, this, values.toSet()) | ||
|
|
||
| /** | ||
| * Creates a filter that checks if this field's value is in a specific set of values. | ||
| * | ||
| * @param values The values to check against. | ||
| * @return A filter that matches when this field's value is in the specified values. | ||
| */ | ||
| public fun <F : FilterField> F.`in`(vararg values: Any): Filter<F> = | ||
| BinaryOperationFilter(FilterOperator.IN, this, values.toSet()) | ||
| @StreamPublishedApi | ||
| public fun <M, F : FilterField<M>> F.`in`(vararg values: Any): Filter<M, F> = | ||
| BinaryOperationFilter(BinaryOperator.IN, this, values.toSet()) | ||
|
|
||
| /** | ||
| * Creates a filter that performs a full-text query on this field. | ||
| * | ||
| * @param value The query string to search for. | ||
| * @return A filter that matches based on the full-text query. | ||
| */ | ||
| public fun <F : FilterField> F.query(value: String): Filter<F> = | ||
| BinaryOperationFilter(FilterOperator.QUERY, this, value) | ||
| @StreamPublishedApi | ||
| public fun <M, F : FilterField<M>> F.query(value: String): Filter<M, F> = | ||
| BinaryOperationFilter(BinaryOperator.QUERY, this, value) | ||
|
|
||
| /** | ||
| * Creates a filter that performs autocomplete matching on this field. | ||
| * | ||
| * @param value The string to autocomplete against. | ||
| * @return A filter that matches based on autocomplete functionality. | ||
| */ | ||
| public fun <F : FilterField> F.autocomplete(value: String): Filter<F> = | ||
| BinaryOperationFilter(FilterOperator.AUTOCOMPLETE, this, value) | ||
| @StreamPublishedApi | ||
| public fun <M, F : FilterField<M>> F.autocomplete(value: String): Filter<M, F> = | ||
| BinaryOperationFilter(BinaryOperator.AUTOCOMPLETE, this, value) | ||
|
|
||
| /** | ||
| * Creates a filter that checks if this field exists. | ||
| * | ||
| * @return A filter that matches when this field exists. | ||
| */ | ||
| public fun <F : FilterField> F.exists(): Filter<F> = | ||
| BinaryOperationFilter(FilterOperator.EXISTS, this, true) | ||
| @StreamPublishedApi | ||
| public fun <M, F : FilterField<M>> F.exists(): Filter<M, F> = | ||
| BinaryOperationFilter(BinaryOperator.EXISTS, this, true) | ||
|
|
||
| /** | ||
| * Creates a filter that checks if this field does not exist. | ||
| * | ||
| * @return A filter that matches when this field does not exist. | ||
| */ | ||
| public fun <F : FilterField> F.doesNotExist(): Filter<F> = | ||
| BinaryOperationFilter(FilterOperator.EXISTS, this, false) | ||
| @StreamPublishedApi | ||
| public fun <M, F : FilterField<M>> F.doesNotExist(): Filter<M, F> = | ||
| BinaryOperationFilter(BinaryOperator.EXISTS, this, false) | ||
|
|
||
| /** | ||
| * Creates a filter that checks if this field contains a specific value. | ||
| * | ||
| * @param value The value to check for within this field. | ||
| * @return A filter that matches when this field contains the specified value. | ||
| */ | ||
| public fun <F : FilterField> F.contains(value: Any): Filter<F> = | ||
| BinaryOperationFilter(FilterOperator.CONTAINS, this, value) | ||
| @StreamPublishedApi | ||
| public fun <M, F : FilterField<M>> F.contains(value: Any): Filter<M, F> = | ||
| BinaryOperationFilter(BinaryOperator.CONTAINS, this, value) | ||
|
|
||
| /** | ||
| * Creates a filter that checks if a specific path exists within this field. | ||
| * | ||
| * @param value The path to check for existence. | ||
| * @return A filter that matches when the specified path exists in this field. | ||
| */ | ||
| public fun <F : FilterField> F.pathExists(value: String): Filter<F> = | ||
| BinaryOperationFilter(FilterOperator.PATH_EXISTS, this, value) | ||
| @StreamPublishedApi | ||
| public fun <M, F : FilterField<M>> F.pathExists(value: String): Filter<M, F> = | ||
| BinaryOperationFilter(BinaryOperator.PATH_EXISTS, this, value) | ||


Uh oh!
There was an error while loading. Please reload this page.