/* cos-search.cxx: * based on quickstartsearch.cc: Simplest possible searcher * * ----START-LICENCE---- * Copyright 1999,2000,2001 BrightStation PLC * Copyright 2003,2004 Olly Betts * Copyright 2011 Stiletto <blasux@blasux.ru> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 * USA */#include<xapian.h>#include<iostream>#include<cstdlib>#include<algorithm>#include<pcrecpp.h>usingnamespacestd;intmain(intargc,char**argv){// Simplest possible options parsing: we just require two or more// parameters.if(argc<3){cout<<"usage: "<<argv[0]<<" <path to database> <search query>"<<endl;exit(1);}// Catch any Xapian::Error exceptions throwntry{Xapian::Databasedb(argv[1]);Xapian::Enquireenquire(db);Xapian::QueryParserqp;stringqstring(argv[2]);pcrecpp::REprereg("([A-Za-z0-9_-]+):");pcrecpp::StringPieceinput(qstring);// Wrap in a StringPiecestringvar;while(prereg.FindAndConsume(&input,&var)){stringupvar=var+":";//std::transform(var.begin(), var.end(), var.begin(), ::tolower);std::transform(upvar.begin(),upvar.end(),upvar.begin(),::toupper);//cout << var << " -> " << upvar << endl;qp.add_boolean_prefix(var,upvar);}// Build the query objectXapian::Queryquery=qp.parse_query(qstring);//Xapian::Query::OP_OR, argv + 2, argv + argc);cerr<<"Performing query `"<<query.get_description()<<"'"<<endl;// Give the query object to the enquire sessionenquire.set_query(query);// Get the top 10 results of the queryXapian::MSetmatches=enquire.get_mset(0,db.get_doccount());// Display the resultscerr<<matches.size()<<" results found"<<endl;for(Xapian::MSetIteratori=matches.begin();i!=matches.end();++i){Xapian::Documentdoc=i.get_document();cout<<"#"<<*i<<"\t"<<doc.get_data()<<endl;}}catch(constXapian::Error&error){cerr<<"Exception: "<<error.get_msg()<<endl;}}