| 202 | | my $data = get_pd_indexes($blog_id) || get_db_indexes($blog_id); |
|---|
| 203 | | if ($data) { |
|---|
| 204 | | my %tindex = %{$data->{tindex}}; |
|---|
| 205 | | if ($case_sensitive) { |
|---|
| 206 | | map { $tags{$_} = scalar(@{$tindex{$_}}) } keys %tindex; |
|---|
| 207 | | } else { |
|---|
| 208 | | map { $tags{lc $_} += scalar(@{$tindex{$_}}) } keys %tindex; |
|---|
| 209 | | } |
|---|
| 210 | | } else { |
|---|
| 211 | | require MT::Entry; |
|---|
| 212 | | my $iter = MT::Entry->load_iter({ blog_id => $blog_id, |
|---|
| 213 | | status => MT::Entry::RELEASE() }); |
|---|
| 214 | | while (my $e = $iter->()) { |
|---|
| 215 | | next unless $e->keywords; |
|---|
| 216 | | my @etags = split_tags($e->keywords, $case_sensitive); |
|---|
| 217 | | foreach my $etag (@etags) { |
|---|
| 218 | | $tags{$etag} = exists $tags{$etag} ? $tags{$etag} + 1 : 1; |
|---|
| 219 | | } |
|---|
| 220 | | } |
|---|
| | 207 | my $data = get_pd_indexes($blog_id) || get_db_indexes($blog_id) |
|---|
| | 208 | or return ''; |
|---|
| | 209 | my %tindex = %{$data->{tindex}}; |
|---|
| | 210 | if ($case_sensitive) { |
|---|
| | 211 | map { $tags{$_} = scalar(@{$tindex{$_}}) } keys %tindex; |
|---|
| | 212 | } else { |
|---|
| | 213 | map { $tags{lc $_} += scalar(@{$tindex{$_}}) } keys %tindex; |
|---|
| 327 | | my @patterns = split_args($search, $delimiter, $case_sensitive); |
|---|
| 328 | | |
|---|
| 329 | | my $data = get_pd_indexes($blog_id) || get_db_indexes($blog_id); |
|---|
| 330 | | if ($data) { |
|---|
| 331 | | my %tindex = %{$data->{tindex}}; |
|---|
| 332 | | my %eindex = %{$data->{eindex}}; |
|---|
| 333 | | my %match; |
|---|
| 334 | | if ($case_sensitive) { |
|---|
| 335 | | foreach my $tag (@patterns) { |
|---|
| 336 | | foreach my $eid (@{$tindex{$tag}}) { |
|---|
| | 323 | |
|---|
| | 324 | my $data = get_pd_indexes($blog_id) || get_db_indexes($blog_id) |
|---|
| | 325 | or return ''; |
|---|
| | 326 | my %tindex = %{$data->{tindex}}; |
|---|
| | 327 | my %eindex = %{$data->{eindex}}; |
|---|
| | 328 | my %match; |
|---|
| | 329 | if ($case_sensitive) { |
|---|
| | 330 | foreach my $tag (@patterns) { |
|---|
| | 331 | foreach my $eid (@{$tindex{$tag}}) { |
|---|
| | 332 | $match{$eid} = exists $match{$eid} ? $match{$eid} + 1 : 1; |
|---|
| | 333 | } |
|---|
| | 334 | } |
|---|
| | 335 | } else { |
|---|
| | 336 | foreach my $tag (@patterns) { |
|---|
| | 337 | foreach my $mtag (grep { lc $_ eq $tag } keys %tindex) { |
|---|
| | 338 | foreach my $eid (@{$tindex{$mtag}}) { |
|---|
| 340 | | } else { |
|---|
| 341 | | foreach my $tag (@patterns) { |
|---|
| 342 | | foreach my $mtag (grep { lc $_ eq $tag } keys %tindex) { |
|---|
| 343 | | foreach my $eid (@{$tindex{$mtag}}) { |
|---|
| 344 | | $match{$eid} = exists $match{$eid} ? $match{$eid} + 1 : 1; |
|---|
| 345 | | } |
|---|
| 346 | | } |
|---|
| 347 | | } |
|---|
| 348 | | } |
|---|
| 349 | | my $count = scalar @patterns; |
|---|
| 350 | | my @eids = grep { $match{$_} == $count } keys %match or return; |
|---|
| 351 | | @eids = sort { $eindex{$b}->{created_on} <=> $eindex{$a}->{created_on} } @eids; |
|---|
| 352 | | @eids = $sort_order eq 'descend' ? |
|---|
| 353 | | sort { $eindex{$b}->{created_on} <=> $eindex{$a}->{created_on} } @eids : |
|---|
| 354 | | sort { $eindex{$a}->{created_on} <=> $eindex{$b}->{created_on} } @eids; |
|---|
| 355 | | require MT::Entry; |
|---|
| 356 | | map { push @entries, MT::Entry->load($_) } @eids; |
|---|
| 357 | | # The above code is sticked to "created_on". |
|---|
| 358 | | } else { |
|---|
| 359 | | require MT::Entry; |
|---|
| 360 | | my $iter = MT::Entry->load_iter({ blog_id => $blog_id, |
|---|
| 361 | | status => MT::Entry::RELEASE() }, |
|---|
| 362 | | { sort => $sort_by, |
|---|
| 363 | | direction => $sort_order }); |
|---|
| 364 | | my $i = 0; |
|---|
| 365 | | while (my $e = $iter->()) { |
|---|
| 366 | | last if $lastn && $i >= $lastn; |
|---|
| 367 | | next unless $e->keywords; |
|---|
| 368 | | my @tags = split_tags($e->keywords, $case_sensitive); |
|---|
| 369 | | my $check = 1; |
|---|
| 370 | | foreach my $pattern (@patterns) { |
|---|
| 371 | | unless (scalar grep { $_ eq $pattern } @tags) { |
|---|
| 372 | | $check = 0; |
|---|
| 373 | | last; |
|---|
| 374 | | } |
|---|
| 375 | | } |
|---|
| 376 | | if ($check) { |
|---|
| 377 | | push @entries, $e; |
|---|
| 378 | | $i++; |
|---|
| 379 | | } |
|---|
| 380 | | } |
|---|
| 381 | | return '' unless @entries; |
|---|
| 382 | | } |
|---|
| | 342 | } |
|---|
| | 343 | } |
|---|
| | 344 | my $count = scalar @patterns; |
|---|
| | 345 | my @eids = grep { $match{$_} == $count } keys %match or return; |
|---|
| | 346 | @eids = sort { $eindex{$b}->{created_on} <=> $eindex{$a}->{created_on} } @eids; |
|---|
| | 347 | @eids = $sort_order eq 'descend' ? |
|---|
| | 348 | sort { $eindex{$b}->{created_on} <=> $eindex{$a}->{created_on} } @eids : |
|---|
| | 349 | sort { $eindex{$a}->{created_on} <=> $eindex{$b}->{created_on} } @eids; |
|---|
| | 350 | splice(@eids, $lastn) if $lastn && (scalar @eids > $lastn); |
|---|
| | 351 | require MT::Entry; |
|---|
| | 352 | map { push @entries, MT::Entry->load($_) } @eids; |
|---|
| 425 | | my %match = (); |
|---|
| 426 | | |
|---|
| 427 | | my $data = get_pd_indexes($blog_id) || get_db_indexes($blog_id); |
|---|
| 428 | | if ($data) { |
|---|
| 429 | | my %tindex = %{$data->{tindex}}; |
|---|
| 430 | | my %eindex = %{$data->{eindex}}; |
|---|
| 431 | | my %match; |
|---|
| 432 | | if ($case_sensitive) { |
|---|
| 433 | | foreach my $tag (@patterns) { |
|---|
| 434 | | foreach my $eid (@{$tindex{$tag}}) { |
|---|
| | 397 | |
|---|
| | 398 | my $data = get_pd_indexes($blog_id) || get_db_indexes($blog_id) |
|---|
| | 399 | or return ''; |
|---|
| | 400 | my %tindex = %{$data->{tindex}}; |
|---|
| | 401 | my %eindex = %{$data->{eindex}}; |
|---|
| | 402 | my %match; |
|---|
| | 403 | if ($case_sensitive) { |
|---|
| | 404 | foreach my $tag (@patterns) { |
|---|
| | 405 | foreach my $eid (@{$tindex{$tag}}) { |
|---|
| | 406 | next if $eid == $entry->id; |
|---|
| | 407 | $match{$eid} = exists $match{$eid} ? $match{$eid} + 1 : 1; |
|---|
| | 408 | } |
|---|
| | 409 | } |
|---|
| | 410 | } else { |
|---|
| | 411 | foreach my $tag (@patterns) { |
|---|
| | 412 | foreach my $mtag (grep { lc $_ eq $tag } keys %tindex) { |
|---|
| | 413 | foreach my $eid (@{$tindex{$mtag}}) { |
|---|
| 440 | | } else { |
|---|
| 441 | | foreach my $tag (@patterns) { |
|---|
| 442 | | foreach my $mtag (grep { lc $_ eq $tag } keys %tindex) { |
|---|
| 443 | | foreach my $eid (@{$tindex{$mtag}}) { |
|---|
| 444 | | next if $eid == $entry->id; |
|---|
| 445 | | $match{$eid} = exists $match{$eid} ? |
|---|
| 446 | | $match{$eid} + 1 : 1; |
|---|
| 447 | | } |
|---|
| 448 | | } |
|---|
| 449 | | } |
|---|
| 450 | | } |
|---|
| 451 | | my @eids = keys %match or return ''; |
|---|
| 452 | | @eids = sort { $eindex{$b}->{created_on} <=> $eindex{$a}->{created_on} } @eids; |
|---|
| 453 | | @eids = sort { $match{$b} <=> $match{$a} } @eids; |
|---|
| 454 | | splice(@eids, $lastn) if $lastn && (scalar @eids > $lastn); |
|---|
| 455 | | require MT::Entry; |
|---|
| 456 | | map { push @entries, MT::Entry->load($_) } @eids; |
|---|
| 457 | | return '' unless @entries; |
|---|
| 458 | | } else { |
|---|
| 459 | | require MT::Entry; |
|---|
| 460 | | my $iter = MT::Entry->load_iter({ blog_id => $blog_id, |
|---|
| 461 | | status => MT::Entry::RELEASE() }, |
|---|
| 462 | | { sort => 'created_on', |
|---|
| 463 | | direction => 'descend' }); |
|---|
| 464 | | while (my $e = $iter->()) { |
|---|
| 465 | | next unless $e->keywords; |
|---|
| 466 | | next if $e->id == $entry->id; |
|---|
| 467 | | my @tags = split_tags($e->keywords, $case_sensitive); |
|---|
| 468 | | my $count = 0; |
|---|
| 469 | | foreach my $pattern (@patterns) { |
|---|
| 470 | | $count++ if (scalar grep { $_ eq $pattern } @tags); |
|---|
| 471 | | } |
|---|
| 472 | | if ($count) { |
|---|
| 473 | | push @entries, $e; |
|---|
| 474 | | $match{ $e->id } = $count; |
|---|
| 475 | | } |
|---|
| 476 | | } |
|---|
| 477 | | return '' unless @entries; |
|---|
| 478 | | |
|---|
| 479 | | @entries = sort { $match{$b->id} <=> $match{$a->id} } @entries; |
|---|
| 480 | | splice(@entries, $lastn) if $lastn && (scalar @entries > $lastn); |
|---|
| 481 | | } |
|---|
| | 418 | } |
|---|
| | 419 | } |
|---|
| | 420 | my @eids = keys %match or return ''; |
|---|
| | 421 | @eids = $sort_order eq 'descend' ? |
|---|
| | 422 | sort { $eindex{$b}->{created_on} <=> $eindex{$a}->{created_on} } @eids : |
|---|
| | 423 | sort { $eindex{$a}->{created_on} <=> $eindex{$b}->{created_on} } @eids; |
|---|
| | 424 | @eids = sort { $match{$b} <=> $match{$a} } @eids; |
|---|
| | 425 | splice(@eids, $lastn) if $lastn && (scalar @eids > $lastn); |
|---|
| | 426 | require MT::Entry; |
|---|
| | 427 | map { push @entries, MT::Entry->load($_) } @eids; |
|---|
| | 428 | return '' unless @entries; |
|---|
| 535 | | my $data = get_pd_indexes($blog_id) || get_db_indexes($blog_id); |
|---|
| 536 | | if ($data) { |
|---|
| 537 | | my %tindex = %{$data->{tindex}}; |
|---|
| 538 | | my %eindex = %{$data->{eindex}}; |
|---|
| 539 | | my %match; |
|---|
| 540 | | if ($case_sensitive) { |
|---|
| 541 | | foreach my $tag (@patterns) { |
|---|
| 542 | | foreach my $eid (@{$tindex{$tag}}) { |
|---|
| 543 | | $match{$eid} = exists $match{$eid} ? |
|---|
| 544 | | $match{$eid} + 1 : 1; |
|---|
| | 482 | my $data = get_pd_indexes($blog_id) || get_db_indexes($blog_id) |
|---|
| | 483 | or return \@results; |
|---|
| | 484 | my %tindex = %{$data->{tindex}}; |
|---|
| | 485 | my %eindex = %{$data->{eindex}}; |
|---|
| | 486 | my %match; |
|---|
| | 487 | if ($case_sensitive) { |
|---|
| | 488 | foreach my $tag (@patterns) { |
|---|
| | 489 | foreach my $eid (@{$tindex{$tag}}) { |
|---|
| | 490 | $match{$eid} = exists $match{$eid} ? $match{$eid} + 1 : 1; |
|---|
| | 491 | } |
|---|
| | 492 | } |
|---|
| | 493 | } else { |
|---|
| | 494 | foreach my $tag (@patterns) { |
|---|
| | 495 | foreach my $mtag (grep { lc $_ eq $tag } keys %tindex) { |
|---|
| | 496 | foreach my $eid (@{$tindex{$mtag}}) { |
|---|
| | 497 | $match{$eid} = exists $match{$eid} ? $match{$eid} + 1 : 1; |
|---|
| 547 | | } else { |
|---|
| 548 | | foreach my $tag (@patterns) { |
|---|
| 549 | | foreach my $mtag (grep { lc $_ eq $tag } keys %tindex) { |
|---|
| 550 | | foreach my $eid (@{$tindex{$mtag}}) { |
|---|
| 551 | | $match{$eid} = exists $match{$eid} ? |
|---|
| 552 | | $match{$eid} + 1 : 1; |
|---|
| 553 | | } |
|---|
| 554 | | } |
|---|
| 555 | | } |
|---|
| 556 | | } |
|---|
| 557 | | my $count = scalar @patterns; |
|---|
| 558 | | my @eids = grep { $match{$_} == $count } keys %match |
|---|
| 559 | | or return; |
|---|
| 560 | | @eids = $sort_order eq 'descend' ? |
|---|
| 561 | | sort { $eindex{$b}->{created_on} <=> $eindex{$a}->{created_on} } @eids : |
|---|
| 562 | | sort { $eindex{$a}->{created_on} <=> $eindex{$b}->{created_on} } @eids; |
|---|
| 563 | | require MT::Entry; |
|---|
| 564 | | map { push @results, MT::Entry->load($_) } @eids; |
|---|
| 565 | | # The above code is sticked to "created_on". |
|---|
| 566 | | } else { |
|---|
| 567 | | my $iter = MT::Entry->load_iter({ blog_id => $blog_id, |
|---|
| 568 | | status => MT::Entry::RELEASE() }, |
|---|
| 569 | | { sort => $sort_by, |
|---|
| 570 | | direction => $sort_order }); |
|---|
| 571 | | while (my $e = $iter->()) { |
|---|
| 572 | | next unless $e->keywords; |
|---|
| 573 | | my @tags = split_tags($e->keywords, $case_sensitive) |
|---|
| 574 | | or next; |
|---|
| 575 | | my $check = 1; |
|---|
| 576 | | foreach my $pattern (@patterns) { |
|---|
| 577 | | unless (scalar grep { $_ eq $pattern } @tags) { |
|---|
| 578 | | $check = 0; |
|---|
| 579 | | last; |
|---|
| 580 | | } |
|---|
| 581 | | } |
|---|
| 582 | | push @results, $e if $check; |
|---|
| 583 | | } |
|---|
| 584 | | } |
|---|
| | 500 | } |
|---|
| | 501 | } |
|---|
| | 502 | my $count = scalar @patterns; |
|---|
| | 503 | my @eids = grep { $match{$_} == $count } keys %match |
|---|
| | 504 | or return \@results; |
|---|
| | 505 | @eids = $sort_order eq 'descend' ? |
|---|
| | 506 | sort { $eindex{$b}->{created_on} <=> $eindex{$a}->{created_on} } @eids : |
|---|
| | 507 | sort { $eindex{$a}->{created_on} <=> $eindex{$b}->{created_on} } @eids; |
|---|
| | 508 | require MT::Entry; |
|---|
| | 509 | map { push @results, MT::Entry->load($_) } @eids; |
|---|