[Xapian-devel] How to filter search result with query with has white space.

Naveen A.N. naveen at searchlabs.org
Sun Sep 22 06:25:15 BST 2013


Hello,

include <iostream>#include <string>#include <xapian.h>struct document{
    std::string title;
    std::string content;
    std::string url;};
void indexData(document d) {
    try {
        Xapian::WritableDatabase db("/Users/ramesh/Desktop/xapian",
Xapian::DB_CREATE_OR_OPEN);
        Xapian::TermGenerator indexer;
        Xapian::Stem stemmer("english");
        indexer.set_stemmer(stemmer);
        Xapian::Document doc;
        doc.set_data(d.title);
        indexer.set_document(doc);
        indexer.index_text(d.title,1,"title");
        indexer.index_text(d.content,1,"content");
        indexer.index_text(d.url,1,"url");
        doc.add_boolean_term("title"+d.title);
        db.replace_document(d.url,doc);
        db.commit();
    } catch (const Xapian::Error &e) {
        std::cout << e.get_description() << std::endl;
        exit(1);
    }}
void searchData(std::string query_string){
    try{
        Xapian::Database db("/Users/ramesh/Desktop/xapian");
        Xapian::Enquire enquire(db);
        Xapian::QueryParser qp;
        Xapian::Stem stemmer("english");
        qp.set_default_op(Xapian::Query::OP_FILTER);
        qp.set_stemmer(stemmer);
        qp.add_prefix("","title");
        qp.add_prefix("","content");
        qp.add_boolean_prefix("title","title");
        qp.set_database(db);
        qp.set_stemming_strategy(Xapian::QueryParser::STEM_SOME);
        Xapian::Query query = qp.parse_query(query_string);
        std::cout << "Parsed query is: " << query.get_description() <<
std::endl;
        enquire.set_query(query);
        Xapian::MSet matches = enquire.get_mset(0, 10);
        std::cout << matches.get_matches_estimated() << " results found.\n";
        std::cout << "Matches 1-" << matches.size() << ":\n" << std::endl;
        for (Xapian::MSetIterator i = matches.begin(); i !=
matches.end(); ++i) {
            std::cout << i.get_rank() + 1 << ": " << i.get_weight() <<
" docid=" << *i
                 << " [" << i.get_document().get_data() << "]\n\n";
        }
    } catch (const Xapian::Error &e) {
        std::cout << e.get_description() << std::endl;
        exit(1);
    }
}
int main(){
    document d1,d2;
    d1.title = "Xapain is good";
    d1.content = "Xapian is an open source search engine library,
which allows developers to add advanced indexing and search facilities
to their own applications.";
    d1.url = "http://www.xapian.org";
    d2.title = "Xapain is awesome";
    d2.content = "good Xapian is an open source search engine library,
which allows developers to add advanced indexing and search facilities
to their own applications.";
    d2.url = "http://www.xapian.org/test";
    indexData(d1);
    indexData(d2);
    searchData("xapian title:good");
    searchData("xapian title:Xapian is good");
    return 0;}

First query with filter "xapian title:good" works well.

But "xapian title:Xapian is good" fails.

Can any one please explain what is the issue ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xapian.org/pipermail/xapian-devel/attachments/20130922/732f4edb/attachment.html>


More information about the Xapian-devel mailing list