need help on FLAG_PARTIAL

Eden He deisler.he at gmail.com
Tue Apr 20 08:37:58 BST 2021


Hi Olly,

Thanks for your code, I finally figured out the problem, the query I passed
to parse_query is incorrectly enclosed by quotation marks.
Thank you so much.

Olly Betts <olly at survex.com> 于2021年4月20日周二 上午11:33写道:

> On Tue, Apr 20, 2021 at 10:34:31AM +0800, Eden He wrote:
> > I created an index for them and gave a prefix "P" to the field "phone",
> > and there is one doc whose value of phone is "53083763748".
> > However, when I searched that field using FLAG_PARTIAL, I can only get
> > results when I used the following code:
> >
> > queryparser.add_prefix("phone", "P")
> > query = queryparser.parse_query("phone:5",
> xapian.QueryParser.FLAG_PARTIAL)
> >
> > when I expand the query to "53" or "530", I can only get nothing.
> >
> > queryparser.add_prefix("phone", "P")
> > query = queryparser.parse_query("phone:53",
> xapian.QueryParser.FLAG_PARTIAL)
> >
> > there must be something wrong, but I cannot tell where it is. Would you
> > please help me with this?
>
> I can't reproduce your problem.
>
> Creating the database:
>
> $ python3 -c 'import xapian; db=xapian.WritableDatabase("tmp.db");
> doc=xapian.Document(); doc.add_term("P53083763748"); db.add_document(doc);
> db.commit()'
>
> And:
>
> $ python3 -c 'import xapian; db=xapian.Database("tmp.db");
> enq=xapian.Enquire(db); qp=xapian.QueryParser(); qp.add_prefix("phone", "P")
> for q in (5, 53, 530): enq.set_query(qp.parse_query("phone:"+str(q),
> xapian.QueryParser.FLAG_PARTIAL)); print("%d -> %d match" % (q,
> enq.get_mset(0,10).size()))'
> 5 -> 1 match
> 53 -> 1 match
> 530 -> 1 match
>
> If you still can't get it to work, please post a simple script which
> demonstrates it not working.
>
> Cheers,
>     Olly
>


-- 
all the best.


More information about the Xapian-discuss mailing list