README 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. Pure C searchd client API library
  2. Sphinx search engine, http://sphinxsearch.com/
  3. API notes
  4. ----------
  5. 1. API can either copy the contents of passed pointer arguments,
  6. or rely on the application that the pointer will not become invalid.
  7. This is controlled on per-client basis; see 'copy_args' argument
  8. to the sphinx_create() call.
  9. When 'copy_args' is true, API will create and manage a copy of every
  10. string and array passed to it. This causes additional malloc() pressure,
  11. but makes calling code easier to write.
  12. When 'copy_args' is false, API expects that pointers passed to
  13. sphinx_set_xxx() calls will still be valid at the time when sphinx_query()
  14. or sphinx_add_query() are called.
  15. Rule of thumb: when 'copy_args' is false, do not free query arguments
  16. until you have the search result. Example code for that case:
  17. VALID CODE:
  18. char * my_filter_name;
  19. my_filter_name = malloc ( 256 );
  20. strncpy ( my_filter_name, "test", 256 );
  21. sphinx_add_filter_range ( client, my_filter_name, 10, 20, false );
  22. result = sphinx_query ( client );
  23. free ( my_filter_name );
  24. my_filter_name = NULL;
  25. INVALID CODE:
  26. void setup_my_filter ( sphinx_client * client )
  27. {
  28. char buffer[256];
  29. strncpy ( buffer, "test", sizeof(buffer) );
  30. // INVALID! by the time when sphinx_query() is called,
  31. // buffer will be out of scope
  32. sphinx_add_filter_range ( client, buffer, 10, 20, false );
  33. }
  34. setup_my_filter ( client );
  35. result = sphinx_query ( client );
  36. --eof--