[Xapian-devel] Auto completion using xapian

Naveen A.N. naveen at searchlabs.org
Sun Oct 7 18:16:50 BST 2012


Hello James,

Thank you for your reply,
I tried using the below code.As you said it matches the partial query if i
remove the * but the thing is i am not sure is this the correct way to
generate the auto completion. Can u tell me how can i generate the auto
completion ? Or give me an example?

#include <xapian.h>
#include <iostream>
#include <string>
#include <cstdlib> // For exit().
#include <cstring>

using namespace std;

int main(int argc, char **argv)
try {

Xapian::WritableDatabase db("/home/example/xapian",
Xapian::DB_CREATE_OR_OPEN);
Xapian::TermGenerator indexer;
Xapian::Stem stemmer("english");
indexer.set_stemmer(stemmer);
indexer.set_database(db);
indexer.set_flags(indexer.FLAG_SPELLING);
string para = "master of business administration  master in c++ ";
Xapian::Document doc;
doc.set_data(para);
indexer.set_document(doc);
indexer.index_text(para);
db.add_document(doc);
db.commit();
Xapian::QueryParser parser;
parser.set_database(db);
parser.set_default_op(Xapian::Query::OP_AND);
parser.set_stemmer(stemmer);
parser.set_stemming_strategy(Xapian::QueryParser::STEM_SOME);
Xapian::Query query = parser.parse_query("master",
parser.FLAG_DEFAULT | parser.FLAG_SPELLING_CORRECTION
| parser.FLAG_AUTO_SYNONYMS | parser.FLAG_PARTIAL);
Xapian::Enquire enquire(db);
enquire.set_query(query);
Xapian::MSet mset = enquire.get_mset(0, 10);

for (Xapian::MSetIterator i = mset.begin(); i != mset.end(); i++) {
Xapian::Document doc = i.get_document();
string data = doc.get_data();
cout << *i << ": [" << i.get_weight() << "]\n" << data << "\n";
}
cout << flush;
}
catch (const Xapian::Error &e) {
cout << e.get_description() << endl;
exit(1);
}


On Sun, Oct 7, 2012 at 10:13 PM, James Aylett <james-xapian at tartarus.org>wrote:

> A query string such as "m*" is using the wildcard expansion operator – if
> you want to use the partial support, you don't want the * at the end of
> your query string.
>
> It's also not clear from your message whether you've set a database before
> trying to parse your query. You need to do this, because Xapian's wildcard
> support (which is what partial uses) is done at query time, expanding to
> all the possibly matching terms, rather than at index time in an n-gram
> analyzer style.
>
> If you still can't get this to work, try posting a complete program rather
> than just a snippet.
>
> James
>
>
> On 4 Oct 2012, at 18:20, Naveen A.N. <naveen at searchlabs.org> wrote:
>
> > Hello,
> >
> > Do xapian has analyzer like EdgeNGram to use it for autocomplete.
> >
> > I am trying to use the auto completion using xapian.
> > For example:
> > e
> > ex
> > exa
> > exam
> > example
> > etc..
> > so that we can get it.
> > I tried to use using the Partial flag but it dose not work Xapian::Query
> query = parser.parse_query("m*",parser.FLAG_PARTIAL);
> > Do you have any example or any tutorial is appreciated.
> >
> > --Naveen.
> > _______________________________________________
> > Xapian-devel mailing list
> > Xapian-devel at lists.xapian.org
> > http://lists.xapian.org/mailman/listinfo/xapian-devel
>
> --
>  James Aylett, occasional trouble-maker
>  xapian.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.xapian.org/pipermail/xapian-devel/attachments/20121007/e50f91f4/attachment.htm>


More information about the Xapian-devel mailing list