ept::textsearch::TextSearch Class Reference

Maintains and accesses a Xapian index of package descriptions. More...

#include <textsearch.h>

List of all members.

Classes

struct  ExtraIndexer

Public Member Functions

 TextSearch ()
Xapian::Database & db ()
 Access the Xapian database.
const Xapian::Database & db () const
 Access the Xapian database.
time_t timestamp () const
 Timestamp of when the Xapian database was last updated.
bool hasData () const
 Returns true if the index has data.
bool needsRebuild (apt::Apt &apt)
 Returns true if the index is older than the Apt database information.
bool rebuildIfNeeded (apt::Apt &apt, const std::vector< const ExtraIndexer * > &extraIndexers=std::vector< const ExtraIndexer * >())
 Rebuild the index if needed.
Xapian::docid docidByName (const std::string &pkgname) const
 Retrieve a Xapian docid by package name.
Xapian::Query makeORQuery (const std::string &keywords) const
 Tokenize the string and build an OR query with the resulting keywords.
Xapian::Query makePartialORQuery (const std::string &keywords) const
 Tokenize the string and build an OR query with the resulting keywords.
template<typename ITER >
Xapian::Query makeORQuery (const ITER &begin, const ITER &end) const
 Build a query with the given keywords, specified as iterators of strings.
std::vector< std::string > expand (Xapian::Enquire &enq) const
 Return a list of tag-based terms that can be used to expand an OR query.
Xapian::Query makeRelatedQuery (const std::string &pkgname) const
 Create a query to look for packages similar to the given one.
double getDoubleValue (const std::string &pkgname, Xapian::valueno val_id) const
 Get the integer value for.
int getIntValue (const std::string &pkgname, Xapian::valueno val_id) const
 Get the integer value for.

Protected Member Functions

void normalize_and_add (Xapian::Document &doc, const std::string &term, int &pos) const
 Add normalised tokens computed from the string to the document doc.

Static Protected Member Functions

static std::string toLower (const std::string &str)
 Return a lowercased copy of the string.

Protected Attributes

time_t m_timestamp
Xapian::Database m_db
Xapian::Stem m_stem

Detailed Description

Maintains and accesses a Xapian index of package descriptions.

Contrarily to Debtags and Popcon, TextSearch does not attempt to create the index in the home directory if no system index is found and it is not running as root: this is to avoid secretly building large indexes (>50Mb) in the home directory of users.

The idea then is to have root keep the index up to date, possibly running a reindexing tool once a day, or after an apt-get update.

This works because the full text search index is useful even if it is slightly out of date.


Constructor & Destructor Documentation

ept::textsearch::TextSearch::TextSearch (  ) 

Member Function Documentation

const Xapian::Database& ept::textsearch::TextSearch::db (  )  const [inline]

Access the Xapian database.

References m_db.

Xapian::Database& ept::textsearch::TextSearch::db (  )  [inline]
Xapian::docid ept::textsearch::TextSearch::docidByName ( const std::string &  pkgname  )  const

Retrieve a Xapian docid by package name.

References m_db.

Referenced by TestTextsearch::docidByName(), getDoubleValue(), and getIntValue().

vector< string > ept::textsearch::TextSearch::expand ( Xapian::Enquire &  enq  )  const

Return a list of tag-based terms that can be used to expand an OR query.

double ept::textsearch::TextSearch::getDoubleValue ( const std::string &  pkgname,
Xapian::valueno  val_id 
) const

Get the integer value for.

References db(), and docidByName().

Referenced by TestTextsearch::values().

int ept::textsearch::TextSearch::getIntValue ( const std::string &  pkgname,
Xapian::valueno  val_id 
) const

Get the integer value for.

References db(), and docidByName().

Referenced by TestTextsearch::values().

bool ept::textsearch::TextSearch::hasData (  )  const [inline]

Returns true if the index has data.

References m_timestamp.

Referenced by TestTextsearch::basicAccess(), TestTextsearch::empty(), and TestTextsearch::values().

template<typename ITER >
Xapian::Query ept::textsearch::TextSearch::makeORQuery ( const ITER &  begin,
const ITER &  end 
) const [inline]

Build a query with the given keywords, specified as iterators of strings.

References m_stem, and toLower().

Xapian::Query ept::textsearch::TextSearch::makeORQuery ( const std::string &  keywords  )  const

Tokenize the string and build an OR query with the resulting keywords.

Referenced by TestTextsearch::basicAccess(), makePartialORQuery(), and TestTextsearch::queryAccess().

Xapian::Query ept::textsearch::TextSearch::makePartialORQuery ( const std::string &  keywords  )  const

Tokenize the string and build an OR query with the resulting keywords.

The last token in keywords is considered to be typed only partially, to implement proper search-as-you-type.

References m_db, and makeORQuery().

Referenced by TestTextsearch::partialOrQuery().

Xapian::Query ept::textsearch::TextSearch::makeRelatedQuery ( const std::string &  pkgname  )  const

Create a query to look for packages similar to the given one.

References db().

bool ept::textsearch::TextSearch::needsRebuild ( apt::Apt apt  ) 

Returns true if the index is older than the Apt database information.

References m_timestamp, and ept::apt::Apt::timestamp().

Referenced by TestTextsearch::basicAccess(), TestTextsearch::empty(), and TestTextsearch::values().

void ept::textsearch::TextSearch::normalize_and_add ( Xapian::Document &  doc,
const std::string &  term,
int &  pos 
) const [protected]

Add normalised tokens computed from the string to the document doc.

pos is used as a sequence generator for entering the token position in the document.

References m_stem, and toLower().

bool ept::textsearch::TextSearch::rebuildIfNeeded ( apt::Apt apt,
const std::vector< const ExtraIndexer * > &  extraIndexers = std::vector< const ExtraIndexer * >() 
)

Rebuild the index if needed.

Allow to specify functors that contribute to the indexing.

Note:
This requires write access to the index directory.
This is not the main way to update the index: it is provided here only as a way to build a draft index for the library tests

Referenced by TestTextsearch::TestTextsearch(), and XapianTestEnvironment::XapianTestEnvironment().

time_t ept::textsearch::TextSearch::timestamp (  )  const [inline]

Timestamp of when the Xapian database was last updated.

References m_timestamp.

Referenced by TestTextsearch::basicAccess(), TestTextsearch::empty(), and TestTextsearch::values().

std::string ept::textsearch::TextSearch::toLower ( const std::string &  str  )  [static, protected]

Return a lowercased copy of the string.

Referenced by makeORQuery(), and normalize_and_add().


Member Data Documentation

Xapian::Database ept::textsearch::TextSearch::m_db [protected]
Xapian::Stem ept::textsearch::TextSearch::m_stem [protected]

Referenced by makeORQuery(), and normalize_and_add().


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

Generated on Thu Oct 22 21:28:06 2009 for libept by  doxygen 1.6.1