Solrj Questions for faceting and json resoponse - solrj

I am trying to use solrj for my application, my code is given below,
query.add("q", "simplify360");
query.add("facet", "true");
query.add("facet.range", "createdOnGMTDate");
query.add("facet.range.start", "2010-08-01T00:00:00Z+330MINUTES");
query.add("facet.range.end", "2011-05-31T00:00:00Z+330MINUTES");
query.add("facet.range.gap", "+1DAY");
//query.add("wt","json");
//query.add("wt.mime-type","application/json");
System.err.println(query.toString());
The code executes fine and when i execute the url on solr server, i get the following result for faceting,
<lst name="facet_counts"><lst name="facet_queries"/>
<lst name="facet_fields"/>
<lst name="facet_dates"/>
<lst name="facet_ranges">
<lst name="createdOnGMTDate">
<lst name="counts">
<int name="2010-01-01T00:00:00Z">0</int>
<int name="2010-01-02T00:00:00Z">0</int>
<int name="2010-01-03T00:00:00Z">0</int>
<int name="2010-01-04T00:00:00Z">0</int>
<int name="2010-01-05T00:00:00Z">0</int>
<int name="2010-01-06T00:00:00Z">0</int
</lst>
<str name="gap">+1DAY</str>
<date name="start">2010-01-01T00:00:00Z</date>
<date name="end">2011-05-31T00:00:00Z</date>
</lst>
</lst>
</lst>
</response>
1) How can i retrieve these values in java,
2) Also if there is anyway i can convert the json response to the json java object
Regards,
Rohit

Using SOLRJ API, you can use following code:
QueryResponse rsp = server.query(query); // you issue the query and get resuls
Map<String, Integer> fq = rsp.getFacetQuery(); // this returns facetQuery part of response
Hope this helps ...

Related

Including a CDATA field in a Service Connector

An API I am communicating with is Soap based and requires XML with inner XML (CDATA) in the request.
For the service connector action test I have hard-coded the inner xml with this format:
<![CDATA[
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationCrossReferenceId="123">
...
...
</Application> ]]>
where the dots indicate the data contained.
When running the test the request payload has been transformed to the html entity for < which is $lt; - as seen below :
Is there a way to avoid this?
This is a bug in Informatica. the other characters are decoded back to their original correctly, as described in KB 512858, &gt and &lt however are not decoded.
A bug report has been raised 29.05.2020.
Edit: Further investigation revealed that using CDATA was not necessary in my case, instead I was able to use the following input for the body binding:
<Application xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ApplicationCrossReferenceId="123">
...
...
</Application>

SOAP UI Automation - Assertion if reponse XML's dynamic elements value is blank

Please find below sample soap request
<FlowerSearchRequest>
<Request>
<name>ROSE</name>
<color></color>
<smell></smell>
</Request>
</FlowerSearchRequest>
Current Functionality
<Request>--<name> is mandatory field
<Request>--<color> and <Request>--<smell> is not mandatory i.e, they can be blank(<smell></smell>) but cannot be null
SOAP response <FlowerSearchResponse> contains all the request parameters <Request> and the response parameters for this request under <ResponseList> (as shown below)
For each <Request>, Response can have List of <Response> elements under <ResponseList>
If i search with ROSE , for few results <Response> -- <smell> element may/may not have value (but it cannot be null)
<Response> occurrence in result is dynamic , i.e, if I search with Lily I may get 10 or even more <Response> elements
SOAP response for above request
<FlowerSearchResponse>
<Request>
<name>ROSE</name>
<color></color>
<smell></smell>
</Request>
<ResponseList>
<Response>
<name>ROSE</name>
<color>Red</color>
<smell>Pleasant</smell>
</Response>
<Response>
<name>ROSE</name>
<color>Blue</color>
<smell>UnPleasant</smell>
</Response>
<Response>
<name>ROSE</name>
<color>Yellow</color>
<smell></smell>
</Response>
</ResponseList>
</FlowerSearchResponse>
Question
In SOAP UI, how to automate below case?
Go through all the <Response> elements from the dynamic list (not sure about the count of <Response> tags at the time of writing assertions), Assert if even a single <Response> has Blank value for <smell> element
Assertion test case should only consider elements <Response>-- <smell> when its checking for Blank <smell> elements i.e, it should not consider the <Request> -- <smell>
P.S: I am really novice at SOAP UI assertions-- trying hard to find a solution using xslt, but couldn't succeed so far.
If you want an XPath expression returning true or false depending on whether there is any Response/smell element with no content:
(: returns true if NO single one smell element is empty :)
empty(//Response/smell[empty(node())])
If you want to count them instead:
(: returns the number of empty smell elements :)
count(//Response/smell[empty(node())])

Spellcheck using Solr and Haystack not showing any results

Our Solr build is functioning as
http://192.168.1.106:8983/solr/spell?q=query&spellcheck=true&spellcheck.build=true
does successfully return spelling suggestions based off our index based dictionary
However the django-haystack variable {{suggestion}} or even python command SearchQuerySet().spelling_suggestion("query") return "None".
We use the standard view and url provided by haystack.
The install apps are
Python 2.7.2, Django 1.3.2,
Haystack 2.0, Apache Solr 3.6.1 (running on standard Jetty), PySolr 2.1.
Here is some of the code we are using:
In settings.py
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
'URL': 'http://192.168.1.106:8983/solr',
'INCLUDE_SPELLING': True,
},
}
In /PATH/TO/SOLR/example/solr/conf/solrconfig.xml:
<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
<str name="queryAnalyzerFieldType">textSpell</str>
<lst name="spellchecker">
<str name="name">default</str>
<str name="field">text</str>
<str name="spellcheckIndexDir">spellchecker</str>
</lst>
</searchComponent>
<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="df">text</str>
<str name="spellcheck.onlyMorePopular">false</str>
<str name="spellcheck.extendedResults">false</str>
<str name="spellcheck.count">10</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
</arr>
</requestHandler>
So the question is: where is the issue in the code to cause the installed app 'haystack' to not communicate with the results for spelling suggestions Solr is finding? Or in otherwords, why does haystack show no spelling suggestions while Solr provides some?
Do you have the INCLUDE_SPELLING setting defined as True in the CONNECTIONS in your Django settings file? http://django-haystack.readthedocs.org/en/latest/searchqueryset_api.html#spelling-suggestion
One thing that may be helpful is to see exactly what Haystack is sending to Solr. You can add a print statement into the SolrBackend class in Haystack's backends/solr_backend.py in the search function so you can see the URL being used. That would at least show you if Haystack is doing the search suggestion as ordered.
You may also want to check for Haystack updates direct from the Github repo. The development there is pretty active.
I was struggling with this error, and spelling_suggestion wasn't showing nothing, until I add to request handler "/select" the component spellchecker. So the default connection is as said above and the '/select' handler goes like this:
<requestHandler name="/select" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<int name="rows">10</int>
<str name="df">text</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
</arr>
Adittionally, I also add as attribute of my RestaurantIndex at search_indexes.py, something like:
#Suggestions - so obvious
suggestions = indexes.CharField()
def prepare(self, obj):
prepared_data = super(RestaurantIndex, self).prepare(obj)
prepared_data['suggestions'] = prepared_data['text']
return prepared_data
In this case 'text' will be your own field that will be suggestions.
After this, in python shell you could execute this and results would came up:
sqs = SearchQuerySet().auto_query('Restauront')
spelling = sqs.spelling_suggestion()
My suggestion to this is restaurant.
Cheers!
PS: If you need extra config, just say it.

How to invoke this webservice method?

I can't wrap my mind around invoking a simple method of 3rd-party service. Here's the chunk of WSDL for this method:
<s:element name="PushRequest">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="LocationCode" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="PushRequestXml" type="s:string"/>
<s:element minOccurs="0" maxOccurs="1" name="PassPhrase" type="s:string"/>
</s:sequence>
</s:complexType>
</s:element>
This is a sample SOAP 1.1 request, generated by web-service:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<PushRequest xmlns="http://xxxx.yyyy.com/">
<LocationCode>string</LocationCode>
<PushRequestXml>string</PushRequestXml>
<PassPhrase>string</PassPhrase>
</PushRequest>
</soap:Body>
</soap:Envelope>
First I thought that this is one argument of complex type, so I've tried this:
ws = CreateObject("webservice", serviceURL);
push = {};
push["LocationCode"] = "xxx";
push["PushRequestXml"] = "yyy";
push["PassPhrase"] = "zzz";
responseXML = ws.PushRequest(push);
But got usual CF response Web service operation PushRequest with parameters {{PushRequestXml={yyy},LocationCode={xxx},PassPhrase={zzz}}} cannot be found..
Next I thought that maybe this is not a complex argument (at least it doesn't have a name attribute in XML), but three different arguments:
ws = CreateObject("webservice", serviceURL);
responseXML = ws.PushRequest(LocationCode = "xxx", PushRequestXml = "yyy", PassPhrase = "zzz");
Result is the same: Web service operation PushRequest with parameters {PushRequestXml={{PushRequestXml, yyy}},LocationCode={{LocationCode, xxx}},PassPhrase={{PassPhrase, zzz}}} cannot be found.
Any ideas how this should be handled? Please tell if more information needed.
I'm using ACF9, webservice is provided by ASP.net
Thanks.
I've ended up with using plain POST-ing raw XML to the web-service and parsing response XML manually, as proposed in this blog post.
Also I've tried wsdl2java as proposed in 3rd part of that blog series, but it did not help me -- method looked exactly as expected previously:
public java.lang.String pushRequest(java.lang.String locationCode, java.lang.String pushRequestXml, java.lang.String passPhrase) throws java.rmi.RemoteException;
As a result, I haven't found the applicable way for use cfinvoke for my webservice.
So, my current request code looks as follows:
<cfsavecontent variable="SOAPXML">
<cfoutput>
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<PushRequest xmlns="http://serviceurl.com/">
<LocationCode>#LocationCode#</LocationCode>
<PushRequestXml>#XMLFormat(Trim(PushRequestXml))#</PushRequestXml>
<PassPhrase>#PassPhrase#</PassPhrase>
</PushRequest>
</soap:Body>
</soap:Envelope>
</cfoutput>
</cfsavecontent>
<cfhttp method="post" url="#ServiceURL#">
<cfhttpparam type="header" name="SOAPAction" value="http://serviceurl.com/PushRequest" />
<cfhttpparam type="xml" value="#Trim(SOAPXML)#" />
</cfhttp>
Service returns XML, so handling it is not a problem.
Have u tried using CFBuilder, and paste in the serviceURL into Services Browser (Show Web Services -> +), and then right click that to generate the correct createObject() call?
I'm no guru on WSDL, but I seem to remember that auto generated WSDL's usually suffix the method with either 'Request' or 'Response', so you may need to simply call 'Push' rather than 'PushRequest'.
ws = CreateObject("webservice", serviceURL);
push = {};
push["LocationCode"] = "xxx";
push["PushRequestXml"] = "yyy";
push["PassPhrase"] = "zzz";
responseXML = ws.Push(push);
worth a shot.

Haystack more_like_this returns all

I am using Django, haystack, solr, to do searching. Ive am able to search and now I would like to find similar items using more_like_this. When I try to use the more_like_this functionality I get back all of the objects that are of that model type instead of just the ones that closely match it. Here is some code to show you how I am using it:
def resource_view(request, slug):
resource = Resource.objects.get(slug=slug)
versions = Version.objects.get_for_object(resource)
related = SearchQuerySet().more_like_this(resource)
add_comment_form = AddCommentForm()
return render_to_response('resources/resource.html',
{'resource': resource,
'versions': versions,
'related': related,
'add_comment_form': add_comment_form},
context_instance=RequestContext(request))
Apparently I need to enable mlt in the solrconfig.xml file. Anyone know how to do this, or an article/tutorial that is helpful?
stale question, but here's the answer anyway:
As John already pointed out, you need to add the more like this handler (MLT) to your solr config. This should do, put it somewhere in your solrconfig.xml, and reload SOLR (Tomcat):
<requestHandler name="/mlt" class="solr.MoreLikeThisHandler">
<lst name="defaults">
<str name="mlt.mintf">1</str>
<str name="mlt.mindf">1</str>
<str name="mlt.minwl">3</str>
<str name="mlt.maxwl">15</str>
<str name="mlt.maxqt">20</str>
<str name="mlt.match.include">false</str>
</lst>
</requestHandler>