Naveen A.N.
2013-Sep-22 05:25 UTC
[Xapian-devel] How to filter search result with query with has white space.
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-0002.html>
Olly Betts
2013-Sep-22 06:08 UTC
[Xapian-devel] How to filter search result with query with has white space.
[Note: xapian-discuss is more appropriate for questions about how to use Xapian] On Sun, Sep 22, 2013 at 10:55:15AM +0530, Naveen A.N. wrote:> But "xapian title:Xapian is good" fails.You need double quotes to get the boolean prefix to apply to more than just "Xapian" - try searching for: xapian title:"Xapian is good" See http://trac.xapian.org/wiki/FAQ/NoMatches for tips on debugging this sort of problem. You probably don't want to treat the title as a boolean term though - a title is usually better handled as a probabilistic field. Cheers, Olly
Naveen A.N.
2013-Sep-22 06:34 UTC
[Xapian-discuss] [Xapian-devel] How to filter search result with query with has white space.
I tried the query xapian title:"Xapian is good" It was not working. The description is "Xapian::Query(((Ztitlexapian:(pos=1) OR Zcontentxapian:(pos=1)) FILTER title:Xapian is good))" And this is what i have when i use "delve -r 1 -d xapian/" Data for record #1: Xapain is good Term List for record #1: Zcontentadd Zcontentadvanc Zcontentallow Zcontentan Zcontentand Zcontentapplic Zcontentdevelop Zcontentengin Zcontentfacil Zcontentindex Zcontentis Zcontentlibrari Zcontentopen Zcontentown Zcontentsearch Zcontentsourc Zcontenttheir Zcontentto Zcontentwhich Zcontentxapian Ztitlegood Ztitleis Ztitlexapain Zurlhttp Zurlorg Zurlwww Zurlxapian contentadd contentadvanced contentallows contentan contentand contentapplications contentdevelopers contentengine contentfacilities contentindexing contentis contentlibrary contentopen contentown contentsearch contentsource contenttheir contentto contentwhich contentxapian titleXapain is good titlegood titleis titlexapain urlhttp urlorg urlwww urlxapian