function HookAnnotateAllAfterreindexresource($ref) { // make sure annotation indexing isn't lost when doing a reindex. $notes = sql_query("select * from annotate_notes where ref='{$ref}'"); global $pagename; foreach ($notes as $note) { #Add annotation to keywords $keywordtext = substr(strstr($note['note'], ": "), 2); # don't add the username to the keywords add_keyword_mappings($ref, i18n_get_indexable($keywordtext), -1, false, false, "annotation_ref", $note['note_id']); } }
} set_time_limit(60 * 60 * 5); echo "<pre>"; $resources = sql_query("select r.ref,u.username,u.fullname from \ncollection_resource left join resource r on collection_resource.resource = r.ref \nleft outer join user u on r.created_by=u.ref where collection_resource.collection = '{$collection}' order by ref"); for ($n = 0; $n < count($resources); $n++) { $ref = $resources[$n]["ref"]; # Delete existing keywords sql_query("delete from resource_keyword where resource='{$ref}'"); # Index fields $data = get_resource_field_data($ref); for ($m = 0; $m < count($data); $m++) { if ($data[$m]["keywords_index"] == 1) { #echo $data[$m]["value"]; $value = $data[$m]["value"]; if ($data[$m]["type"] == 3 || $data[$m]["type"] == 2) { # Prepend a comma when indexing dropdowns $value = "," . $value; } # Date field? These need indexing differently. $is_date = $data[$m]["type"] == 4 || $data[$m]["type"] == 6; add_keyword_mappings($ref, i18n_get_indexable($value), $data[$m]["ref"], $data[$m]["partial_index"], $is_date); } } # Also index contributed by field. add_keyword_mappings($ref, $resources[$n]["username"] . " " . $resources[$n]["fullname"], -1); # Always index the resource ID as a keyword remove_keyword_mappings($ref, $ref, -1); add_keyword_mappings($ref, $ref, -1); $words = sql_value("select count(*) value from resource_keyword where resource='{$ref}'", 0); echo "Done {$ref} ({$n}/" . count($resources) . ") - {$words} words<br />\n"; }
function reindex_resource($ref) { global $index_contributed_by; # Reindex a resource. Delete all resource_keyword rows and create new ones. # Delete existing keywords sql_query("delete from resource_keyword where resource='$ref'"); # Index fields $data=get_resource_field_data($ref,false,false); # Fetch all fields and do not use permissions. for ($m=0;$m<count($data);$m++) { if ($data[$m]["keywords_index"]==1) { #echo $data[$m]["value"]; $value=$data[$m]["value"]; if ($data[$m]["type"]==3 || $data[$m]["type"]==2) { # Prepend a comma when indexing dropdowns $value="," . $value; } # Date field? These need indexing differently. $is_date=($data[$m]["type"]==4 || $data[$m]["type"]==6); add_keyword_mappings($ref,i18n_get_indexable($value),$data[$m]["ref"],$data[$m]["partial_index"],$is_date); } } # Also index contributed by field, unless disabled if ($index_contributed_by) { $resource=get_resource_data($ref); $userinfo=get_user($resource["created_by"]); add_keyword_mappings($ref,$userinfo["username"] . " " . $userinfo["fullname"],-1); } # Always index the resource ID as a keyword remove_keyword_mappings($ref, $ref, -1); add_keyword_mappings($ref, $ref, -1); hook("afterreindexresource","all",array($ref)); }
die("no"); } $top = getvalescaped('top', ''); $left = getvalescaped('left', ''); $width = getvalescaped('width', ''); $height = getvalescaped('height', ''); $text = getvalescaped('text', ''); $text = str_replace("<br />\n", " ", $text); // remove the breaks added by get.php $id = getvalescaped('id', ''); $preview_width = getvalescaped('pw', ''); $preview_height = getvalescaped('ph', ''); $oldtext = sql_value("select note value from annotate_notes where ref='{$ref}' and note_id='{$id}'", ""); if ($oldtext != "") { remove_keyword_mappings($ref, i18n_get_indexable($oldtext), -1, false, false, "annotation_ref", $id); } sql_query("delete from annotate_notes where ref='{$ref}' and note_id='{$id}'"); if (substr($text, 0, strlen($username)) != $username) { $text = $username . ": " . $text; } sql_query("insert into annotate_notes (ref,top_pos,left_pos,width,height,preview_width,preview_height,note,user) values ('{$ref}','{$top}','{$left}','{$width}','{$height}','{$preview_width}','{$preview_height}','{$text}','{$userref}') "); $annotateid = sql_insert_id(); echo $annotateid; $notes = sql_query("select * from annotate_notes where ref='{$ref}'"); sql_query("update resource set annotation_count=" . count($notes) . " where ref={$ref}"); #Add annotation to keywords $keywordtext = substr(strstr($text, ": "), 2); # don't add the username to the keywords debug("adding annotation to resource keywords. Keywords: " . $keywordtext); add_keyword_mappings($ref, i18n_get_indexable($keywordtext), -1, false, false, "annotation_ref", $annotateid); #add_keyword_mappings($ref,$text,-1);
<?php include_once "../../../include/db.php"; include_once "../../../include/authenticate.php"; include_once "../../../include/general.php"; include_once "../../../include/resource_functions.php"; $ref = getvalescaped("ref", ""); if ($ref == "") { die("no"); } $id = getvalescaped('id', ''); $oldtext = sql_value("select note value from annotate_notes where ref='{$ref}' and note_id='{$id}'", ""); if ($oldtext != "") { remove_keyword_mappings($ref, i18n_get_indexable($oldtext), -1, false, false, "annotation_ref", $id); debug("Annotation: deleting keyword: " . i18n_get_indexable($oldtext) . " from resource id: " . $ref); } $notes = sql_query("delete from annotate_notes where ref='{$ref}' and note_id='{$id}'"); $notes = sql_query("select * from annotate_notes where ref='{$ref}'"); sql_query("update resource set annotation_count=" . count($notes) . " where ref={$ref}");
$data = sql_query("select * from resource_data {$joindata} where resource_type_field='{$field}' and length(value)>0 {$conditionand} and value is not null"); $n = 0; $total = count($data); foreach ($data as $row) { $n++; $ref = $row["resource"]; $value = $row["value"]; if ($fieldinfo["type"] == 3 || $fieldinfo["type"] == 2 || $fieldinfo["type"] == 9) { # Prepend a comma when indexing dropdowns to ensure full value is also indexed $value = "," . $value; } # Date field? These need indexing differently. $is_date = $fieldinfo["type"] == 4 || $fieldinfo["type"] == 6; $is_html = $fieldinfo["type"] == 8; # function add_keyword_mappings($ref,$string,$resource_type_field,$partial_index=false,$is_date=false) add_keyword_mappings($ref, i18n_get_indexable($value), $field, $fieldinfo["partial_index"], $is_date, '', '', $is_html); echo "Done {$ref} - " . htmlspecialchars(substr($value, 0, 50)) . "... ({$n}/{$total})\n"; if ($n / 20 == floor($n / 20) || $n == $total) { ?> <script>window.scroll(0,document.height);</script><?php } flush(); } echo "Reindex complete\n\n\n"; } else { $extratext = ""; if ($collectionid != "") { $collectionname = sql_value("select name as value from collection where ref='{$collectionid}'", ''); $extratext = " for collection '" . $collectionname . "'"; } ?>
function i18n_get_indexable($text) { # For field names / values using the i18n syntax, return all language versions, as necessary for indexing. $text = trim($text); $text = str_replace("<br />", " ", $text); // make sure keywords don't get squashed together $text = strip_tags($text); $text = preg_replace('/~(.*?):/', ',', $text); // remove i18n strings, which shouldn't be in the keywords //echo $text;die(); # For multiple keywords, parse each keyword. if (substr($text, 0, 1) != "," && strpos($text, ",") !== false && strpos($text, "~") !== false) { $s = explode(",", $text); $out = ""; for ($n = 0; $n < count($s); $n++) { if ($n > 0) { $out .= ","; } $out .= i18n_get_indexable(trim($s[$n])); } return $out; } # Split $s = explode("~", $text); # Not a translatable field? if (count($s) < 2) { return $text; } $out = ""; for ($n = 1; $n < count($s); $n++) { if (substr($s[$n], 2, 1) != ":") { return $text; } if ($out != "") { $out .= ","; } $out .= substr($s[$n], 3); } return $out; }