evolvingweb/ajax-solr

Space characters in "facetLinks"

Closed this issue · 8 comments

Hi!

I have downloaded AjaxSolr from github and tried it out with my "own" data. Everything seems to work fine but I'm experiencing some strange behaviour when rendering "facetLinks" in the result list. The problem seems to be that the code used to render facetLinks inserts a space-character between each character for a given facet. Say that we have a facet value of "WITS", it will be rendered as "W I T S". The facets are stored as Solr "string" types and when using the Solr Schema browser the values look 100% correct (no space characters).

I've had a look in the ResultWidget.js file but can't find anything that might introduce the effect mentioned above. What might be wrong here? Unfortunately I'm not able to give you access to our server as it is behind a firewall...

The code in the ResultWidget.js that renders a result:

facetLinks: function (facet_field, facet_values) {
    var links = [];
    if (facet_values) {
        for (var i = 0, l = facet_values.length; i < l; i++) {
            links.push(AjaxSolr.theme('facet_link', facet_values[i], this.facetHandler(facet_field, facet_values[i])));
        }
    }
return links;

}

The code in the ResultWidget.js that has been tweaked somewhat to render "my" facets:

afterRequest: function () {
    $(this.target).empty();
    for (var i = 0, l = this.manager.response.response.docs.length; i < l; i++) {
        var doc = this.manager.response.response.docs[i];
        $(this.target).append(AjaxSolr.theme('result', doc, AjaxSolr.theme('snippet', doc)));

       var items = [];
       items = items.concat(this.facetLinks('source', doc.source));
       items = items.concat(this.facetLinks('region', doc.region));
       items = items.concat(this.facetLinks('classification', doc.classification));
       AjaxSolr.theme('list_items', '#links_' + doc.id, items);
    }
}

The code in the reuters.theme.js that renders facet links:

AjaxSolr.theme.prototype.facet_link = function (value, handler) {
    return $('<a href="#"/>').text(value).click(handler);
};

Cheers

Which facet is WITS? Is it classification? Anyway, try replacing the line:

items = items.concat(this.facetLinks('classification', doc.classification));

with:

items = items.concat(this.facetLinks('classification', [doc.classification]));

If it's not classification, then make a similar change for the appropriate facet.

On 2012-03-27, at 8:32 AM, kodo65 wrote:

Hi!

I have downloaded AjaxSolr from github and tried it out with my "own" data. Everything seems to work fine but I'm experiencing some strange behaviour when rendering "facetLinks" in the result list. The problem seems to be that the code used to render facetLinks inserts a space-character between each character for a given facet. Say that we have a facet value of "WITS", it will be rendered as "W I T S". The facets are stored as Solr "string" types and when using the Solr Schema browser the values look 100% correct (no space characters).

I've had a look in the ResultWidget.js file but can't find anything that might introduce the effect mentioned above. What might be wrong here? Unfortunately I'm not able to give you access to our server as it is behind a firewall...

The code in the ResultWidget.js that renders a result:
facetLinks: function (facet_field, facet_values) {
var links = [];
if (facet_values) {
for (var i = 0, l = facet_values.length; i < l; i++) {
links.push(AjaxSolr.theme('facet_link', facet_values[i], this.facetHandler(facet_field, facet_values[i])));
}
}
return links;
}

The code in the ResultWidget.js that has been tweaked somewhat to render "my" facets:
afterRequest: function () {
$(this.target).empty();
for (var i = 0, l = this.manager.response.response.docs.length; i < l; i++) {
var doc = this.manager.response.response.docs[i];
$(this.target).append(AjaxSolr.theme('result', doc, AjaxSolr.theme('snippet', doc)));

 var items = [];
 items = items.concat(this.facetLinks('source', doc.source));
 items = items.concat(this.facetLinks('region', doc.region));
 items = items.concat(this.facetLinks('classification', doc.classification));
 AjaxSolr.theme('list_items', '#links_' + doc.id, items);

}
}

The code in the reuters.theme.js that renders facet links:
AjaxSolr.theme.prototype.facet_link = function (value, handler) {
return $('').text(value).click(handler);
};

Cheers


Reply to this email directly or view it on GitHub:
#11

Currently I have three "facets": Sources, Regions and Classifications and they're managed by the following code in ResultWidget.js:

  var items = [];
  items = items.concat(this.facetLinks('source', doc.source));
  items = items.concat(this.facetLinks('region', doc.region));
  items = items.concat(this.facetLinks('classification', [doc.classification]));
  AjaxSolr.theme('list_items', '#links_' + doc.id, items);

I followed your recommendation and changed "doc.source" to "[doc.source]" and that solved the issue with "WITS" becoming "W I T S". However, as soon as I tried to enclose the two other "facets" the UI stopped working... >To clarify this works:

  var items = [];
  items = items.concat(this.facetLinks('source', [doc.source]));
  items = items.concat(this.facetLinks('region', doc.region));
  items = items.concat(this.facetLinks('classification', [doc.classification]));
  AjaxSolr.theme('list_items', '#links_' + doc.id, items);

this doesn't:

  var items = [];
  items = items.concat(this.facetLinks('source', [doc.source]));
  items = items.concat(this.facetLinks('region', [doc.region]));
  items = items.concat(this.facetLinks('classification', [doc.classification]));
  AjaxSolr.theme('list_items', '#links_' + doc.id, items);

Hmmm, strange. I'm not a JS-expert so I don't have a clue why it behaves the way it does...

Cheers

Was there a problem with the other two? If not, then don't add the brackets.

On 2012-03-28, at 2:39 AM, kodo65 wrote:

Currently I have three "facets": Sources, Regions and Classifications and they're managed by the following code in ResultWidget.js:

 var items = [];
 items = items.concat(this.facetLinks('source', doc.source));
 items = items.concat(this.facetLinks('region', doc.region));
 items = items.concat(this.facetLinks('classification', [doc.classification]));
 AjaxSolr.theme('list_items', '#links_' + doc.id, items);

I followed your recommendation and changed "doc.source" to "[doc.source]" and that solved the issue with "WITS" becoming "W I T S". However, as soon as I tried to enclose the two other "facets" the UI stopped working... >To clarify this works:

 var items = [];
 items = items.concat(this.facetLinks('source', [doc.source]));
 items = items.concat(this.facetLinks('region', doc.region));
 items = items.concat(this.facetLinks('classification', [doc.classification]));
 AjaxSolr.theme('list_items', '#links_' + doc.id, items);

this doesn't:

 var items = [];
 items = items.concat(this.facetLinks('source', [doc.source]));
 items = items.concat(this.facetLinks('region', [doc.region]));
 items = items.concat(this.facetLinks('classification', [doc.classification]));
 AjaxSolr.theme('list_items', '#links_' + doc.id, items);

Hmmm, strange. I'm not a JS-expert so I don't have a clue why it behaves the way it does...

Cheers


Reply to this email directly or view it on GitHub:
#11 (comment)

Hi!

Sorry for not giving feedback earlier:)

Here's the deal: If I enclose only one of the facetlinks with square brackets everything works but as soon as I enclose one more (no matter which) in square brackets the UI fails to load properly.

This works:

items = items.concat(this.facetLinks('source', [doc.source]));
items = items.concat(this.facetLinks('region', doc.region));
items = items.concat(this.facetLinks('classification', doc.classification));

This doesn't:

items = items.concat(this.facetLinks('source', [doc.source]));
items = items.concat(this.facetLinks('region', doc.region));
items = items.concat(this.facetLinks('classification', [doc.classification]));

Cheers

Ok, so what's the problem with just putting square brackets around one?

On 2012-04-02, at 12:59 PM, kodo65 wrote:

Hi!

Sorry for not giving feedback earlier:)

Here's the deal: If I enclose only one of the facetlinks with square brackets everything works but as soon as I enclose one more (no matter which) in square brackets the UI fails to load properly.

This works:

items = items.concat(this.facetLinks('source', [doc.source]));
items = items.concat(this.facetLinks('region', doc.region));
items = items.concat(this.facetLinks('classification', doc.classification));

This doesn't:

items = items.concat(this.facetLinks('source', [doc.source]));
items = items.concat(this.facetLinks('region', doc.region));
items = items.concat(this.facetLinks('classification', [doc.classification]));

Cheers


Reply to this email directly or view it on GitHub:
#11 (comment)

Those which hasn't been enclosed by square brackets are displayed with space characters in between as I mentioned in my initial posting!

can you add console.log(doc.region); to your code to see what doc.region looks like? It's hard to debug without having access to your website.

Need more info.