invalid argument for literal struct

80 views
Skip to first unread message

Ivan

unread,
Mar 30, 2016, 3:18:07 PM3/30/16
to Lucee
Hi,
I'm doing this:

// estrago le info sulla categoria
catInfo = catConvert(Trim(arguments.categoria));

// creo i filtri di ricerca
savecontent variable="filtri" {

  // se è una ricerca con filtri
  if ( !catInfo.all ) {

      // cerca tutta la categoria
      if (catInfo.padre == 1) {

        writeOutput('

            "and":[
              {
                "term":{
                  "pro_cat": ' & catInfo.IdCat & '
                }
              }
            ]

        ');

      } else {

        // cerca solo nella sottocategoria
        writeOutput('

            "and":[
              {
                "term":{
                  "pro_cat_id": ' & catInfo.IdUni & '
                }
              }
            ]

        ');

      } // if secondaria
  } // if principale
}; // savecontent



variables.searchParams = [];
variables.searchParams = {
    "from":0,
    "size":150,
    "query":{
      "filtered":{
        "query":{
          "multi_match":{
            "query":"#searchUrlToString(arguments.searchText)#",
            "type": "most_fields",
            "fields":[
               "pro_titolo^10",
               "pro_descrizione",
               "pro_brand"
             ]
          }
        },
        "filter": { #filtri# }
      }
   }
};



and I get this error (at red line):
invalid argument for literal struct, only named arguments are allowed like {name:"value",name2:"value2"}


I can not solve ... Can anyone make me understand?

Igal @ Lucee.org

unread,
Mar 30, 2016, 3:27:27 PM3/30/16
to lu...@googlegroups.com
the problem is at

    { #filtri# }

the parser sees it as a single item, which would be expected in an Array but not in a Struct.  This is invalid just like

    { invalid }

is not a valid Struct, but

    { state: valid }

is a valid one.

if it were an Array, then it would be

    [ valid ]

which is also valid.

makes sense?

Igal Sapir
Lucee Core Developer
Lucee.org

--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/df3c1e6f-1d73-4e08-8b3a-cd9d8e131752%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nando Breiter

unread,
Mar 30, 2016, 4:15:49 PM3/30/16
to lu...@googlegroups.com
Not sure if this will work, but I'd try putting the braces { } inside the savecontent block and then do:

"filter": #filtri# 



Aria Media Sagl
+41 (0)76 303 4477 cell
skype: ariamedia

Igal @ Lucee.org

unread,
Mar 30, 2016, 4:52:50 PM3/30/16
to lu...@googlegroups.com
I don't think that would work, because the literal struct is still invalid.

the way I did it in my code, incidentally also for submitting a query to ElasticSearch, is by building a struct with the conditions, and then at the end serializing it to JSON.  so instead of savecontent, I actually added keys and values to the struct according to the conditions.


Igal Sapir
Lucee Core Developer
Lucee.org

Igal @ Lucee.org

unread,
Mar 30, 2016, 5:00:53 PM3/30/16
to lu...@googlegroups.com
On 3/30/2016 1:52 PM, Igal @ Lucee.org wrote:
I don't think that would work, because the literal struct is still invalid.
Actually, I take that back.  I didn't read Nando's message properly.  It might as well work.


Ivan

unread,
Mar 31, 2016, 2:47:03 AM3/31/16
to Lucee

Hi everyone,

I tried the solution: "filter": #filtri# but it is passed as a string. Look:







Nando Breiter

unread,
Mar 31, 2016, 4:02:44 AM3/31/16
to lu...@googlegroups.com
Well, that makes sense. It was constructed as a string using savecontent.



Aria Media Sagl
+41 (0)76 303 4477 cell
skype: ariamedia

--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

Ivan

unread,
Mar 31, 2016, 4:10:20 AM3/31/16
to Lucee
Ok. So, you how do you suggest me to do?

Michael van Leest

unread,
Mar 31, 2016, 5:01:40 AM3/31/16
to lu...@googlegroups.com
Try this

"filter": #serializejson(filtri)#

2016-03-31 10:10 GMT+02:00 Ivan <ivan....@gmail.com>:
Ok. So, you how do you suggest me to do?

--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Michael van Leest

Ivan

unread,
Mar 31, 2016, 5:19:56 AM3/31/16
to Lucee
As before :


Michael van Leest

unread,
Mar 31, 2016, 5:44:10 AM3/31/16
to lu...@googlegroups.com
My bad... I ment deserializeJSON(filtri)

2016-03-31 11:19 GMT+02:00 Ivan <ivan....@gmail.com>:
As before :


--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Michael van Leest

Ivan

unread,
Mar 31, 2016, 6:08:51 AM3/31/16
to Lucee
 Great! so it works! Thank you Michael

Michael van Leest

unread,
Mar 31, 2016, 6:57:45 AM3/31/16
to lu...@googlegroups.com
No problem

2016-03-31 12:08 GMT+02:00 Ivan <ivan....@gmail.com>:
 Great! so it works! Thank you Michael

--
Love Lucee? Become a supporter and be part of the Lucee project today! - http://lucee.org/supporters/become-a-supporter.html
---
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Michael van Leest
Reply all
Reply to author
Forward
0 new messages