YAZ  4.2.57
Data Structures | Macros | Typedefs | Functions
solr.h File Reference

Header with public definitions about Solr. More...

#include <stdio.h>
#include <yaz/nmem.h>

Go to the source code of this file.

Data Structures

struct  solr_node
 SOLR parse tree (node) More...
struct  solr_buf_write_info
 Structure used by solr_buf_write_handler. More...

Macros

#define SOLR_NODE_ST   1
 Node type: search term.
#define SOLR_NODE_BOOL   2
 Node type: boolean.

Typedefs

typedef struct solr_parser * SOLR_parser
 SOLR parser handle (opaque pointer)
typedef struct solr_transform_t_solr_transform_t
 SOLR transform handle. The transform describes how to convert from SOLR to PQF (Type-1 AKA RPN).

Functions

SOLR_parser solr_parser_create (void)
 creates a SOLR parser.
void solr_parser_destroy (SOLR_parser cp)
 destroys a SOLR parser.
int solr_parser_string (SOLR_parser cp, const char *str)
 parses a SOLR query (string)
int solr_parser_stream (SOLR_parser cp, int(*getbyte)(void *client_data), void(*ungetbyte)(int b, void *client_data), void *client_data)
 parses SOLR query (query stream)
int solr_parser_stdio (SOLR_parser cp, FILE *f)
 parses SOLR query (from FILE)
void solr_buf_write_handler (const char *b, void *client_data)
 Handler for solr_buf_write_info.
void solr_node_print (struct solr_node *cn)
 Prints a SOLR node and all sub nodes. Hence this function prints the parse tree which is as returned by solr_parser_result.
struct solr_nodesolr_node_mk_sc (NMEM nmem, const char *index, const char *relation, const char *term)
 creates a search clause node (st).
struct solr_nodesolr_apply_prefix (NMEM nmem, struct solr_node *cn, const char *prefix, const char *uri)
 applies a prefix+uri to "unresolved" index and relation URIs. "unresolved" URIs are those nodes where member index_uri / relation_uri is NULL.
struct solr_nodesolr_node_mk_boolean (NMEM nmem, const char *op)
 creates a boolean node.
void solr_node_destroy (struct solr_node *cn)
 destroys a node and its children.
struct solr_nodesolr_node_dup (NMEM nmem, struct solr_node *cp)
struct solr_nodesolr_parser_result (SOLR_parser cp)
 returns the parse tree of the most recently parsed SOLR query.
void solr_to_xml (struct solr_node *cn, void(*pr)(const char *buf, void *client_data), void *client_data)
 converts SOLR tree to XSOLR and writes to user-defined stream
void solr_to_xml_stdio (struct solr_node *cn, FILE *f)
 converts SOLR tree to XSOLR and writes to file
int solr_to_xml_buf (struct solr_node *cn, char *out, int max)
 converts SOLR tree to XSOLR and writes result to buffer
void solr_fputs (const char *buf, void *client_data)
 stream handle for file (used by solr_to_xml_stdio)
solr_transform_t solr_transform_create (void)
 creates a SOLR transform handle
solr_transform_t solr_transform_open_FILE (FILE *f)
 creates a SOLR transform handle from am opened file handle
solr_transform_t solr_transform_open_fname (const char *fname)
 creates a SOLR transform handle from a file
int solr_transform_define_pattern (solr_transform_t ct, const char *pattern, const char *value)
 defines SOLR transform pattern
void solr_transform_close (solr_transform_t ct)
 destroys a SOLR transform handle
int solr_transform (solr_transform_t ct, struct solr_node *cn, void(*pr)(const char *buf, void *client_data), void *client_data)
 tranforms PQF given a SOLR tree
int solr_transform_FILE (solr_transform_t ct, struct solr_node *cn, FILE *f)
 transforms PQF given a SOLR tree (from FILE)
int solr_transform_buf (solr_transform_t ct, struct solr_node *cn, char *out, int max)
 transforms PQF given a SOLR tree (from FILE)
int solr_transform_error (solr_transform_t ct, const char **addinfo)
 returns additional information for last transform
void solr_transform_set_error (solr_transform_t ct, int error, const char *addinfo)
 sets error and addinfo for transform
const char * solr_strerror (int code)
 returns the SOLR message corresponding to a given error code.
const char * solr_uri (void)
 returns the standard SOLR context set URI.
int solr_strcmp (const char *s1, const char *s2)
 compares two SOLR strings (ala strcmp)
int solr_strncmp (const char *s1, const char *s2, size_t n)
 compares two SOLR strings (ala strncmp)

Detailed Description

Header with public definitions about Solr.

Definition in file solr.h.

Macro Definition Documentation

#define SOLR_NODE_BOOL   2

Node type: boolean.

Definition at line 102 of file solr.h.

Referenced by solr_transform_r().

#define SOLR_NODE_ST   1

Node type: search term.

Definition at line 100 of file solr.h.

Referenced by emit_term(), and solr_transform_r().

Typedef Documentation

typedef struct solr_parser* SOLR_parser

SOLR parser handle (opaque pointer)

Definition at line 40 of file solr.h.

SOLR transform handle. The transform describes how to convert from SOLR to PQF (Type-1 AKA RPN).

Definition at line 228 of file solr.h.

Function Documentation

struct solr_node* solr_apply_prefix ( NMEM  nmem,
struct solr_node cn,
const char *  prefix,
const char *  uri 
)
read

applies a prefix+uri to "unresolved" index and relation URIs. "unresolved" URIs are those nodes where member index_uri / relation_uri is NULL.

void solr_buf_write_handler ( const char *  b,
void *  client_data 
)
void solr_fputs ( const char *  buf,
void *  client_data 
)

stream handle for file (used by solr_to_xml_stdio)

void solr_node_destroy ( struct solr_node cn)

destroys a node and its children.

struct solr_node* solr_node_dup ( NMEM  nmem,
struct solr_node cp 
)
read

duplicates a node (returns a copy of supplied node) .

struct solr_node* solr_node_mk_boolean ( NMEM  nmem,
const char *  op 
)
read

creates a boolean node.

struct solr_node* solr_node_mk_sc ( NMEM  nmem,
const char *  index,
const char *  relation,
const char *  term 
)
read

creates a search clause node (st).

void solr_node_print ( struct solr_node cn)

Prints a SOLR node and all sub nodes. Hence this function prints the parse tree which is as returned by solr_parser_result.

SOLR_parser solr_parser_create ( void  )

creates a SOLR parser.

Returns
CCL parser

Returns SOLR parser or NULL if parser could not be created.

void solr_parser_destroy ( SOLR_parser  cp)

destroys a SOLR parser.

Parameters
cpSOLR parser

This function does nothing if NULL if received.

struct solr_node* solr_parser_result ( SOLR_parser  cp)
read

returns the parse tree of the most recently parsed SOLR query.

Parameters
cpSOLR parser
Returns
SOLR node or NULL for failure
int solr_parser_stdio ( SOLR_parser  cp,
FILE *  f 
)

parses SOLR query (from FILE)

Parameters
cpSOLR parser
ffile where query is read from
Return values
0success
!=0failure

This function is similar to solr_parser_string but reads from stdio FILE handle instead.

int solr_parser_stream ( SOLR_parser  cp,
int(*)(void *client_data)  getbyte,
void(*)(int b, void *client_data)  ungetbyte,
void *  client_data 
)

parses SOLR query (query stream)

Parameters
cpSOLR parser
getbytefunction which reads one character from stream
ungetbytefunction which unreads one character from stream
client_datadata to be passed to stream functions
Return values
0success
!=0failure

This function is similar to solr_parser_string but takes a functions to read each query character from a stream.

The functions pointers getbytes, ungetbyte are similar to that known from stdios getc, ungetc.

int solr_parser_string ( SOLR_parser  cp,
const char *  str 
)

parses a SOLR query (string)

Parameters
cpSOLR parser
strSOLR string
Return values
0success
!=0failure
int solr_strcmp ( const char *  s1,
const char *  s2 
)

compares two SOLR strings (ala strcmp)

Parameters
s1string 1
s2string 2
Returns
comparison value Compares two SOLR strings (for relations, operators, etc) (unfortunately defined as case-insensitive unlike XML etc)

Definition at line 45 of file solrtransform.c.

References cql_strcmp().

Referenced by solr_lookup_property(), and solr_transform_r().

const char* solr_strerror ( int  code)

returns the SOLR message corresponding to a given error code.

Parameters
codeerror code
Returns
text message
int solr_strncmp ( const char *  s1,
const char *  s2,
size_t  n 
)

compares two SOLR strings (ala strncmp)

Parameters
s1string 1
s2string 2
nsize
Returns
comparison value Compares two SOLR strings at most n bytes (unfortunately defined as case-insensitive unlike XML etc)

Definition at line 49 of file solrtransform.c.

References cql_strncmp().

void solr_to_xml ( struct solr_node cn,
void(*)(const char *buf, void *client_data)  pr,
void *  client_data 
)

converts SOLR tree to XSOLR and writes to user-defined stream

Parameters
cnSOLR node (tree)
prprint function
client_datadata to be passed to pr function
int solr_to_xml_buf ( struct solr_node cn,
char *  out,
int  max 
)

converts SOLR tree to XSOLR and writes result to buffer

Parameters
cnSOLR node (tree)
outbuffer
maxsize of buffer (max chars to write)
Returns
length of resulting buffer
void solr_to_xml_stdio ( struct solr_node cn,
FILE *  f 
)

converts SOLR tree to XSOLR and writes to file

Parameters
cnSOLR node (tree)
ffile handle
int solr_transform ( solr_transform_t  ct,
struct solr_node cn,
void(*)(const char *buf, void *client_data)  pr,
void *  client_data 
)

tranforms PQF given a SOLR tree

Parameters
ctSOLR transform handle
cnSOLR node tree
prprint function
client_datadata to be passed to pr
Return values
0success
!=0 error

The result is written to a user-defined stream.

Definition at line 907 of file solrtransform.c.

References solr_transform_t_::addinfo, solr_transform_t_::entry, solr_transform_t_::error, solr_prop_entry::next, nmem_create(), nmem_destroy(), solr_transform_r(), and xfree.

Referenced by solr_transform_buf(), and solr_transform_FILE().

int solr_transform_buf ( solr_transform_t  ct,
struct solr_node cn,
char *  out,
int  max 
)

transforms PQF given a SOLR tree (from FILE)

Parameters
ctSOLR transform handle
cnSOLR tree
outbuffer for output
maxmaximum bytes for output (size of buffer)
Return values
0success
!=0failure (error code)

Definition at line 939 of file solrtransform.c.

References solr_transform_t_::addinfo, solr_buf_write_info::buf, cql_buf_write_handler(), solr_transform_t_::error, solr_buf_write_info::max, solr_buf_write_info::off, solr_transform(), xstrdup, and YAZ_SRW_TOO_MANY_CHARS_IN_QUERY.

void solr_transform_close ( solr_transform_t  ct)
solr_transform_t solr_transform_create ( void  )
int solr_transform_define_pattern ( solr_transform_t  ct,
const char *  pattern,
const char *  value 
)

defines SOLR transform pattern

Parameters
ctSOLR transform handle
patternpattern string
valuepattern value
Returns
0 for succes; -1 for failure

Definition at line 225 of file solrtransform.c.

References solr_transform_parse_tok_line(), solr_transform_t_::tok_cfg, yaz_tok_cfg_single_tokens(), yaz_tok_parse_buf(), and yaz_tok_parse_destroy().

int solr_transform_error ( solr_transform_t  ct,
const char **  addinfo 
)

returns additional information for last transform

Parameters
ctSOLR transform handle
addinfoadditional info (result)
Returns
error code

Definition at line 963 of file solrtransform.c.

References solr_transform_t_::addinfo, and solr_transform_t_::error.

int solr_transform_FILE ( solr_transform_t  ct,
struct solr_node cn,
FILE *  f 
)

transforms PQF given a SOLR tree (from FILE)

Parameters
ctSOLR transform handle
cnSOLR tree
fFILE where output is written
Return values
0success
!=0failure (error code)

The result is written to a file specified by FILE handle (which must be opened for writing.

Definition at line 933 of file solrtransform.c.

References cql_fputs(), and solr_transform().

solr_transform_t solr_transform_open_FILE ( FILE *  f)

creates a SOLR transform handle from am opened file handle

Parameters
ffile where transformation spec is read
Returns
transform handle or NULL for failure

The transformation spec is read from a FILE handle which is assumed opened for reading.

Definition at line 236 of file solrtransform.c.

References solr_prop_entry::pattern, solr_transform_close(), solr_transform_create(), solr_transform_parse_tok_line(), solr_transform_t_::tok_cfg, solr_transform_t_::w, wrbuf_rewind(), xfree, xstrdup, yaz_tok_cfg_single_tokens(), YAZ_TOK_EOF, yaz_tok_move(), yaz_tok_parse_buf(), yaz_tok_parse_destroy(), yaz_tok_parse_string(), and YAZ_TOK_STRING.

Referenced by solr_transform_open_fname().

solr_transform_t solr_transform_open_fname ( const char *  fname)

creates a SOLR transform handle from a file

Parameters
fnamename of where transformation spec is read
Returns
transform handle or NULL for failure

Definition at line 299 of file solrtransform.c.

References solr_transform_open_FILE().

void solr_transform_set_error ( solr_transform_t  ct,
int  error,
const char *  addinfo 
)

sets error and addinfo for transform

Parameters
ctSOLR transform handle
errorerror code
addinfoadditional info

Definition at line 969 of file solrtransform.c.

References solr_transform_t_::addinfo, solr_transform_t_::error, xfree, and xstrdup.

Referenced by rpn2solr_attr(), rpn2solr_simple(), rpn2solr_structure(), and solr_transform_rpn2solr_stream().

const char* solr_uri ( void  )

returns the standard SOLR context set URI.

Returns
SOLR URI string

Definition at line 54 of file solrtransform.c.

Referenced by solr_transform_r().