Ticket #448: main.cc

File main.cc, 1.7 KB (added by Evgeny Sizikov, 14 years ago)

C++ test to use HunspellStem with Xapian::QueryParser

Line 
1/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2/*
3 * main.cc
4 * Copyright (C) Evgeny Sizikov 2010 <esizikov@gmail.com>
5 *
6 * test_xapian_stem is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * test_xapian_stem is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <iostream>
21#include <algorithm>
22
23#include <xapian/queryparser.h>
24#include "xapian_hunspell_stemmer.h"
25
26// a search query in Russian as an example of non-ASCII characters in UTF-8
27const std::string search_query = "платья из золота на продажу";
28
29int main()
30{
31 // get a stemmer instance
32 Xapian::HunspellStem stem("ru");
33
34 // get a query parser instance
35 Xapian::QueryParser qp;
36
37 // apply our stemmer
38 qp.set_stemmer(stem);
39 // set stemming strategy to return only stemmed terms
40 qp.set_stemming_strategy(Xapian::QueryParser::STEM_ALL);
41
42 // parse the query using our stemmer
43 Xapian::Query query = qp.parse_query(search_query);
44
45 // output original search query
46 std::cout << search_query << "\n";
47
48 // output parsed query terms
49 std::copy(
50 query.get_terms_begin(),
51 query.get_terms_end(),
52 std::ostream_iterator<std::string >(std::cout, " "));
53 std::cout << std::endl;
54
55 return 0;
56}