Forum Discussion

DylanGeorgeFiel's avatar
9 years ago

Problems trying to match by label and body/subject REST V2

Hello,

 

I'm trying to use LiQL to retrieve posts by label and keywords in body/subject. I've been testing this and I've noticed that the 'MATCHES' query is working inconsistently. Here is my query:

 

SELECT id, subject, body, board.id, view_href, metrics.views, author.login, post_time FROM messages WHERE labels.text = 'FAQ' AND depth=0 AND labels.text MATCHES ( "stereo", "electro", "kickit") AND body MATCHES ("boys") OR subject MATCHES ("boys") ORDER BY metrics.views DESC LIMIT 5

 

The query retrieves posts labelled 'FAQ' and posts containing 'boys' however ignores posts containing labels 'stereo', 'electro' and 'kickit'. Now, if I remove the line "AND body MATCHES ("boys") OR subject MATCHES ("boys")" then the line "MATCHES ( "stereo", "electro", "kickit")" works correctly.

 

It seems they cannot be used together, is there a way I can match posts by label AND body/subject. Keeping in mind it must always contain an 'FAQ' label?

 

Sorry if this is very confusing. 

  • ChhamaJ's avatar
    ChhamaJ
    Khoros Staff

    Hi DylanGeorgeFiel

     

    First of all, I would hate to mention that we never supported OR operator in our LiQL queries. We would love to have that but currently there is no support for this.  You will have to write two different queries for subject and body and create a union out of those.

    Second, I need to understand the WHERE clause in the query that you had written 

    labels.text = 'FAQ' AND depth=0 AND labels.text MATCHES ( "stereo", "electro", "kickit")

    Ideally you should be doing either labels.text = or labels.text MATCHES. Is there a need for both the clauses? As a best practice, we suggest to use labels.text MATCHES.

     

    Hope this helps.

    Let me know if you have further questions.

     

    Regards,

    Chhama

    • Hi ChhamaJ, in the process of going through something similar to DylanGeorgeFiel, i can try to explain the difference with using labels.text = as opposed to using labels.text MATCHES.

       

      Using something like the following allows you to query messages based on a AND relationship of labels. Meaning, get posts that has both labels as requested:

      SELECT * FROM messages WHERE labels.text = 'FAQ' AND labels.text = 'Help'

      If you use MATCHES ("FAQ", "Help"), you are saying you want to get posts with either labels FAQ or Help.

       

      I believe Dylan was trying to do a combination of AND and OR relationships, which is where im also running into a snag: get posts that has the FAQ label AND (also stereo OR electro OR kickit labels)

       

      Do you know what was the resolution to this original request?