HI I want to perform combination (AND OR) search on the basis of the provided parameter by the user, where user will select the field name e.g.(title, isbn, author) and their value from front-end so here field name will be the parameter for the BaseX.
Currently i am asking front-end person the generate below combination query ( (title = "United States" or isbn = "2345371242192") and author ="Jhon" )
Now the all parameter value will be compared to specific XPATH , like below.
let $Author := 'David Hare' let $title := "United States " let $isbn:= '2345371242192 '
return db:open('test')/*[(( normalize-space(string-join((*:info/*:author)[1]/*:personname//text()) ) = $Author or $title = *:info/*:title ) and $isbn="*:info/isban")]/base-uri()
In the above code XPATH is hardcoded, but I want it to concatenate on the fly once string query comes front-end then it will be passed to Basex .
Is there any other way to achieve this? or how should i ask combinations query from front-end so that i could achieve this.
Thanks Dharmendra Kumar Singh
Hi Dharmendra,
Thanks for writing to the list.
I want to perform combination (AND OR) search on the basis of the provided parameter by the user, where user will select the field name e.g.(title, isbn, author) and their value from front-end so here field name will be the parameter for the BaseX.
Currently i am asking front-end person the generate below combination query ( (title = "United States" or isbn = "2345371242192") and author ="Jhon" )
Could you please give us more details on how this string is generated by the frontend?
Next, your XPath expression differs in many aspects from the frontend representation. Some examples:
• It seems that "author" needs to be mapped to: normalize-space(string-join((*:info/*:author)[1]/*:personname//text()) • "isbn" was mapped to $isbn="*:info/isban" (shouldn’t it be *:info/*:isbn, and without quotes?)
I assume that it’s not sufficient to map each frontend field to an element name?
Thanks in advance, Christian
Thanks Christian for your kind reply
Currently front-end not generating the search combination ( (title = "United States" or isbn = "2345371242192") and author ="Jhon" ) just i am thinking, if i could achieve this way, so that i could ask fron-end person to send this way.
As per implementation, the front-end is not going to send XPATH for any field, I am thinking to generate XPATH on the fly and concatenating it with the search query which will be sent from front-end, is it possible?
The XPATH will be on assumption as per field e.g.(if user select the field author then i have to look on XPATH (*:info/*:author)[1]/*:personname)
For this search ( (title = "United States" or isbn = "2345371242192") and author ="Jhon" ) how should i ask to generate the query from front-end so that combination search can be achieved.
Note: I have to create REST API for this service.
Thanks
On Tue, Nov 15, 2022 at 6:43 PM Christian Grün christian.gruen@gmail.com wrote:
Hi Dharmendra,
Thanks for writing to the list.
I want to perform combination (AND OR) search on the basis of the
provided parameter by the user, where user will select the field name e.g.(title, isbn, author) and their value from front-end so here field name will be the parameter for the BaseX.
Currently i am asking front-end person the generate below combination
query
( (title = "United States" or isbn = "2345371242192") and author ="Jhon"
)
Could you please give us more details on how this string is generated by the frontend?
Next, your XPath expression differs in many aspects from the frontend representation. Some examples:
• It seems that "author" needs to be mapped to: normalize-space(string-join((*:info/*:author)[1]/*:personname//text()) • "isbn" was mapped to $isbn="*:info/isban" (shouldn’t it be *:info/*:isbn, and without quotes?)
I assume that it’s not sufficient to map each frontend field to an element name?
Thanks in advance, Christian
Currently front-end not generating the search combination ( (title = "United States" or isbn = "2345371242192") and author ="Jhon" ) just i am thinking, if i could achieve this way, so that i could ask fron-end person to send this way.
If your frontend is JavaScript-based, it may be easier and cleaner to create a JSON object that contains the search fields. Something like:
{ "AND": { "OR": { "isbn" : "2345371242192", "title": "United States" }, "author": "Jhon" } }
If you POST this snippet as 'application/json' to a RESTXQ backend, the resulting XML structure will be:
<json type="object"> <AND type="object"> <OR type="object"> <isbn>2345371242192</isbn> <title>United States</title> </OR> <author>Jhon</author> </AND> </json>
You can then parse this XML fragment with XQuery to either:
a) recursively build a query string, which will be evaluated via xquery:eval (as proposed on StackOverflow), or b) process the query tree recursively for each element of your document.
The first variant will probably be more efficient.
You’ll probably need to invest some time to get this realized (I don’t think there’s a solution that can be used out of the box).
Best, Christian
Hi Christian,
Thanks for your suggestion
a) recursively build a query string, which will be evaluated via
xquery:eval (as proposed on StackOverflow)
on this solution i could work if i get the expected result then will update on stackoverflow
Thanks for your time Dharmendra kumar Singh
On Tue, Nov 15, 2022 at 7:35 PM Christian Grün christian.gruen@gmail.com wrote:
Currently front-end not generating the search combination ( (title =
"United States" or isbn = "2345371242192") and author ="Jhon" ) just i am thinking, if i could achieve this way, so that i could ask fron-end person to send this way.
If your frontend is JavaScript-based, it may be easier and cleaner to create a JSON object that contains the search fields. Something like:
{ "AND": { "OR": { "isbn" : "2345371242192", "title": "United States" }, "author": "Jhon" } }
If you POST this snippet as 'application/json' to a RESTXQ backend, the resulting XML structure will be:
<json type="object"> <AND type="object"> <OR type="object"> <isbn>2345371242192</isbn> <title>United States</title> </OR> <author>Jhon</author> </AND> </json>
You can then parse this XML fragment with XQuery to either:
a) recursively build a query string, which will be evaluated via xquery:eval (as proposed on StackOverflow), or b) process the query tree recursively for each element of your document.
The first variant will probably be more efficient.
You’ll probably need to invest some time to get this realized (I don’t think there’s a solution that can be used out of the box).
Best, Christian
basex-talk@mailman.uni-konstanz.de