The goal is to hack core so that the search module will populate the search_node_links
table from uuid-link hrefs in node content.
Planned approach is to modify the parsing functions of search_index
in the core search.module
.
The targeted section of code is lines 633-643 of search.module
.
if (preg_match($node_regexp, $value, $match)) {
$path = drupal_get_normal_path($match[1]);
if (preg_match('!(?:node|book)/(?:view/)?([0-9]+)!i', $path, $match)) {
$linknid = $match[1];
if ($linknid > 0) {
$node = db_query('SELECT title, nid, vid FROM {node} WHERE nid = :nid', array(':nid' => $linknid), array('target' => 'slave'))->fetchObject();
$link = TRUE;
$linktitle = $node->title;
}
}
}
The plan is to use entity_uuid_load
to grab the nid
directly like so:
if (preg_match($uuid_regexp, $value, $match)) {
$entity = entity_uuid_load('node',$match);
$linknid = key($entity);
if ($linknid > 0) {
$node = db_query('SELECT title, nid, vid FROM {node} WHERE nid = :nid', array(':nid' => $linknid), array('target' => 'slave'))->fetchObject();
$link = TRUE;
$linktitle = $node->title;
}
}
I've used this code to pull a node title with $value
set to an HTML snippet containing a UUID-href link; however, this still seems to fail to populate the search_node_links
table.
$uuid_regexp
is working as expected, but here it is for reference along with $node_regexp
for comparison.
$node_regexp = '@href=[\'"]?(?:' . preg_quote($base_url, '@') . '/|' . preg_quote(base_path(), '@') . ')(?:\?q=)?/?((?![a-z]+:)[^\'">]+)[\'">]@i';
$uuid_regexp = '@href=[\'"]?(?:\[uuid-link:node:)([0-9a-f]{8}-(([0-9a-f]{4}-){3})[0-9a-f]{12})(?:\])(?:[\'">])@i';
And here is the UUID link format:
<a href="[uuid-link:node:dc2c18f0-0abb-43b9-899c-f7c0a16934fd]">UUID link</a>
I'm sure there's something I'm just not seeing in search.module
that is preventing this from working as desired. Any comments/support/pointers would be greatly appreciated.
UPDATE: Finding now that it's not UUIDs causing the issue, but aliased paths instead (probably combined with Global Redirect module). Tried the following code instead, still no change in search_node_links
.
if (preg_match($node_regexp, $value, $match)) {
$clean_url = preg_split('![(en)|(fr)]/!', $match[1])[1];
$path = drupal_lookup_path("source", $clean_url);
if (preg_match('!(?:node|book)/(?:view/)?([0-9]+)!i', $path, $match)) {
$linknid = $match[1];
if ($linknid > 0) {
$node = db_query('SELECT title, nid, vid FROM {node} WHERE nid = :nid', array(':nid' => $linknid), array('target' => 'slave'))->fetchObject();
$link = TRUE;
$linktitle = $node->title;
}
}
}
Again, this code is able to pull a node title but is not contributing to search_node_links
.