4
* Copyright (C) 2012 10gen Inc.
6
* This program is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU Affero General Public License, version 3,
8
* as published by the Free Software Foundation.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Affero General Public License for more details.
15
* You should have received a copy of the GNU Affero General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#include "mongo/db/fts/fts_command.h"
23
#include "mongo/db/fts/fts_enabled.h"
24
#include "mongo/db/fts/fts_search.h"
25
#include "mongo/db/fts/fts_util.h"
26
#include "mongo/util/mongoutils/str.h"
27
#include "mongo/util/timer.h"
33
using namespace mongoutils;
35
FTSCommand ftsCommand;
37
FTSCommand::FTSCommand()
41
void FTSCommand::addRequiredPrivileges(const std::string& dbname,
42
const BSONObj& cmdObj,
43
std::vector<Privilege>* out) {
45
actions.addAction(ActionType::find);
46
out->push_back(Privilege(parseNs(dbname, cmdObj), actions));
50
bool FTSCommand::run(const string& dbname,
54
BSONObjBuilder& result,
57
if ( !isTextSearchEnabled() ) {
58
errmsg = "text search not enabled";
62
string ns = dbname + "." + cmdObj.firstElement().String();
64
string search = cmdObj["search"].valuestrsafe();
65
if ( search.size() == 0 ) {
66
errmsg = "no search specified";
70
string language = cmdObj["language"].valuestrsafe();
72
int limit = cmdObj["limit"].numberInt();
77
if ( cmdObj["filter"].isABSONObj() )
78
filter = cmdObj["filter"].Obj();
81
if (cmdObj["project"].isABSONObj()) {
82
projection = cmdObj["project"].Obj();
85
return _run( dbname, cmdObj, options,
86
ns, search, language, limit, filter, projection, errmsg, result );