Hi Chris,

The theme function theme_luceneapi_morelikethis_block($items) does not expose the node nid. The $items array contains the node title and node path (alias, not drupal), but not the node nid. Therefore, to attain the node->nid, one would have to query the db which seems really unecessary, seeing as the function _luceneapi_morelikethis_block_view that calls the theming function has all the needed information, but simply does not pass it along.

Can this be added?
best wishes
scotjam

Comments

cpliakas’s picture

Assigned: Unassigned » cpliakas
Category: feature » task

This is a feature that most definitely should be added. Look for it in the next alpha release.

Thanks,
Chris

cpliakas’s picture

Assigned: cpliakas » Unassigned
Category: task » feature

Hi scotjam,

After having some time to read through my own code and think about this a little more, you can actually just call the luceneapi_morelikethis_nid_get() function to obtain the node ID. It statically caches the node ID that it calculates, so only one query is executed no matter how many times you call it. I think that it makes the most sense to make use this function as opposed to passing a node ID to the theme function, but I am willing to discuss. My thinking is that there might be cases in the future when non-node text is used as the source when calculating a moreLikeThis query, so a node ID might not always be available.

Either way, thanks for pointing out this use case and making me think more about it,
Chris

cpliakas’s picture

Assigned: Unassigned » cpliakas
Category: feature » task

Please disregard the last post, as I misunderstood what you meant. The item (in this case the node), should most definitely be available for the matched items. Obviously I was thinking about the node being used as the source text. Changing back to a task to make this information available.

cpliakas’s picture

Status: Active » Fixed

A solution has been committed at #264652. The entire hit object is attached to each item in $itmes, so you will be able to get the node ID. Code example is below:


/**
 * Implementation of theme_luceneapi_morelikethis_item().
 *
 * $item now has the 'hit' key in addition to 'title' and 'link'.
 */
function mytheme_luceneapi_morelikethis_item($item) {
  $output = '';

  // get the node ID for the matched item
  $nid = $item['hit']->nid;

  // do whetever you need to do to format the return value
  // ...
  // ...
  return $output;
}

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.