Looking for example java code to do a simple scalar search with WCS

I have a class named “document” which has a field/property named “content”.
To avoid adding a duplicate row, I want to first check that the content string does not already exist.

The java example here gets all the “content” values, but does not provide any clue on how to search for a particular value (Exact match)

  Field contentField = Field.builder().name(fieldName).build();
  Result<GraphQLResponse> graphQLResponse = client.graphQL()
  		.get()
  		.withClassName(className)
  		.withFields(contentField)
  		.run();

I’ve tried NearText and NearObject but both had their own issues.

Note: I was able to so a semantic vector search with no issues, if this simple scalar search does not work I will have to use that (with a certainty of 1.0)

Hey there @noob :wave:

Scalar search syntax and examples can be found here (GraphQL - Vector search parameters | Weaviate - vector database). It’s in the BM25 section as that is the ranking algorithm used. :slight_smile:

Or, for this particular use case, you might be able to use a filter as shown here (GraphQL - Conditional filters | Weaviate - vector database) with the Equal operator.

Cheers!
JP

1 Like

Thanks , the filter search worked fine.

		Field title = Field.builder().name(fieldName).build();
		WhereFilter where = WhereFilter.builder().path(new String[] { fieldName }).operator(Operator.Equal).valueText(searchText).build();

		WhereArgument whereArg = WhereArgument.builder().filter(where).build();

		Result<GraphQLResponse> result = weaviateClient.graphQL().get().withClassName(className).withFields(title).withWhere(whereArg).run();

Is there any expectation that this GraphQL search would be quicker? I’m seeing slower performance than a vector proximity search, while the vector search also spends time in vectorization.

Should I try BM25 and see if thats faster?