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

Add Java search filters examples #2656

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Tag("crud")
@Tag("search")
@Tag("basic")
public class BasicSearchTest {

private static WeaviateClient client;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.weaviate.docs.search;

import io.weaviate.client.Config;
import io.weaviate.client.WeaviateClient;
import io.weaviate.client.base.Result;
import io.weaviate.client.v1.filters.Operator;
import io.weaviate.client.v1.filters.WhereFilter;
import io.weaviate.client.v1.graphql.model.GraphQLResponse;
import io.weaviate.client.v1.graphql.query.argument.WhereArgument;
import io.weaviate.client.v1.graphql.query.fields.Field;
import io.weaviate.docs.helper.EnvHelper;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Tag("search")
@Tag("filters")
public class FiltersSearchTest {
private static WeaviateClient client;

@BeforeAll
public static void beforeAll() {
String scheme = EnvHelper.scheme("http");
String host = EnvHelper.host("localhost");
String port = EnvHelper.port("8080");

Config config = new Config(scheme, host + ":" + port);
client = new WeaviateClient(config);

Result<Boolean> result = client.schema().allDeleter().run();
assertThat(result).isNotNull()
.withFailMessage(() -> result.getError().toString())
.returns(false, Result::hasErrors)
.withFailMessage(null)
.returns(true, Result::getResult);
}

@Test
public void shouldPerformVectorSearch() {
filterWithOneCondition();
}

private void filterWithOneCondition() {
// START SingleFilter
Result<GraphQLResponse> result = client.graphQL().get()
.withClassName("JeopardyQuestion")
.withFields(
Field.builder().name("question").build(),
Field.builder().name("answer").build(),
Field.builder().name("round").build()
)
// highlight-start
.withWhere(WhereArgument.builder()
.filter(WhereFilter.builder()
.path("round")
.operator(Operator.Equal)
.valueString("Double Jeopardy!")
.build()
).build())
// highlight-end
.withLimit(3)
.run();
// END SingleFilter
assertThat(result).isNotNull()
.extracting(Result::getResult).isNotNull();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Tag("crud")
@Tag("search")
@Tag("vector-search")
public class VectorSearchTest {

Expand Down
10 changes: 10 additions & 0 deletions developers/weaviate/search/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import PyCodeV3 from '!!raw-loader!/_includes/code/howto/search.filters-v3.py';
import JavaScriptCode from '!!raw-loader!/_includes/code/howto/search.filters.ts';
import JavaScriptCodeLegacy from '!!raw-loader!/_includes/code/howto/search.filters-v2.ts';
import GoCode from '!!raw-loader!/_includes/code/howto/go/docs/mainpkg/search-filters_test.go';
import JavaCode from '!!raw-loader!/_includes/code/howto/java/src/test/java/io/weaviate/docs/search/FiltersSearchTest.java';


Filters let you include, or exclude, particular objects from your result set based on provided conditions.<br/>
Expand Down Expand Up @@ -68,6 +69,15 @@ Add a `filter` to your query, to limit the result set.
/>
</TabItem>

<TabItem value="java" label="Java">
<FilteredTextBlock
text={JavaCode}
startMarker="// START SingleFilter"
endMarker="// END SingleFilter"
language="java"
/>
</TabItem>

<TabItem value="graphql" label="GraphQL">
<FilteredTextBlock
text={PyCodeV3}
Expand Down