diff options
author | Andreas Bille <abi@openoffice.org> | 2001-05-11 11:39:12 +0000 |
---|---|---|
committer | Andreas Bille <abi@openoffice.org> | 2001-05-11 11:39:12 +0000 |
commit | e6de18799594feefb7708e559b0b3edbef755152 (patch) | |
tree | ecfd2083639440c2bb599473d1e7b08c5cec008e /xmlhelp | |
parent | e71d70e474e7ec2dcb3672c5710ab450a9e007f8 (diff) |
C++-search engine now also searching in specific scopes
Diffstat (limited to 'xmlhelp')
-rw-r--r-- | xmlhelp/source/cxxhelp/qe/Query.cxx | 132 | ||||
-rw-r--r-- | xmlhelp/source/cxxhelp/qe/QueryProcessor.cxx | 6 | ||||
-rw-r--r-- | xmlhelp/source/cxxhelp/qe/Search.cxx | 191 |
3 files changed, 228 insertions, 101 deletions
diff --git a/xmlhelp/source/cxxhelp/qe/Query.cxx b/xmlhelp/source/cxxhelp/qe/Query.cxx index adca71711975..80520755c261 100644 --- a/xmlhelp/source/cxxhelp/qe/Query.cxx +++ b/xmlhelp/source/cxxhelp/qe/Query.cxx @@ -2,9 +2,9 @@ * * $RCSfile: Query.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: abi $ $Date: 2001-05-10 15:25:32 $ + * last change: $Author: abi $ $Date: 2001-05-11 12:39:12 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -139,61 +139,26 @@ QueryHit* HitStore::createQueryHit( double penalty,sal_Int32 doc,sal_Int32 begin struct CompareQueryHit { - inline int operator()( const QueryHit* l,const QueryHit* r ); + bool operator()( const QueryHit* l,const QueryHit* r ) + { + return l->compareTo( r ); + } }; -int CompareQueryHit::operator()( const QueryHit* l,const QueryHit* r ) -{ - return l->compareTo( r ); -} - - #include <stl/algorithm> -sal_Int32 QueryHit::compareTo( const QueryHit* o ) const -{ - if( penalty_ != o->penalty_ ) - return penalty_ < o->penalty_ ? -1 : 1; - else if( begin_ != o->begin_ ) - return begin_ < o->begin_ ? -1 : 1; - else if( end_ != o->end_ ) - return end_ < o->end_ ? -1 : 1; - else - return 0; -} - - QueryHit* HitStore::firstBestQueryHit() { -// for( sal_uInt32 i = 0; i < heap_.size(); ++i ) -// { -// heap_[i]->setNum( i ); -// printf( " element %d = %x\n",i,heap_[i] ); -// } - -// printf( " and the size %d(%d)\n", free_,heap_.size() ); - if( free_ > 0) { -// std::vector< sal_Int32 > bla(100); -// for( i = 0; i < 100; ++i ) -// bla[i] = i*(i-99); -// std::sort( bla.begin(),bla.end() ); - -// CompareQueryHit bla; - -// std::sort( heap_.begin(),heap_.end(),bla ); - - // quicksort( 0,free_ - 1 ); - -// for( i = 0; i < heap_.size(); ++i ) -// { -// heap_[i]->setNum( i ); -// printf( " element %d = %x\n",i,heap_[i] ); -// } +// for( sal_uInt32 i = 0; i < heap_.size(); ++i ) +// printf( " number = %x\n",heap_[i] ); + CompareQueryHit bla; + heap_.resize( free_ ); + std::stable_sort( heap_.begin(),heap_.end(),bla ); index_ = 0; return nextBestQueryHit(); } @@ -229,37 +194,37 @@ void HitStore::heapify( sal_Int32 i ) } -sal_Int32 HitStore::partition( sal_Int32 p,sal_Int32 r ) -{ - QueryHit* x = heap_[ ((p + r) >> 1) & 0x7FFFFFFF ]; - sal_Int32 i = p - 1, j = r + 1; - while( true ) - { - while( x->compareTo( heap_[--j] ) ) - ; - while( heap_[++i]->compareTo( x ) ) - ; - if( i < j ) - { - QueryHit* t = heap_[i]; - heap_[i] = heap_[j]; - heap_[j] = t; - } - else - return j; - } -} +// sal_Int32 HitStore::partition( sal_Int32 p,sal_Int32 r ) +// { +// QueryHit* x = heap_[ ((p + r) >> 1) & 0x7FFFFFFF ]; +// sal_Int32 i = p - 1, j = r + 1; +// while( true ) +// { +// while( x->compareTo( heap_[--j] ) ) +// ; +// while( heap_[++i]->compareTo( x ) ) +// ; +// if( i < j ) +// { +// QueryHit* t = heap_[i]; +// heap_[i] = heap_[j]; +// heap_[j] = t; +// } +// else +// return j; +// } +// } -void HitStore::quicksort( sal_Int32 p,sal_Int32 r ) -{ - while( p < r ) - { - sal_Int32 q = partition( p,r ); - quicksort(p, q); - p = q + 1; - } -} +// void HitStore::quicksort( sal_Int32 p,sal_Int32 r ) +// { +// while( p < r ) +// { +// sal_Int32 q = partition( p,r ); +// quicksort(p, q); +// p = q + 1; +// } +// } @@ -315,19 +280,17 @@ Query::~Query() } -void Query::setIgnoredElements( const rtl::OUString& element ) -{ -} - - - void Query::setIgnoredElements( const sal_Int32 ignoredElementsL,const rtl::OUString* ignoredElements ) { if( ctx_ ) ignoredElements_ = ctx_->getIgnoredElementsSet( ignoredElementsL_, ignoredElementsL,ignoredElements ); - if( ! ctx_ ) ignoredElementsL_ = 0; + if( ! ctx_ ) + { + ignoredElementsL_ = 0; + ignoredElements_ = 0; + } } @@ -361,7 +324,7 @@ void Query::getHits( std::vector< QueryHitData* >& data,sal_Int32 n ) QueryHit* Query::maybeCreateQueryHit( double penalty, - sal_Int32 doc, sal_Int32 begin, sal_Int32 end, sal_Int32 parentContext) + sal_Int32 doc, sal_Int32 begin, sal_Int32 end, sal_Int32 parentContext ) { // hits are located using only terms actually present in text // if B is not present, the query A B C reduces to A C and penalties @@ -369,13 +332,14 @@ QueryHit* Query::maybeCreateQueryHit( double penalty, // to meaningfully merge results from different servers, some of which // may have B, penalty has to be normalized to the common computing scheme - return + QueryHit* res = ( store_.goodEnough( penalty += missingTermsPenalty_,begin,end ) && ( ! ignoredElements_ || ctx_->notIgnored( parentContext,ignoredElementsL_,ignoredElements_ ) ) ) ? store_.createQueryHit( penalty,doc,begin,end ) : 0; + return res; } diff --git a/xmlhelp/source/cxxhelp/qe/QueryProcessor.cxx b/xmlhelp/source/cxxhelp/qe/QueryProcessor.cxx index 2f10d5740fa9..60da249e5410 100644 --- a/xmlhelp/source/cxxhelp/qe/QueryProcessor.cxx +++ b/xmlhelp/source/cxxhelp/qe/QueryProcessor.cxx @@ -2,9 +2,9 @@ * * $RCSfile: QueryProcessor.cxx,v $ * - * $Revision: 1.1 $ + * $Revision: 1.2 $ * - * last change: $Author: abi $ $Date: 2001-05-08 12:02:45 $ + * last change: $Author: abi $ $Date: 2001-05-11 12:39:12 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -92,7 +92,7 @@ QueryResults* QueryProcessor::processQuery( const QueryStatement& ment ) { Search search( env_ ); Query* query = processQuery( search,ment ); - query->setIgnoredElements( rtl::OUString::createFromAscii("") ); + query->setIgnoredElements( 0,0 ); search.startSearch(); return makeQueryResults( query,ment.getHitCount() ); } diff --git a/xmlhelp/source/cxxhelp/qe/Search.cxx b/xmlhelp/source/cxxhelp/qe/Search.cxx index ef422e9bfe4e..b643ec099574 100644 --- a/xmlhelp/source/cxxhelp/qe/Search.cxx +++ b/xmlhelp/source/cxxhelp/qe/Search.cxx @@ -2,9 +2,9 @@ * * $RCSfile: Search.cxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: abi $ $Date: 2001-05-10 15:25:32 $ + * last change: $Author: abi $ $Date: 2001-05-11 12:39:12 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -68,13 +68,177 @@ using namespace xmlsearch; using namespace xmlsearch::qe; + + +/******************************************************************************/ +/* */ +/* Emtpy ConceptData/Query */ +/* */ +/******************************************************************************/ + + +class EmptyConceptData + : public ConceptData +{ +public: + + virtual void generateFillers( std::vector< RoleFiller* >& array, sal_Int32 last ) { } + +}; // end class EmptyQuery + + + +class EmptyQuery + : public Query +{ +public: + + EmptyQuery() + : Query( 0,0,0,0,0 ), + conceptDataInstance_( ) + { + } + + virtual ConceptData* makeConceptData( sal_Int32 query, + sal_Int32 col, + sal_Int32 concept, + double score ) + { + return &conceptDataInstance_; + } + +private: + + EmptyConceptData conceptDataInstance_; + +}; // end class EmptyQuery + + + +/******************************************************************************/ +/* */ +/* ConceptData1/Query1 */ +/* */ +/******************************************************************************/ + + +class ConceptData1 + : public ConceptData +{ +public: + + ConceptData1( sal_Int32 id, + sal_Int32 role, + double score, + sal_Int32 queryNo, + sal_Int32 nColumns, + ContextTables* ctxInfo, + sal_Int32 code ) + : ConceptData( id,role,score,queryNo,nColumns,ctxInfo ), + fieldCode_( code ) + { + } + + virtual void generateFillers( std::vector< RoleFiller* >& array, sal_Int32 pos ); + + +private: + + sal_Int32 fieldCode_; + +}; // end class ConceptData1 + + +class Query1 + : public Query +{ +public: + + Query1( XmlIndex* env, + sal_Int32 nColumns, + sal_Int32 nHits, + sal_Int32 missingPenaltiesL, + double* missingPenalties, + sal_Int32 fieldCode ) + : Query( env,nColumns,nHits,missingPenaltiesL,missingPenalties ), + searchFieldCode_( fieldCode ) + { + } + + virtual ConceptData* makeConceptData( sal_Int32 col, + sal_Int32 concept, + double score, + sal_Int32 query ); + + +private: + + sal_Int32 searchFieldCode_; +}; + + + +/********************************************************************************/ +// Impl +/********************************************************************************/ + + +void ConceptData1::generateFillers( std::vector< RoleFiller* >& array, sal_Int32 pos ) +{ + if( array[ queryNo_ ] != RoleFiller::STOP() ) + { // not 'prohibited' + // !!! candidate for a single _ctx op + sal_Int32 ancestor = ctx_->firstParentWithCode(pos,fieldCode_); + if( ancestor != -1 ) + { + + + RoleFiller* p = new RoleFiller( nColumns_, + this, + role_, + pos, + ancestor, + pos + proximity_); + p->use( array,queryNo_ ); + } + } + + if( next_ ) + next_->generateFillers( array,pos ); +} + + + +ConceptData* Query1::makeConceptData( sal_Int32 col, + sal_Int32 concept, + double score, + sal_Int32 query ) +{ + return new ConceptData1( concept,col,score,query,nColumns_,ctx_,searchFieldCode_ ); +} + + + +/******************************************************************************/ +/* */ +/* QueryFactoryImpl */ +/* */ +/******************************************************************************/ + + class QueryFactoryImpl { public: Query* makeQuery( XmlIndex* env,const rtl::OUString& context,sal_Int32 nColumns,sal_Int32 nHits); -}; +private: + + EmptyQuery emptyQueryInstance_; + +}; // end class QueryFactoryImpl + + Query* QueryFactoryImpl::makeQuery( XmlIndex* env, @@ -82,36 +246,35 @@ Query* QueryFactoryImpl::makeQuery( XmlIndex* env, sal_Int32 nColumns, sal_Int32 nHits ) { - // ContextTables* contextTables = env->getContextInfo(); - if( ! context.getLength() ) - { - // cout << "contextlength zero" << endl; return new Query( env,nColumns,nHits,0,0 ); - } else if( context.indexOf( sal_Unicode( '|' ) ) != -1 ) { - return 0; // needs to be modified + return 0; //t } else if( context.indexOf( rtl::OUString::createFromAscii( "//" ) ) != -1 ) { - return 0; // needs to be modified + return 0; //t } else if( context.indexOf( sal_Unicode( '/' ) ) != -1 ) { - return 0; // needs to be modified + return 0; //t } else if( context.indexOf( sal_Unicode( '@' ) ) != -1 ) { - return 0; // needs to be modified + return 0; //t } else if( context.indexOf( sal_Unicode( '[' ) ) != -1 ) { - return 0; // needs to be modified + return 0; //t } else { - return 0; // needs to be modified + sal_Int32 code = env->getContextInfo()->linkCode( context ); + if( code != -1 ) + return new Query1( env,nColumns,nHits,0,0,code); + else + return &emptyQueryInstance_; } } |