JASSv2
Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | List of all members
JASS::query_block_max Class Reference

Everything necessary to process a query is encapsulated in an object of this type. More...

#include <query_block_max.h>

Inheritance diagram for JASS::query_block_max:
Inheritance graph
[legend]
Collaboration diagram for JASS::query_block_max:
Collaboration graph
[legend]

Public Member Functions

 query_block_max (compress_integer &codex)
 Constructor.
 
virtual ~query_block_max ()
 Destructor.
 
virtual void init (const std::vector< std::string > &primary_keys, DOCID_TYPE documents=1024, DOCID_TYPE top_k=10, size_t width=7)
 Initialise the object. MUST be called before first use. More...
 
virtual docid_rsv_pairget_first (void)
 Retrun the top result. More...
 
virtual docid_rsv_pairget_next (void)
 After calling get_first(), return the next result. More...
 
virtual void rewind (ACCUMULATOR_TYPE smallest_possible_rsv=0, ACCUMULATOR_TYPE top_k_lower_bound=1, ACCUMULATOR_TYPE largest_possible_rsv=0)
 Clear this object after use and ready for re-use.
 
virtual void sort (void)
 sort this resuls list before iteration over it. More...
 
forceinline void add_rsv (DOCID_TYPE document_id, ACCUMULATOR_TYPE score)
 Add weight to the rsv for document document_id. More...
 
virtual void decode_with_writer (size_t integers, const void *compressed, size_t compressed_size)
 Given the integer decoder, the number of integes to decode, and the compressed sequence, decompress (but do not process). More...
 
- Public Member Functions inherited from JASS::query
 query (compress_integer &codex)
 Constructor.
 
virtual ~query ()
 Destructor.
 
template<typename STRING_TYPE >
void parse (const STRING_TYPE &query, parser_query::parser_type which_parser=parser_query::parser_type::query)
 Take the given query and parse it. More...
 
query_term_listterms (void)
 Return a reference to the parsed query. More...
 
forceinline void set_impact (ACCUMULATOR_TYPE score)
 Set the impact score to use in a push_back(). More...
 
forceinline void decode_and_process (ACCUMULATOR_TYPE impact, size_t integers, const void *compressed, size_t compressed_size)
 Given the integer decoder, the number of integes to decode, and the compressed sequence, decompress (but do not process). More...
 
virtual void decode_with_writer (query::printer &writer, size_t integers, const void *compressed, size_t compressed_size)
 Given the integer decoder, the number of integes to decode, and the compressed sequence, decompress (but do not process). More...
 

Static Public Member Functions

static void unittest (void)
 Unit test this class.
 

Private Types

typedef pointer_box< ACCUMULATOR_TYPEaccumulator_pointer
 

Private Attributes

accumulator_block_max< ACCUMULATOR_TYPE, MAX_DOCUMENTSaccumulators
 The accumulators, one per document in the collection.
 
bool sorted
 Has the top-k been generates (false after rewind() true after sort())
 
docid_rsv_pair next_result
 A single result, used but get_first() and get_next()
 
DOCID_TYPE next_result_location
 Used by get_first() and get_next() to determine which result is next.
 
accumulator_pointer accumulator_pointers [MAX_TOP_K]
 Array of pointers to the top k accumulators.
 
heap< accumulator_pointertop_results
 Heap containing the top-k results.
 
DOCID_TYPE needed_for_top_k
 The number of results we still need in order to fill the top-k.
 

Additional Inherited Members

- Public Types inherited from JASS::query
typedef uint8_t ACCUMULATOR_TYPE
 the type of an accumulator (probably a uint16_t)
 
typedef uint32_t DOCID_TYPE
 the type of a document id (from a compressor)
 
- Public Attributes inherited from JASS::query
DOCID_TYPE top_k
 The number of results to track.
 
- Static Public Attributes inherited from JASS::query
static constexpr size_t MAX_DOCUMENTS = 200'000'000
 the maximum number of documents an index can hold
 
static constexpr size_t MAX_TOP_K = 1'000
 the maximum top-k value
 
static constexpr size_t MAX_RSV = (std::numeric_limits<ACCUMULATOR_TYPE>::max)()
 
- Protected Attributes inherited from JASS::query
ACCUMULATOR_TYPE impact
 The impact score to be added on a call to add_rsv()
 
allocator_pool memory
 All memory allocation happens in this "arena".
 
std::vector< DOCID_TYPEdecompress_buffer
 The delta-encoded decopressed integer sequence.
 
DOCID_TYPE documents
 The numnber of documents this index contains.
 
parser_query parser
 Parser responsible for converting text into a parsed query.
 
query_term_listparsed_query
 The parsed query.
 
const std::vector< std::string > * primary_keys
 A vector of strings, each the primary key for the document with an id equal to the vector index.
 
compress_integercodex
 The decompressor to use.
 

Detailed Description

Everything necessary to process a query is encapsulated in an object of this type.

Member Function Documentation

◆ add_rsv()

forceinline void JASS::query_block_max::add_rsv ( DOCID_TYPE  document_id,
ACCUMULATOR_TYPE  score 
)
inline

Add weight to the rsv for document document_id.

Parameters
document_id[in] which document to increment
score[in] the amount of weight to add

◆ decode_with_writer()

virtual void JASS::query_block_max::decode_with_writer ( size_t  integers,
const void *  compressed,
size_t  compressed_size 
)
inlinevirtual

Given the integer decoder, the number of integes to decode, and the compressed sequence, decompress (but do not process).

Parameters
integers[in] The number of integers that are compressed.
compressed[in] The compressed sequence.
compressed_size[in] The length of the compressed sequence.

Implements JASS::query.

◆ get_first()

virtual docid_rsv_pair* JASS::query_block_max::get_first ( void  )
inlinevirtual

Retrun the top result.

Returns
The first (i.e. top) result in the results list.

Implements JASS::query.

◆ get_next()

virtual docid_rsv_pair* JASS::query_block_max::get_next ( void  )
inlinevirtual

After calling get_first(), return the next result.

Returns
The next result in the results list, or NULL if at end of list

Implements JASS::query.

◆ init()

virtual void JASS::query_block_max::init ( const std::vector< std::string > &  primary_keys,
DOCID_TYPE  documents = 1024,
DOCID_TYPE  top_k = 10,
size_t  width = 7 
)
inlinevirtual

Initialise the object. MUST be called before first use.

Parameters
primary_keys[in] Vector of the document primary keys used to convert from internal document ids to external primary keys.
documents[in] The number of documents in the collection.
top_k[in] The top-k documents to return from the query once executed.
width[in] The width of the 2-d accumulators (if they are being used).

Reimplemented from JASS::query.

◆ sort()

virtual void JASS::query_block_max::sort ( void  )
inlinevirtual

sort this resuls list before iteration over it.

In block_max processing, we scan the block_max scores looking for instances where the score is greater than the bottom of the heap. If we find one then its necessary to scan that block looking for instances where an accumulator is greater than the bottom of the heap. The heap is then built from those accumulators bu pushing pointers to the accumulators onto the heap. Then we sort the heap.

Implements JASS::query.


The documentation for this class was generated from the following file: