summaryrefslogtreecommitdiff
path: root/src/mongo/db/fts/stop_words.cpp
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2012-12-25 12:08:28 -0500
committerEliot Horowitz <eliot@10gen.com>2012-12-25 12:25:45 -0500
commitf201972ecc87f099777e1c61f269998f4399caf4 (patch)
treee23f1743cf486acbef64bd825b00bd82bb573d95 /src/mongo/db/fts/stop_words.cpp
parentd2df300721805ace411b5d1a87cb4bf6d8a51ff3 (diff)
downloadmongo-f201972ecc87f099777e1c61f269998f4399caf4.tar.gz
SERVER-380: Experimental text search indexing
Diffstat (limited to 'src/mongo/db/fts/stop_words.cpp')
-rw-r--r--src/mongo/db/fts/stop_words.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/mongo/db/fts/stop_words.cpp b/src/mongo/db/fts/stop_words.cpp
new file mode 100644
index 00000000000..0d664caf1bf
--- /dev/null
+++ b/src/mongo/db/fts/stop_words.cpp
@@ -0,0 +1,73 @@
+// stop_words.cpp
+
+/**
+* Copyright (C) 2012 10gen Inc.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License, version 3,
+* as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <map>
+#include <set>
+#include <string>
+
+#include "mongo/db/fts/stop_words.h"
+
+#include "mongo/base/init.h"
+#include "mongo/platform/unordered_map.h"
+
+
+
+namespace mongo {
+
+ namespace fts {
+
+ void loadStopWordMap( std::map< std::string, std::set< std::string > >* m );
+
+ namespace {
+ unordered_map<string,StopWords*> STOP_WORDS;
+ StopWords* empty = NULL;
+ }
+
+
+ StopWords::StopWords(){
+ }
+
+ StopWords::StopWords( const std::set<std::string>& words ) {
+ for ( std::set<std::string>::const_iterator i = words.begin(); i != words.end(); ++i )
+ _words.insert( *i );
+ }
+
+ const StopWords* StopWords::getStopWords( const std::string& langauge ) {
+ unordered_map<string,StopWords*>::const_iterator i = STOP_WORDS.find( langauge );
+ if ( i == STOP_WORDS.end() )
+ return empty;
+ return i->second;
+ }
+
+
+ MONGO_INITIALIZER(StopWords)(InitializerContext* context) {
+ empty = new StopWords();
+
+ std::map< std::string, std::set< std::string > > raw;
+ loadStopWordMap( &raw );
+ for ( std::map< std::string, std::set< std::string > >::const_iterator i = raw.begin();
+ i != raw.end();
+ ++i ) {
+ STOP_WORDS[i->first] = new StopWords( i->second );
+ }
+ return Status::OK();
+ }
+
+ }
+
+}