implement dynamic field name to prefix translation, query side
This commit is contained in:
+45
-2
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.113 2007-06-14 08:20:13 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: rcldb.cpp,v 1.114 2007-06-18 13:04:15 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -740,6 +740,43 @@ bool Db::isopen()
|
||||
return m_ndb->m_isopen;
|
||||
}
|
||||
|
||||
// Try to translate field specification into field prefix. We have a
|
||||
// default table used if translations are not in the config for some
|
||||
// reason (old config not updated ?). We use it only if the config
|
||||
// translation fails
|
||||
string Db::fieldToPrefix(const string& fldname)
|
||||
{
|
||||
// This is the default table
|
||||
static map<string, string> fldToPrefs;
|
||||
if (fldToPrefs.empty()) {
|
||||
fldToPrefs["title"] = "S";
|
||||
fldToPrefs["caption"] = "S";
|
||||
fldToPrefs["subject"] = "S";
|
||||
|
||||
fldToPrefs["author"] = "A";
|
||||
fldToPrefs["creator"] = "A";
|
||||
fldToPrefs["from"] = "A";
|
||||
|
||||
fldToPrefs["keyword"] = "K";
|
||||
fldToPrefs["tag"] = "K";
|
||||
fldToPrefs["keywords"] = "K";
|
||||
fldToPrefs["tags"] = "K";
|
||||
}
|
||||
|
||||
string fld(fldname), pfx;
|
||||
stringtolower(fld);
|
||||
RclConfig *config = RclConfig::getMainConfig();
|
||||
if (config)
|
||||
pfx = config->getFieldPrefix(fld);
|
||||
if (pfx.empty()) {
|
||||
map<string, string>::const_iterator it = fldToPrefs.find(fld);
|
||||
if (it != fldToPrefs.end())
|
||||
fld = it->second;
|
||||
}
|
||||
return pfx;
|
||||
}
|
||||
|
||||
|
||||
// The text splitter callback class which receives words from the
|
||||
// splitter and adds postings to the Xapian document.
|
||||
class mySplitterCB : public TextSplitCB {
|
||||
@@ -882,7 +919,13 @@ bool Db::add(const string &fn, const Doc &idoc, const struct stat *stp)
|
||||
|
||||
TextSplit splitter(&splitData);
|
||||
|
||||
// /////// Split and index terms in document body and auxiliary fields
|
||||
// Index the title, document text, keywords and other textual
|
||||
// metadata. These are all indexed as text with positions, as we
|
||||
// may want to do phrase searches with them (this makes no sense
|
||||
// for keywords by the way, but wtf).
|
||||
/
|
||||
// The order has no importance, and we set a position gap of 100
|
||||
// between fields to avoid false proximity matches.
|
||||
string noacc;
|
||||
|
||||
// Split and index file name as document term(s)
|
||||
|
||||
+3
-1
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
#ifndef _DB_H_INCLUDED_
|
||||
#define _DB_H_INCLUDED_
|
||||
/* @(#$Id: rcldb.h,v 1.50 2007-06-08 16:47:19 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: rcldb.h,v 1.51 2007-06-18 13:04:15 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
@@ -94,6 +94,8 @@ class Db {
|
||||
/** Return list of configured stop words */
|
||||
const StopList& getStopList() const {return m_stops;}
|
||||
|
||||
/** Field name to prefix translation (ie: author -> 'A') */
|
||||
string fieldToPrefix(const string& fldname);
|
||||
|
||||
/* Update-related methods ******************************************/
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: searchdata.cpp,v 1.14 2007-06-02 08:30:42 dockes Exp $ (C) 2006 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: searchdata.cpp,v 1.15 2007-06-18 13:04:15 dockes Exp $ (C) 2006 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -33,6 +33,7 @@ static char rcsid[] = "@(#$Id: searchdata.cpp,v 1.14 2007-06-02 08:30:42 dockes
|
||||
#include "unacpp.h"
|
||||
#include "utf8iter.h"
|
||||
#include "stoplist.h"
|
||||
#include "rclconfig.h"
|
||||
|
||||
#ifndef NO_NAMESPACES
|
||||
using namespace std;
|
||||
@@ -460,34 +461,6 @@ bool StringToXapianQ::processUserString(const string &iq,
|
||||
return true;
|
||||
}
|
||||
|
||||
// Try to translate field specification into field prefix. This should
|
||||
// probably be an Rcl::Db method and much more configurable (store
|
||||
// prefix translation list in config ?)
|
||||
static string fieldToPrefix(const string& i_field)
|
||||
{
|
||||
static map<string, string> fldToPrefs;
|
||||
if (fldToPrefs.empty()) {
|
||||
fldToPrefs["title"] = "S";
|
||||
fldToPrefs["caption"] = "S";
|
||||
fldToPrefs["subject"] = "S";
|
||||
|
||||
fldToPrefs["author"] = "A";
|
||||
fldToPrefs["creator"] = "A";
|
||||
fldToPrefs["from"] = "A";
|
||||
|
||||
fldToPrefs["keyword"] = "K";
|
||||
fldToPrefs["tag"] = "K";
|
||||
fldToPrefs["keywords"] = "K";
|
||||
fldToPrefs["tags"] = "K";
|
||||
}
|
||||
string fld(i_field);
|
||||
stringtolower(fld);
|
||||
map<string, string>::const_iterator it = fldToPrefs.find(fld);
|
||||
if (it != fldToPrefs.end())
|
||||
return it->second;
|
||||
return "";
|
||||
}
|
||||
|
||||
static const string nullstemlang;
|
||||
|
||||
// Translate a simple OR, AND, or EXCL search clause.
|
||||
@@ -514,7 +487,7 @@ bool SearchDataClauseSimple::toNativeQuery(Rcl::Db &db, void *p,
|
||||
}
|
||||
string prefix;
|
||||
if (!m_field.empty())
|
||||
prefix = fieldToPrefix(m_field);
|
||||
prefix = db.fieldToPrefix(m_field);
|
||||
list<Xapian::Query> pqueries;
|
||||
|
||||
// We normally boost the original term in the stem expansion list. Don't
|
||||
@@ -568,7 +541,7 @@ bool SearchDataClauseDist::toNativeQuery(Rcl::Db &db, void *p,
|
||||
|
||||
string prefix;
|
||||
if (!m_field.empty())
|
||||
prefix = fieldToPrefix(m_field);
|
||||
prefix = db.fieldToPrefix(m_field);
|
||||
|
||||
// We normally boost the original term in the stem expansion list. Don't
|
||||
// do it if there are wildcards anywhere, this would skew the results.
|
||||
|
||||
Reference in New Issue
Block a user