how to create query parser to parse query param in spring REST -
my query parameter this:
q=name:abc+age:20+roleid:(23|45)|audeince:(23|24).here + , | or
i have accept query param spring controller , have make query solar fetch data.

@controller @requestmapping("/user") public class bookscontroller { @requestmapping(value="/details", method=requestmethod.get) public responseentity<?> getuser(final httpservletrequest request) { string params = requestparams.get("q")[0]; //passing string make query in apache solar } }
i need write parser split param value make solar query.how write query parser split above url make solar query satisfying or , condition.name:abc+age:20+roleid:(23|45)|audeince:(23|24) means create solar query name=abc , age=20 , roleid in (23,24) or audience in (23,24) .this way user sends query.
eg:firstname:(abc|bcd)+lastname:abc+emailid:abc+dsid:abc|countrycd:us+audienceid:(123+678)
first using regex convert firstname:(abc|bcd)+ -----------segment1
lastname:abc+.............segment2
emailid:abc+.............segment3
dsid:abc|--------------segment4
countrycd:us+----------segment5
audienceid:(123+678)------segment 6;
like many segments may come in url
i have class called
class queryobj{
private string field;
private list value;
private string internaloperator;
private string externaloperator;
}
firstname:(abc|bcd)+ again using regex map this
field=firstname
value={abc,bcd}
internaloperator=|
externaloperator=+
like second segment emailid:abc+
field=emailid
value=abc
internaloperator=null
externaloperator=+
same other segments .if there n segments have n objects.
after add each object linked list.if internaloperator or externaloperator null leave null .how can achieve that
you can use regex pattern "key:value operator" segment
pattern keyvaluepattern = pattern.compile("[\\w]+:([\\w@.]+|\\([\\w|+@.]+\\))[+|]?");
Comments
Post a Comment