Changeset 293

Show
Ignore:
Timestamp:
02/22/08 04:06:12 (9 months ago)
Author:
jake
Message:

Ignore on disk docs that have been updated

Location:
trunk/thrudex/src
Files:
2 added
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/thrudex/src/CLuceneIndex.cpp

    r292 r293  
    1111 
    1212#include "bloom_filter.hpp" 
     13#include "UpdateFilter.h" 
    1314 
    1415using namespace thrudex; 
     
    7374 
    7475        //build up bloom filter 
    75  
    7676        disk_bloom    = shared_ptr<bloom_filter>(new bloom_filter(filter_space,1.0/(1.0 * filter_space), random_seed)); 
     77        disk_reader   = shared_ptr<IndexReader>(IndexReader::open(idx_path.c_str())); 
     78        disk_filter   = shared_ptr<UpdateFilter>(new UpdateFilter(disk_reader)); 
    7779 
    7880        if(!new_index){ 
    7981 
    80             boost::shared_ptr<IndexReader>  reader(IndexReader::open(idx_path.c_str())); 
    81  
    82             int max = reader->maxDoc(); 
     82            int max = disk_reader->maxDoc(); 
    8383            char buf[1024]; 
    8484 
    8585            for(int i=0; i<max; i++){ 
    86                 const wchar_t *id   = reader->document(i)->get( DOC_KEY ); 
     86                const wchar_t *id   = disk_reader->document(i)->get( DOC_KEY ); 
    8787 
    8888                STRCPY_TtoA(buf,id,1024); 
     
    9393            } 
    9494 
    95             reader->close(); 
     95 
    9696        } 
    9797 
     
    105105        ram_searcher  = shared_ptr<IndexSearcher>(new IndexSearcher(ram_directory.get())); 
    106106 
    107         disk_searcher = shared_ptr<IndexSearcher>(new IndexSearcher(idx_path.c_str())); 
     107        disk_searcher = shared_ptr<IndexSearcher>(new IndexSearcher(disk_reader.get())); 
    108108        last_refresh  = -1; 
    109109 
     
    144144CLuceneIndex::~CLuceneIndex() 
    145145{ 
    146     //monitor_thread->stop(); 
    147146    sync(); 
    148147} 
     
    187186{ 
    188187 
    189     assert(!key.empty()); 
    190  
     188    if(key.empty()){ 
     189        ThrudexException ex; 
     190        ex.what = "Empty key"; 
     191        throw ex; 
     192    } 
    191193 
    192194    Guard g( mutex ); 
    193  
    194195 
    195196    //always put into memory (we will merge to disk later) 
     
    198199    shared_ptr<IndexModifier> l_modifier     = modifier; 
    199200    shared_ptr<set<string> >  l_disk_deletes = disk_deletes; 
     201    shared_ptr<UpdateFilter>  l_disk_filter  = disk_filter; 
     202 
     203    wstring wkey = build_wstring(key); 
    200204 
    201205    //if update to a doc in memory old copy first 
    202206    if( ram_bloom->contains( key ) ){ 
    203207 
    204         wstring wkey = build_wstring(key); 
    205208        Term *t = new Term(DOC_KEY, wkey.c_str() ); 
    206209 
     
    212215 
    213216 
    214     //If this exists already on disk 
    215     //remove it 
     217    //If this exists already on disk remove it 
    216218    if( l_disk_bloom->contains( key ) ){ 
    217219        l_disk_deletes->insert( key ); 
     220 
     221        if(!syncing) 
     222            l_disk_filter->skip(wkey); 
    218223    } 
    219224 
    220225    l_modifier->addDocument(doc); 
    221  
    222226    l_ram_bloom->insert( key ); 
    223227 
     
    233237    shared_ptr<IndexModifier> l_modifier     = modifier; 
    234238    shared_ptr<set<string> >  l_disk_deletes = disk_deletes; 
    235  
     239    shared_ptr<UpdateFilter>  l_disk_filter  = disk_filter; 
     240 
     241    wstring wkey = build_wstring(key); 
    236242 
    237243    //Since we don't want to write to disk 
     
    240246        LOG4CXX_DEBUG(logger, "Removed "+key); 
    241247        l_disk_deletes->insert( key ); 
     248 
     249        if(!syncing) 
     250            l_disk_filter->skip(wkey); 
     251 
    242252        last_modified = Util::currentTime(); 
    243253    } 
     
    246256    if(l_ram_bloom->contains( key )){ 
    247257 
    248         wstring wkey = build_wstring(key); 
    249258        Term      *t = new Term(DOC_KEY, wkey.c_str() ); 
    250259 
     
    266275    shared_ptr<CLuceneRAMDirectory> l_ram_prev_directory = ram_prev_directory; 
    267276 
    268     shared_ptr<MultiSearcher> l_searcher = this->getSearcher(); 
     277    shared_ptr<MultiSearcher> l_searcher    = this->getSearcher(); 
     278    shared_ptr<UpdateFilter>  l_disk_filter = disk_filter; 
    269279 
    270280    Query *query; 
     
    301311 
    302312    if( q.sortby.empty() ){ 
    303         h = l_searcher->search(query); 
     313        h = l_searcher->search(query, l_disk_filter.get()); 
    304314    } else { 
    305315 
     
    313323 
    314324        try { 
    315             h = l_searcher->search(query,lsort); 
     325            h = l_searcher->search(query,l_disk_filter.get(),lsort); 
    316326        } catch(CLuceneError &e) { 
    317327 
    318328            LOG4CXX_WARN(logger, "Sort failed, falling back on regular search"); 
    319             h = l_searcher->search(query); 
     329            h = l_searcher->search(query,l_disk_filter.get()); 
    320330        } 
    321331    } 
     
    419429 
    420430    LOG4CXX_DEBUG(logger,"Syncing Started"); 
    421  
     431    string idx_path = index_root + "/" + index_name; 
    422432 
    423433    shared_ptr<IndexModifier>       l_ram_modifier; 
     
    426436    shared_ptr<set<string> >        l_disk_deletes; 
    427437    shared_ptr<bloom_filter>        l_disk_bloom; 
     438    shared_ptr<UpdateFilter>        l_update_filter; 
    428439 
    429440 
     
    459470 
    460471    //Now we start by deleting any updated docs from disk 
    461     string idx_path = index_root + "/" + index_name; 
    462472 
    463473    shared_ptr<IndexReader> disk_reader(IndexReader::open(idx_path.c_str())); 
     
    498508        LOG4CXX_DEBUG(logger,"Merged"); 
    499509    } 
     510 
    500511    //Search new index (big perf hit so get it over now) 
    501  
    502     shared_ptr<IndexSearcher> l_disk_searcher(new IndexSearcher(idx_path.c_str())); 
     512    shared_ptr<IndexReader>   l_disk_reader(IndexReader::open(idx_path.c_str())); 
     513    shared_ptr<IndexSearcher> l_disk_searcher(new IndexSearcher(l_disk_reader.get())); 
     514    shared_ptr<UpdateFilter>  l_disk_filter(new UpdateFilter(l_disk_reader)); 
     515 
     516 
    503517    wstring q = wstring(DOC_KEY)+wstring(L":1234"); 
    504518 
     
    514528        Guard g(mutex); 
    515529 
     530        //Add any new deletes to the filter 
     531        set<string>::iterator it; 
     532        for( it=disk_deletes->begin(); it!=disk_deletes->end(); ++it){ 
     533            wstring wkey = build_wstring(*it); 
     534            l_disk_filter->skip(wkey); 
     535        } 
     536 
     537        disk_reader   = l_disk_reader; 
     538        disk_filter   = l_disk_filter; 
     539        disk_searcher = l_disk_searcher; 
     540 
     541 
     542        last_synched = Util::currentTime(); 
     543 
    516544        syncing = false; //this flag alters the search code to include prev searcher 
    517  
    518         disk_searcher = l_disk_searcher; 
    519  
    520         last_synched = Util::currentTime(); 
    521545    } 
    522546 
  • trunk/thrudex/src/CLuceneIndex.h

    r288 r293  
    2525 
    2626class bloom_filter; 
     27class UpdateFilter; 
    2728 
    2829#define DOC_KEY L"_doc_key_" 
     
    8081    bool                                             syncing; 
    8182 
     83    boost::shared_ptr<lucene::index::IndexReader>    disk_reader; 
     84    boost::shared_ptr<UpdateFilter>                  disk_filter; 
    8285    boost::shared_ptr<lucene::search::IndexSearcher> disk_searcher; 
    8386    boost::shared_ptr<bloom_filter>                  disk_bloom; 
  • trunk/thrudex/src/Makefile.am

    r259 r293  
    1010                  CLuceneRAMDirectory.cpp               \ 
    1111                  CLuceneIndex.cpp                      \ 
     12                  UpdateFilter.cpp                      \ 
    1213                  main.cpp 
    1314 
  • trunk/thrudex/src/thrudex.conf

    r263 r293  
    1616 
    1717# Set root logger level to DEBUG and its only appender to A1. 
    18 #log4j.rootLogger=DEBUG, A1 
    19 log4j.rootLogger=INFO, A1 
     18log4j.rootLogger=DEBUG, A1 
     19#log4j.rootLogger=INFO, A1 
    2020 
    2121# A1 is set to be a ConsoleAppender.