googleads-java-lib icon indicating copy to clipboard operation
googleads-java-lib copied to clipboard

Issue searching audience segments with name starting from the search term

Open AndreiLosikTR opened this issue 3 years ago • 1 comments

Hi All,

I'm trying to request all audience segments which start from "PA - " but the API looks like returns audience segments with the search term not only at the beginning of the name, but also in any part of the name.

This is how my code looks like:


    @Override
    public List<AudienceSegment> findAllPAs() {
        StatementBuilder statementBuilder =
                new StatementBuilder()
                        .where("name LIKE 'PA - %' and type = 'FIRST_PARTY'")
                        .orderBy("id ASC");
        return findAllAudienceSegmentsByStatement(statementBuilder, StatementBuilder.SUGGESTED_PAGE_LIMIT);
    }

private List<AudienceSegment> findAllAudienceSegmentsByStatement(StatementBuilder statement, int limit) {
        statement.limit(limit);
        List<AudienceSegment> segments = new ArrayList<>();
        int totalResultSetSize = 0;

        do {
            AudienceSegmentPage page;
            try {
                page = audienceSegmentService.getAudienceSegmentsByStatement(statement.toStatement());
            } catch (RemoteException re) {
                throw new RuntimeException(re);
            }

            if (page.getResults() != null) {
                totalResultSetSize = page.getTotalResultSetSize();
                segments.addAll(Arrays.asList(page.getResults()));
            }

            statement.increaseOffsetBy(limit);
        } while (statement.getOffset() < totalResultSetSize);

        return segments;
    }

Thanks, Andrei

AndreiLosikTR avatar Apr 14 '21 14:04 AndreiLosikTR

@christopherseeley PTAL

nwbirnie avatar Apr 14 '21 15:04 nwbirnie