general_api_functions.rst 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. General API functions
  2. ---------------------
  3. .. _get_last_error:
  4. GetLastError
  5. ~~~~~~~~~~~~
  6. Prototype: function GetLastError()
  7. Returns last error message, as a string, in human readable format. If
  8. there were no errors during the previous API call, empty string is
  9. returned.
  10. You should call it when any other function (such as
  11. :ref:`Query() <query>`) fails (typically, the failing
  12. function returns false). The returned string will contain the error
  13. description.
  14. The error message is *not* reset by this call; so you can safely call it
  15. several times if needed.
  16. .. _get_last_warning:
  17. GetLastWarning
  18. ~~~~~~~~~~~~~~
  19. **Prototype:** function GetLastWarning ()
  20. Returns last warning message, as a string, in human readable format. If
  21. there were no warnings during the previous API call, empty string is
  22. returned.
  23. You should call it to verify whether your request (such as
  24. :ref:`Query() <query>`) was completed but with warnings.
  25. For instance, search query against a distributed index might complete
  26. successfully even if several remote agents timed out. In that case, a
  27. warning message would be produced.
  28. The warning message is *not* reset by this call; so you can safely call
  29. it several times if needed.
  30. .. _set_server:
  31. SetServer
  32. ~~~~~~~~~
  33. **Prototype:** function SetServer ( $host, $port )
  34. Sets ``searchd`` host name and TCP port. All subsequent requests will
  35. use the new host and port settings. Default host and port are
  36. ‘localhost’ and 9312, respectively.
  37. .. _set_retries:
  38. SetRetries
  39. ~~~~~~~~~~
  40. **Prototype:** function SetRetries ( $count, $delay=0 )
  41. Sets distributed retry count and delay.
  42. On temporary failures ``searchd`` will attempt up to ``$count`` retries
  43. per agent. ``$delay`` is the delay between the retries, in milliseconds.
  44. Retries are disabled by default. Note that this call will **not**
  45. make the API itself retry on temporary failure; it only tells
  46. ``searchd`` to do so. Currently, the list of temporary failures includes
  47. all kinds of connect() failures and maxed out (too busy) remote agents.
  48. .. _set_connect_timeout:
  49. SetConnectTimeout
  50. ~~~~~~~~~~~~~~~~~
  51. **Prototype:** function SetConnectTimeout ( $timeout )
  52. Sets the time allowed to spend connecting to the server before giving
  53. up.
  54. Under some circumstances, the server can be delayed in responding,
  55. either due to network delays, or a query backlog. In either instance,
  56. this allows the client application programmer some degree of control
  57. over how their program interacts with ``searchd`` when not available,
  58. and can ensure that the client application does not fail due to
  59. exceeding the script execution limits (especially in PHP).
  60. In the event of a failure to connect, an appropriate error code should
  61. be returned back to the application in order for application-level error
  62. handling to advise the user.
  63. .. _set_array_result:
  64. SetArrayResult
  65. ~~~~~~~~~~~~~~
  66. **Prototype:** function SetArrayResult ( $arrayresult )
  67. PHP specific. Controls matches format in the search results set (whether
  68. matches should be returned as an array or a hash).
  69. ``$arrayresult`` argument must be boolean. If ``$arrayresult`` is
  70. ``false`` (the default mode), matches will returned in PHP hash format
  71. with document IDs as keys, and other information (weight, attributes) as
  72. values. If ``$arrayresult`` is true, matches will be returned as a plain
  73. array with complete per-match information including document ID.
  74. Introduced along with GROUP BY support on MVA attributes. Group-by-MVA
  75. result sets may contain duplicate document IDs. Thus they need to be
  76. returned as plain arrays, because hashes will only keep one entry per
  77. document ID.
  78. .. _is_connect_error:
  79. IsConnectError
  80. ~~~~~~~~~~~~~~
  81. **Prototype:** function IsConnectError ()
  82. Checks whether the last error was a network error on API side, or a
  83. remote error reported by searchd. Returns true if the last connection
  84. attempt to searchd failed on API side, false otherwise (if the error was
  85. remote, or there were no connection attempts at all).