 how to use multi-fields search for issues in REST api?
how to use multi-fields search for issues in REST api?
Added by Alex Last about 9 years ago
hi guys!
someone submitted a feature request for Redmine Java library to support free-form search with multiple params like "f[]".
I added support for this, but I do not see any documentation on how to use that free-form search in Redmine REST API.
I have this integration test that fails because it returns more than 1 issue, which indicates that search terms I used result in "or" operation rather than expected "and". this test is in Java, but you can see the idea in it - the search part is not specific to any language, it is specific to Redmine only.
can someone please post a link to a page describing how to use free-form search for redmine objects (like "f[]", "op[..]=xyz", "and", "or", etc)?
  /**
     * regression test for https://github.com/taskadapter/redmine-java-api/issues/12 and
     * https://github.com/taskadapter/redmine-java-api/issues/215
     */
    public void issuesCanBeFoundByMultiQuerySearch() throws RedmineException {
        final Issue issue1 = IssueFactory.create(projectId, "summary 1 here");
        issue1.setDescription("abc description");
        issueManager.createIssue(issue1);
        final Issue issue2 = IssueFactory.create(projectId, "summary 2 here");
        issue2.setDescription("def totally different description");
        issueManager.createIssue(issue2);
        final Issue issue3 = IssueFactory.create(projectId, "another");
        issue3.setDescription("abc");
        issueManager.createIssue(issue3);
        Params params = new Params()
                .add("set_filter", "1")
                .add("f[]", "summary")
                .add("op[summary]", "~")
                .add("v[summary]", "another")
                .add("f[]", "description")
                .add("op[description]", "~")
                .add("v[description][]", "abc");
        final ResultsWrapper<Issue> list = issueManager.getIssues(params);
        // only 1 issue must be found
        assertThat(list.getResults()).hasSize(1);
    }
Replies (2)
     RE: how to use multi-fields search for issues in REST api?
    -
    Added by Alex Last about 9 years ago
    RE: how to use multi-fields search for issues in REST api?
    -
    Added by Alex Last about 9 years ago
  
  I found this combination of params to work:
   
    public void issuesCanBeFoundByMultiQuerySearch() throws RedmineException {
        final Issue issue1 = IssueFactory.create(projectId, "summary 1 here");
        issueManager.createIssue(issue1);
        final Issue issue2 = IssueFactory.create(projectId, "summary 2 here");
        issueManager.createIssue(issue2);
        final Issue issue3 = IssueFactory.create(projectId, "another");
        issueManager.createIssue(issue3);
        final User currentUser = userManager.getCurrentUser();
        Params params = new Params()
                .add("set_filter", "1")
                .add("f[]", "subject")
                .add("op[subject]", "~")
                .add("v[subject][]", "another")
                .add("f[]", "author_id")
                .add("op[author_id]", "~")
                .add("v[author_id][]", currentUser.getId()+"");
        final ResultsWrapper<Issue> list = issueManager.getIssues(params);
        // only 1 issue must be found
        assertThat(list.getResults()).hasSize(1);
    }
     RE: how to use multi-fields search for issues in REST api?
    -
    Added by Philipp Gächter about 3 years ago
    RE: how to use multi-fields search for issues in REST api?
    -
    Added by Philipp Gächter about 3 years ago
  
  cf_91 = 2206094     Monsum Customer ID
cf_85 = 966832      Monsum Subscription ID
This can also be used to query the REST API via GET and using custom fields:
{{BASE_URL}}/issues.json?limit=25&offset=0&f[]=cf_83&op[cf_83]==&v[cf_83][]=SOMEVALUE&include[]=relations
{{BASE_URL}}/issues.json
    ? limit         = 25
    & offset        = 0
    & f  []         = cf_83            ← field
    & op [cf_83]    = =                ← operator `=`
    & v  [cf_83] [] = SOMEVALUE        ← value(s)
    & include[]     = relations
	You are adding multiple fields to the parameters.
- Question 0: Is there any documentation about this?
- Question 1: Do you know how a multiple fields filter can be done with GET?
 → Researched myself: Use multiplef[]GET parameters, i.e.?f[]=cf_83&f[]=cf_91(additionally addop[x]andv[x]for second field)(source)
 → Full example:/issues.json?f[]=cf_91&f[]=cf_83&op[cf_83]==&v[cf_83][]=VALUE_X&op[cf_91]==&v[cf_91][]=VALUE_Y
- Question 2: Is it possible to connect the filters with OR instead of AND?
Desired outcome: 
→ Tickets with custom field 83 value X or custom field 91 value Y
best regards, phil