PDA

View Full Version : ExtJS Store not able to display SOLR JSON string



locutusUT
23 Nov 2009, 1:27 PM
I am working with Apache SOLR search engine to display search results into an ExtJS Grid. SOLR supports a JSON result so I've mapped up just ID to start with to see if I could get that to work. Whenever I try to run this, I don't see the grid getting filled in. Any ideas?

Here's my JSON result from SOLR:



strcallback1001({
"responseHeader":{
"status":0,
"QTime":2,
"params":{
"json.wrf":"strcallback1001",
"indent":"on",
"wt":"json",
"rows":"10",
"version":"2.2",
"fl":"*,score",
"start":"0",
"q":"bird",
"qt":"dismax",
"fq":""}},
"response":{"numFound":3293,"start":0,"maxScore":0.14686589,"docs":[
{
"id":"1088101",
"timestamp":"2009-11-19T19:55:14.392Z",
"popularity":0,
"score":0.14686589},
...


Heres is the ExtJS code:



var ds = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: 'http://solrdev/solr/select/'
}),
reader: new Ext.data.JsonReader({
id: 'id',
totalProperty: 'response.numFound',
root: 'response.docs'
}, Ext.data.Record.create([
{
name:'id'
}
])),
baseParams: {q:'bird',version:'2.2',start:'0',rows:'10',indent:'on',qt:'dismax',wt:'json',"json.wrf":"strcallback1001"}
});

var grid = new Ext.grid.GridPanel({
store: ds,

columns: [
{
header: 'ID',
width: 120,
sortable: true,
dataIndex: 'id'
}
],
viewConfig: {
forceFit: false
},
renderTo: 'content',
title: 'SOLR Grid',
width: 500,
autoHeight: true,
frame: true
});

grid.getSelectionModel().selectFirstRow();
ds.load();

jnicora
23 Nov 2009, 3:13 PM
I'm not real familiar with script tag proxy's, how is your function strcallback1001 getting called?

jnicora
23 Nov 2009, 3:15 PM
do you need to add callbackParam: "strcallback1001" to your scriptTagProxy config?

locutusUT
23 Nov 2009, 4:15 PM
do you need to add callbackParam: "strcallback1001" to your scriptTagProxy config?

Yes, I've tried that as well. I've tried with and without the callback approach as well as moving the params up into the URL and that didn't work either.

locutusUT
23 Nov 2009, 6:24 PM
Actually, I had a typo. It should of been "stcCallback1001". That works when setting both in the params and the callback param. Thank you!

Fredric Berling
24 Nov 2009, 12:32 AM
It seems im doing the same as you are :).. This is my working code. You just specify callbackParam:'json.wrf' and Ext will tell SOlr whar the function should be called.


proxy: new Ext.data.ScriptTagProxy({
url: 'http://solr.mydomain.com:8080/solrdev/select/?',
method: 'GET',
callbackParam:'json.wrf'
}),
baseParams: {
q: 'test',
start:'0',
version:'2.2',
rows:'10',
indent:'on',
sort:'subject asc',
wt:'json'
}

locutusUT
24 Nov 2009, 10:03 PM
Thank you Fredric...that works much better for me. :)

I noticed that you have sort as part of your base params. This works fine for the initial pull but I've noticed that if I try to sort a column (using GroupingStore) it only sorts the rows on that page. I've read that you need to use "remoteSort:true" to get it to call the service again but it requires you to have two parameters (sort and dir). Unfortunately, SOLR sort of combines those in "sort". Have you found a way to manage sort with SOLR without writing some sort of wrapper?

Fredric Berling
24 Nov 2009, 11:55 PM
Hi locutusUT

Nice that im not the only one that uses solR. Well i havent come that far yet , but it will certantly be crucual for me to solve that issue too.

There must be a way to override that handling on remoteSort. If you beat me to the goal, please let me know.

Some more useful things regarding SolR and Ext JS together

*If you start using comboboxes with livesearch functions. Dont forget the queryParam: 'q' for changing the pameter name for "query"

*if you use pagination you must change parameter name for "limit" to "rows" using the paramNames: {limit:'rows'} on the store you are using