test2.php 965 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. //
  3. // $Id$
  4. //
  5. require ( "sphinxapi.php" );
  6. $docs = array
  7. (
  8. "this is my test text to be highlighted, and for the sake of the testing we need to pump its length somewhat",
  9. "another test text to be highlighted, below limit",
  10. "test number three, without phrase match",
  11. "final test, not only without phrase match, but also above limit and with swapped phrase text test as well",
  12. );
  13. $words = "test text";
  14. $index = "test1";
  15. $opts = array
  16. (
  17. "before_match" => "<b>",
  18. "after_match" => "</b>",
  19. "chunk_separator" => " ... ",
  20. "limit" => 60,
  21. "around" => 3,
  22. );
  23. foreach ( array(0,1) as $exact )
  24. {
  25. $opts["exact_phrase"] = $exact;
  26. print "exact_phrase=$exact\n";
  27. $cl = new SphinxClient ();
  28. $res = $cl->BuildExcerpts ( $docs, $index, $words, $opts );
  29. if ( !$res )
  30. {
  31. die ( "ERROR: " . $cl->GetLastError() . ".\n" );
  32. } else
  33. {
  34. $n = 0;
  35. foreach ( $res as $entry )
  36. {
  37. $n++;
  38. print "n=$n, res=$entry\n";
  39. }
  40. print "\n";
  41. }
  42. }
  43. //
  44. // $Id$
  45. //
  46. ?>