Given an xml block of:
<parent>
<child id="1" />
<child id="2" />
</parent>
How might I use xpath to return
<parent>
<child id="1" />
</parent>
Based on a filter for id="1" (not firstchild).
I am not looking for an xslt or xquery solution.
Many thanks.
With just XPath, you can't.
XPath allows you to query (select) nodes from an XML document tree, but it can't modify a tree or create new nodes. So if you select the original <parent> node, it will have two <child> children, and you can't change that. In order to get a <parent> with only one child, you'd have to either modify the original <parent> to delete its other child, or create a new <parent>.
You could do this with XSLT, as you alluded to; or a number of other XML tree-building technologies. If you tell us what kind of platform you're building on, we could suggest ones that are most relevant to your platform.
Related
How to deal with a performance issue in searching from database as mentioned below:
In the app i am working on , has a searchCustomer functionality where api will return the list of customers based on the search criteria. The search request will be like this:
<Search>
<name>
<firstName>fname</firstName>
<lastName>lname</lastName>
</name>
<address>
<addressLine1>address1</addressLine1>
<postalCode>679122</postalCode>
<city>testcity</city>
<countryCode>US</countryCode>
</address>
<id>
<Customerid>1234<customerid>
<Search>
<Search>
<name>
<firstName>fname</firstName>
<lastName>lname</lastName>
</name>
<address>
<addressLine1>address1</addressLine1>
<postalCode>679122</postalCode>
<city>testcity</city>
<countryCode>US</countryCode>
</address>
<id>
<Customerid>1234<customerid>
<Search>
In this request its not necessary to mention all the fields, any one of the field is enough.
If we could find a list of customers based on that given field we will return those customers.
How current system work is, process the list of items one by one, create a predicate using querydsl then fetch the data using springdata findall method.
Since the request list can have hundreds of items, processing is too slow and is taking more than a minute to get the response.
What is the right approach to do this kind of search?
I am currently creating a data model in BI Publisher which has an XML file for its data set. I am however unfamiliar on how to access its contents for the Bursting Query.
Here is a sample of my XML file:
<records>
<customer>
<id>123</id>
<name>john</name>
</customer>
<customer>
<id>456</id>
<name>jane</name>
</customer>
</records>
I am familiar on how to burst to file, email, etc... The problem is on how to query the XML file for the Bursting Query.
Given an xml block of:
<parent>
<child id="1" />
<child id="2" />
</parent>
How might I use xpath to return
<parent>
<child id="1" />
</parent>
Based on a filter for id="1" (not firstchild).
I am not looking for an xslt or xquery solution.
Many thanks.
With just XPath, you can't.
XPath allows you to query (select) nodes from an XML document tree, but it can't modify a tree or create new nodes. So if you select the original <parent> node, it will have two <child> children, and you can't change that. In order to get a <parent> with only one child, you'd have to either modify the original <parent> to delete its other child, or create a new <parent>.
You could do this with XSLT, as you alluded to; or a number of other XML tree-building technologies. If you tell us what kind of platform you're building on, we could suggest ones that are most relevant to your platform.
I am still new to SOLR and I've managed to install and index 1000 documents from the database. When I submit a query, the results are returned correctly but the order of the fields are not displayed as how it is defined in the data config file.
Example of data config file:
<field column="id" name="event_id" />
<field column="event_desc_current" name="event_desc" />
<field column="event_cost" name="event_cost" />
<field column="event_sponsors" name="event_sponsors" />
...
Example of results returned:
<result name="response" numFound="7" start="0">
<doc>
<str name="event_desc">Church Fund Raising</str>
<arr name="event_sponsors">
<str/>
</arr>
<str name="event_id">2</str>
<int name="event_cost">428</int>
...
<long name="_version_">1472652516366745600</long></doc>
How can I output the order of the fields as defined in the data config file like this:
event_id
event_desc
event_cost
event_sponsors
...
Typically, the order of the fields should not matter, as you would de-serialize it in a client and the logic of displaying the search results is with the client.
However, if you do want to dictate the order of fields, you could use the fl parameter in your Solr query to get results in the order you prefer.
You could also choose which fields to include in the search field.
Personally, I would recommend that you need not worry about order of fields, and have a client that can consume it in any order. Reason being, if you add a new field to your schema, in the middle, you could potentially breaking the client's logic!
I've very a lot of searching on Google and can not find the answer to this question.
We have Enterprise Magento and are using SOLR. We would like to select a group of products and put them at the top of the search results when they are returned by SOLR. We would use this for clearance products, etc.
My idea was to put the items in to a special non-display category on the backend and to somehow configure SOLR to put a greater weighting on these products for the search results. But I can not see how to do this. I can only see how to weight product attributes.
Anyone have any suggestiogs?
Giving fields different weights is very simple in Solr -- simply add the following to your default requestHandler in solrconfig.xml
<requestHandler name="/select" class="solr.SearchHandler">
<lst name="defaults">
...
<qf>Weighted_Category^3 Lesser_Category^0.5</qf>
</lst>
</requestHandler>
This weighs "Weighted Category" by a factor of 3, should there be a match.
Magento-solr has a built in function to do exactly this.
magento/lib/apache/solr/config/elevate.xml:
<elevate>
<query text="foo bar">
<doc id="1" />
<doc id="2" />
<doc id="3" />
</query>
<query text="ipod">
<doc id="MA147LL/A" /> <!-- put the actual ipod at the top -->
<doc id="IW-02" exclude="true" /> <!-- exclude this cable -->
</query>
</elevate>
QueryElevationComponent