Switch to unified view

a/src/common/rclconfig.cpp b/src/common/rclconfig.cpp
1
#ifndef lint
1
#ifndef lint
2
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.57 2008-09-08 16:49:10 dockes Exp $ (C) 2004 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: rclconfig.cpp,v 1.58 2008-09-16 08:18:30 dockes Exp $ (C) 2004 J.F.Dockes";
3
#endif
3
#endif
4
/*
4
/*
5
 *   This program is free software; you can redistribute it and/or modify
5
 *   This program is free software; you can redistribute it and/or modify
6
 *   it under the terms of the GNU General Public License as published by
6
 *   it under the terms of the GNU General Public License as published by
7
 *   the Free Software Foundation; either version 2 of the License, or
7
 *   the Free Software Foundation; either version 2 of the License, or
...
...
465
    return false;
465
    return false;
466
    }
466
    }
467
467
468
    // Build a direct map avoiding all indirections for field to
468
    // Build a direct map avoiding all indirections for field to
469
    // prefix translation
469
    // prefix translation
470
    // Add direct prefixes
470
    // Add direct prefixes from the [prefixes] section
471
    list<string>tps = m_fields->getNames("prefixes");
471
    list<string>tps = m_fields->getNames("prefixes");
472
    for (list<string>::const_iterator it = tps.begin(); it != tps.end();it++) {
472
    for (list<string>::const_iterator it = tps.begin(); it != tps.end();it++) {
473
    string val;
473
    string val;
474
    m_fields->get(*it, val, "prefixes");
474
    m_fields->get(*it, val, "prefixes");
475
  m_fldtopref[*it] = val;
475
  m_fldtopfx[stringtolower(*it)] = val;
476
    }
476
    }
477
    // Add prefixes for aliases:
477
    // Add prefixes for aliases (build alias-to-canonic map while we're at it)
478
    tps = m_fields->getNames("aliases");
478
    tps = m_fields->getNames("aliases");
479
    for (list<string>::const_iterator it = tps.begin(); it != tps.end();it++) {
479
    for (list<string>::const_iterator it = tps.begin(); it != tps.end();it++) {
480
    string canonic = *it; // canonic name
480
    string canonic = stringtolower(*it); // canonic name
481
    string pfx;
481
    string pfx;
482
    map<string,string>::const_iterator pit = m_fldtopref.find(canonic);
482
    map<string,string>::const_iterator pit = m_fldtopfx.find(canonic);
483
    if (pit != m_fldtopref.end()) {
483
    if (pit != m_fldtopfx.end()) {
484
        pfx = pit->second;
484
        pfx = pit->second;
485
  } else {
486
      // Note: it's perfectly normal to have no prefix for the canonic
487
      // name, this could be a stored, not indexed field
488
      LOGDEB2(("RclConfig::readFieldsConfig: no pfx for canonic [%s]\n",
489
          canonic.c_str()));
490
      continue;
491
    }
485
    }
492
    string aliases;
486
    string aliases;
493
    m_fields->get(canonic, aliases, "aliases");
487
    m_fields->get(canonic, aliases, "aliases");
494
    list<string> l;
488
    list<string> l;
495
    stringToStrings(aliases, l);
489
    stringToStrings(aliases, l);
496
    for (list<string>::const_iterator ait = l.begin();
490
    for (list<string>::const_iterator ait = l.begin();
497
         ait != l.end(); ait++) {
491
         ait != l.end(); ait++) {
498
      m_fldtopref[*ait] = pfx;
492
      if (!pfx.empty())
493
      m_fldtopfx[stringtolower(*ait)] = pfx;
494
      m_aliastocanon[stringtolower(*ait)] = canonic;
499
    }
495
    }
500
    }
496
    }
501
#if 0
497
#if 0
502
    for (map<string,string>::const_iterator it = m_fldtopref.begin();
498
    for (map<string,string>::const_iterator it = m_fldtopfx.begin();
503
     it != m_fldtopref.end(); it++) {
499
     it != m_fldtopfx.end(); it++) {
504
    LOGDEB(("RclConfig::readFieldsConfig: [%s] => [%s]\n",
500
    LOGDEB(("RclConfig::readFieldsConfig: [%s] => [%s]\n",
505
        it->first.c_str(), it->second.c_str()));
501
        it->first.c_str(), it->second.c_str()));
506
    }
502
    }
507
#endif
503
#endif
508
504
...
...
510
    if (m_fields->get("stored", ss, "stored")) {
506
    if (m_fields->get("stored", ss, "stored")) {
511
    list<string> sl;
507
    list<string> sl;
512
    stringToStrings(ss, sl);
508
    stringToStrings(ss, sl);
513
    for (list<string>::const_iterator it = sl.begin(); 
509
    for (list<string>::const_iterator it = sl.begin(); 
514
         it != sl.end(); it++) {
510
         it != sl.end(); it++) {
511
      string fld = fieldCanon(stringtolower(*it));
515
        LOGDEB(("Inserting [%s] in stored list\n", (*it).c_str()));
512
        LOGDEB(("Inserting [%s] in stored list\n", fld.c_str()));
516
        m_storedFields.insert(*it);
513
        m_storedFields.insert(fld);
517
    }
514
    }
518
    }
515
    }
519
516
520
    return true;
517
    return true;
521
}
518
}
522
519
523
// Return term indexing prefix for field name (ie: "filename" -> "XSFN")
520
// Return term indexing prefix for field name (ie: "filename" -> "XSFN")
521
// The input must be a canonical field name (alias translation done already)
524
bool RclConfig::getFieldPrefix(const string& fld, string &pfx)
522
bool RclConfig::getFieldPrefix(const string& fld, string &pfx)
525
{
523
{
526
    map<string,string>::const_iterator pit = m_fldtopref.find(fld);
524
    map<string,string>::const_iterator pit = m_fldtopfx.find(fld);
527
    if (pit != m_fldtopref.end()) {
525
    if (pit != m_fldtopfx.end()) {
528
    pfx = pit->second;
526
    pfx = pit->second;
529
    return true;
527
    return true;
530
    } else {
528
    } else {
531
    LOGDEB1(("RclConfig::readFieldsConfig: no prefix for field [%s]\n",
529
    LOGDEB1(("RclConfig::readFieldsConfig: no prefix for field [%s]\n",
532
         fld.c_str()));
530
         fld.c_str()));
...
...
570
    }
568
    }
571
    pfxes.sort();
569
    pfxes.sort();
572
    pfxes.unique();
570
    pfxes.unique();
573
    return true;
571
    return true;
574
}
572
}
573
575
bool RclConfig::fieldIsStored(const string& fld)
574
string RclConfig::fieldCanon(const string& fld)
576
{
575
{
577
    set<string>::const_iterator it = m_storedFields.find(fld);
576
    map<string, string>::const_iterator it = m_aliastocanon.find(fld);
578
    return it != m_storedFields.end();
577
    if (it != m_aliastocanon.end())
578
  return it->second;
579
    return fld;
579
}
580
}
580
581
581
string RclConfig::getMimeViewerDef(const string &mtype)
582
string RclConfig::getMimeViewerDef(const string &mtype)
582
{
583
{
583
    string hs;
584
    string hs;