Commit d6c9271b authored by vermeul's avatar vermeul

improved regex to separate category and search-depth. Optimized categories-table in search result

parent 6f104a8d
......@@ -61,7 +61,6 @@ class YATA {
# $parser->getOptions()->optionUsed( 'math' );
#}
$title = $parser->getTitle();
$wikiPage = new WikiPage( $title );
$queries_found = preg_match_all(
......@@ -85,38 +84,49 @@ class YATA {
$field = 'wiki_text';
}
if( $field === 'category') {
# multiple categories are defined by using a comma ,
# between two categories.
$categories = preg_split('/\s*\,\s*/', $values);
$cat_ids = array();
foreach( $categories as $category ) {
# keep category for display
array_push($in_categories, $category);
foreach( $categories as $category_name ) {
# keep category name for display later
#array_push($in_categories, $category_name);
# remove the search-depth from the category name, e.g.
# category_name(1) --> category_name 1
# category_name[1] --> category_name 1
preg_match(
'/(?P<category>\w+)\s*(\((?P<depth>\d+)\))?/',
$category, $matches, PREG_OFFSET_CAPTURE
'/(?P<category>.*)(\[(?P<depth>\d+)\])|(?P<category_all>.*)/',
$category_name, $matches, PREG_OFFSET_CAPTURE
);
$category = $matches['category'][0];
$depth = null;
if (array_key_exists('depth', $matches)) {
$depth = $matches['depth'][0];
}
$category = array_key_exists('category_all', $matches) ? $matches['category_all'][0] : $matches['category'][0];
$depth = array_key_exists('depth', $matches) ? $matches['depth'][0] : null;
# get the category entry from DB
$cat = self::get_category($dbr, $category);
$in_categories[] = $cat->name;
if ($cat) {
$cat_ids[] = $cat->id;
if ($depth) {
$child_categories = self::get_child_categories($dbr, $cat, 0, $depth-1);
foreach($child_categories as $child_category) {
$cat_ids[] = $child_category->id;
$in_categories[] = $child_category->name;
}
}
elseif ($depth === "") {
$child_categories = self::get_child_categories($dbr, $cat, 0, null);
foreach($child_categories as $child_category) {
$cat_ids[] = $child_category->id;
$in_categories[] = $child_category->name;
}
}
}
else {
array_push($errors, "no such category found: $category");
}
}
$where[] =
"EXISTS(
......@@ -246,12 +256,14 @@ class YATA {
}
if ($in_categories) {
$table .= "<b>Search in Categories:</b>";
$table .="<pre>";
foreach($in_categories as $category) {
$table .= "<pre>".$category."</pre>";
$table .= "\n".$category;
}
$table .="</pre>";
}
$table .= "<b>Results of annotask query: </b>";
$table .= "<b>" . $dbr->numRows($annotations). " Results of annotask query: </b>";
$table .= '([' . $title->getFullURL() . '?action=purge' . ' refresh page]):';
if ($dbr->numRows($annotations) > 0) {
......@@ -609,7 +621,6 @@ EOT;
}
catch (Exception $e) {
print($e->getMessage());
die;
}
}
# keep track of all the annotations we have seen on this page,
......@@ -1032,6 +1043,7 @@ EOT;
'c.hashtag' => $category,
)
);
#print($dbr->lastQuery($row));
return $row;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment