Forum Discussion

peterlu's avatar
peterlu
Champion
12 years ago

rest api - search blog by label

Hi Guys,

 

User case:

A blog has 3 labels set "Apple", "Banana", "Test Space"

 

Here are the rest calls that works:

/search/messages?q=is_root:true%20AND%20labels:(Apple)&include_blogs=true
/search/messages?q=is_root:true%20AND%20labels:(Apple%20OR%20Banana)&include_blogs=true

  

Here is the rest call that does not work:

/search/messages?q=is_root:true%20AND%20labels:(Test%20Space)&include_blogs=true

 Any idea?

 

What is the format for labels with spaces?

 

Thanks

  • I'm not sure exactly why this occurs, but I've worked around similar issues in the past by replacing the space with %3F, which is the encoded form of ?. In the search query, the question mark character represents a single-character wildcard and seems to do the trick.

  • I would also try with %22Test%20Space%22 , where %22 is the encoding for " (although I haven't tried that myself so I am not 100% sure)

5 Replies

  • Good question - I did a little experiment, including replacing the space with a + or %2B, but couldn't get any results.

     

    AdamN, PaoloT - do you know how to search for labels with spaces in them?

  • AdamN's avatar
    AdamN
    Khoros Oracle
    12 years ago

    I'm not sure exactly why this occurs, but I've worked around similar issues in the past by replacing the space with %3F, which is the encoded form of ?. In the search query, the question mark character represents a single-character wildcard and seems to do the trick.

  • PaoloT's avatar
    PaoloT
    Lithium Alumni (Retired)
    12 years ago
    I would also try with %22Test%20Space%22 , where %22 is the encoding for " (although I haven't tried that myself so I am not 100% sure)
  • peterlu's avatar
    peterlu
    Champion
    12 years ago

    Thanks PaoloT, you are right, this works.

    <#assign testcount = restadmin("/search/messages/count?q=is_root:true%20AND%20labels:(%22test%20space%22)").value />

     This returns a total count of all root messages that have "test space" label set.

     

  • peterlu's avatar
    peterlu
    Champion
    12 years ago

    I am just playing around and find something interesting.

    You can set a label exactly like this:

    a" b'c+d

    This label includes " and space and ' and +.

    It is funny that lithium alows you to set a label like this.

    I guess it is not possible to do rest api /search/messages for that label :)

    Maybe only wildcard can do this: eg. a??b?c?d