private DeferredResult<List<ContainerState>> retrieveContainerStates( ContainerDescription cd) { logFine("Retrieving containers from container description: %s", cd.documentSelfLink); Builder builder = Builder.create() .addKindFieldClause(ContainerState.class) .addFieldClause(ContainerState.FIELD_NAME_DESCRIPTION_LINK, cd.documentSelfLink); QueryByPages<ContainerState> query = new QueryByPages<>(getHost(), builder.build(), ContainerState.class, null); return query.collectDocuments(Collectors.toList()); }
private DeferredResult<List<ContainerState>> retrieveContainerStates(String descriptionLink) { Builder builder = Builder.create() .addKindFieldClause(ContainerState.class) .addFieldClause(ContainerState.FIELD_NAME_DESCRIPTION_LINK, descriptionLink); QueryByPages<ContainerState> query = new QueryByPages<>(host, builder.build(), ContainerState.class, null); return query.collectDocuments(Collectors.toList()); }
private QueryTask makeQueryTask() { return QueryTask.Builder.createDirectTask() .setQuery(QueryTask.Query.Builder.create() .addKindFieldClause(ExampleServiceState.class) .addFieldClause(ExampleServiceState.FIELD_NAME_NAME, "a", MatchType.WILDCARD, Occurance.MUST_NOT_OCCUR) .addFieldClause(ExampleServiceState.FIELD_NAME_NAME, "c", MatchType.WILDCARD, Occurance.MUST_NOT_OCCUR) .addFieldClause(ExampleServiceState.FIELD_NAME_NAME, "5", MatchType.WILDCARD, Occurance.MUST_NOT_OCCUR) .build()) .setResultLimit(50) .build(); }
/** * Add a clause which matches a nested field value. * @param parentFieldName the top level field name. * @param nestedFieldName the nested field name. * @param nestedFieldValue the nested field value to match. * @return a reference to this object. */ public Builder addCompositeFieldClause(String parentFieldName, String nestedFieldName, String nestedFieldValue) { return addFieldClause( QuerySpecification.buildCompositeFieldName(parentFieldName, nestedFieldName), nestedFieldValue); }
/** * Add a {@link Occurance#MUST_OCCUR} clause which matches a top level field name using * {@link MatchType#TERM}. * @param fieldName the top level field name. * @param fieldValue the field value to match. * @return a reference to this object. */ public Builder addFieldClause(String fieldName, Object fieldValue) { return addFieldClause(fieldName, QuerySpecification.toMatchValue(fieldValue), MatchType.TERM, Occurance.MUST_OCCUR); }
@Test public void testLuceneQueryConversion() throws Throwable { Query topLevelQuery = Query.Builder.create() .addFieldClause("name", "foo", Occurance.SHOULD_OCCUR) .addFieldClause("id", "foo-id", Occurance.SHOULD_OCCUR) .build(); org.apache.lucene.search.Query luceneQuery = LuceneQueryConverter.convertToLuceneQuery(topLevelQuery, null); // Assert that the top level MUST_OCCUR is ignored ( old behavior ) assertEquals(luceneQuery.toString(), "name:foo id:foo-id"); luceneQuery = LuceneQueryConverter.convert(topLevelQuery, null); // Assert that the top level MUST_OCCUR is not ignored assertEquals(luceneQuery.toString(), "+(name:foo id:foo-id)"); }
private Long getDocumentCount(VerificationHost host, String factoryLink) { QueryTask queryTask = QueryTask.Builder .createDirectTask() .addOption(QueryOption.INCLUDE_ALL_VERSIONS) .addOption(QueryOption.COUNT) .setQuery( Query.Builder.create().addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, factoryLink, MatchType.PREFIX).build()) .build(); host.createQueryTaskService(queryTask, false, true, queryTask, null); return queryTask.results.documentCount; } }
public QueryTask createTagsQueryTask(boolean deletedTags) { Query.Builder query = Query.Builder.create() .addKindFieldClause(TagState.class); if (deletedTags) { query.addFieldClause(TagState.FIELD_NAME_DELETED, Boolean.TRUE); } else { query.addFieldClause(TagState.FIELD_NAME_DELETED, Boolean.FALSE); } return QueryTask.Builder.createDirectTask() .addOption(QueryOption.EXPAND_CONTENT) .setQuery(query.build()) .build(); }
/** * Generates a query that finds all computes which resource pool link points to this resource * pool. Applicable to non-elastic pools only. */ private Query generateResourcePoolQuery(ResourcePoolState initState) { Query query = Query.Builder.create() .addKindFieldClause(ComputeState.class) .addFieldClause(ComputeState.FIELD_NAME_RESOURCE_POOL_LINK, getSelfLink()) .build(); return query; } }
private void doThroughputPostWithNoQueryResults(boolean interleaveQueries, URI factoryUri) throws Throwable { // Create a query which will match no documents. This code path is designed to simulate // the cost of queries on the index without incurring the cost of processing results. QueryTask queryTask = QueryTask.Builder.createDirectTask() .setQuery(Query.Builder.create() .addFieldClause(ExampleServiceState.FIELD_NAME_ID, "saffsdfs") .build()) .build(); queryTask.indexLink = this.indexLink; doThroughputPost(interleaveQueries, factoryUri, null, queryTask); }
private Query buildFieldClause(State initState) { Query query = Query.Builder.create() .addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, addSlash(initState.sourceFactoryLink), QueryTask.QueryTerm.MatchType.PREFIX) .build(); return query; }
/** * Add a clause which matches a collection item. * @param collectionFieldName the collection field name. * @param itemName the item name in the collection to match. * @return a reference to this object. */ public Builder addCollectionItemClause(String collectionFieldName, String itemName) { return addFieldClause( QuerySpecification.buildCollectionItemName(collectionFieldName), itemName); }
/** * Add a clause with the specified occurance which matches the * {@linkplain ServiceDocument#documentKind document kind} of the provided class. * @param documentClass the service document class. * @param occurance the occurance for this clause. * @return a reference to this object. */ public Builder addKindFieldClause(Class<? extends ServiceDocument> documentClass, Occurance occurance) { return addFieldClause(FIELD_NAME_KIND, Utils.buildKind(documentClass), occurance); }
/** * Add a clause which matches the {@linkplain ServiceDocument#documentKind document kind} of the provided class. * @param documentClass the service document class. * @return a reference to this object. */ public Builder addKindFieldClause(Class<? extends ServiceDocument> documentClass) { return addFieldClause(FIELD_NAME_KIND, Utils.buildKind(documentClass)); }
private void doThroughputPostWithNoQueryResults(boolean interleaveQueries, URI factoryUri) throws Throwable { // Create a query which will match no documents. This code path is designed to simulate // the cost of queries on the index without incurring the cost of processing results. QueryTask queryTask = QueryTask.Builder.createDirectTask() .setQuery(Query.Builder.create() .addFieldClause(ExampleServiceState.FIELD_NAME_ID, "saffsdfs") .build()) .build(); queryTask.indexLink = this.indexLink; doThroughputPost(interleaveQueries, factoryUri, null, queryTask); }
/** * Add a clause which matches a top level field name using {@link MatchType#TERM} with the provided * {@link Occurance}. * @param fieldName the top level field name. * @param fieldValue the field value to match. * @param occurance the {@link Occurance} for this clause. * @return a reference to this object. */ public Builder addFieldClause(String fieldName, String fieldValue, Occurance occurance) { return addFieldClause(fieldName, fieldValue, MatchType.TERM, occurance); }
/** * Add a {@link Occurance#MUST_OCCUR} clause which matches a top level field name using * {@link MatchType#TERM}. * @param fieldName the top level field name. * @param fieldValue the field value to match. * @return a reference to this object. */ public Builder addFieldClause(String fieldName, String fieldValue) { return addFieldClause(fieldName, fieldValue, MatchType.TERM, Occurance.MUST_OCCUR); }
/** * Generates a query that finds all computes which resource pool link points to this * resource pool. Applicable to non-elastic pools only. */ private Query generateResourcePoolQuery(ResourcePoolState initState) { Query query = Query.Builder.create() .addKindFieldClause(ComputeState.class) .addFieldClause(ComputeState.FIELD_NAME_RESOURCE_POOL_LINK, getSelfLink()) .build(); return query; } }
public static ResourceGroupState buildProjectMemberResourceGroup(String projectId) { Query commonQuery = buildCommonProjectResourceGroup(projectId, AuthRole.PROJECT_MEMBER).query; Query.Builder builder = Query.Builder.create(); builder.addFieldClause(ServiceDocument.FIELD_NAME_SELF_LINK, buildUriWithWildcard(ManagementUriParts.CLUSTERS), MatchType.WILDCARD, Occurance.SHOULD_OCCUR); for (Query query : commonQuery.booleanClauses) { builder.addClause(query); } return buildResourceGroupState(AuthRole.PROJECT_MEMBER, projectId, builder.build()); }
/** * Add a {@link Occurance#MUST_OCCUR} clause which matches a top level field name with the provided * {@link MatchType} * @param fieldName the top level field name. * @param fieldValue the field value to match. * @param matchType the match type. * @return a reference to this object. */ public Builder addFieldClause(String fieldName, String fieldValue, MatchType matchType) { return addFieldClause(fieldName, fieldValue, matchType, Occurance.MUST_OCCUR); }