FAQ

[Xapian-discuss] How to choose the proximity between search words

Nat
Dec 7, 2011 at 2:14 pm
Hi,

I'd like to know how we can choose the distance between two words that we search
in a text. I know there is an "op_near" operator but I don't know how I can
specified that the number of words between the two specified words should not
exceed 10 or 20 or x words.

I'm really sorry for my terrible English, I hope I'm understandable!
reply

Search Discussions

8 responses

  • James Aylett at Dec 7, 2011 at 4:07 pm

    On 7 Dec 2011, at 14:14, Nat wrote:

    I'd like to know how we can choose the distance between two words that we search
    in a text. I know there is an "op_near" operator but I don't know how I can
    specified that the number of words between the two specified words should not
    exceed 10 or 20 or x words.

    Hey, Nat. For OP_NEAR (and OP_PHRASE), the "parameter" to the Xapian::Query constructor gives a "window" which will do what you want. The getting started guide has a little on these <http://getting-started-with-xapian.readthedocs.org/en/latest/concepts/search/queries.html#near-and-phrase>, although probably not nearly enough. I don't think it has practical examples of using them, but in the meantime the API docs have some details:

    <http://xapian.org/docs/apidoc/html/classXapian_1_1Query.html#7e7b6b8ad0c915c2364578dfaaf6100b7a78c8353d5d06d3a38c1899ae762b21>

    Hope this helps!

    J

    --
    James Aylett
    talktorex.co.uk - xapian.org - devfort.com
  • Nat at Dec 13, 2011 at 10:07 am
    Hi!

    Thanks for your response, I'm not sure I totally understand how it works, but
    this surely helps.
    I have something where to start ;)

    Nat
  • Nat at Dec 22, 2011 at 2:36 pm
    Hi!

    So thanks to James and OP_NEAR operator, I can search for terms within 10 words
    of each other. What I'd like is to choose the number of words : 10, 20, 50... Is
    that possible?

    Thanks in advance,

    Nat
  • James Aylett at Dec 22, 2011 at 3:16 pm

    On 22 Dec 2011, at 14:36, Nat wrote:

    So thanks to James and OP_NEAR operator, I can search for terms within 10 words
    of each other. What I'd like is to choose the number of words : 10, 20, 50... Is
    that possible?

    Nat ? this is what the Query parameter is used for with OP_NEAR. It's called the "window" that the near operator works over.

    J

    --
    James Aylett
    talktorex.co.uk - xapian.org - devfort.com
  • Nat at Dec 22, 2011 at 4:29 pm
    Oh! Ok, I really didn't understand that... Thanks a lot!

    Nat
  • Nat at Jan 3, 2012 at 8:46 am
    Hi! And happy new year :)

    With the end of the year, I haven't had much time to work on my search
    application. I just tried to use Xapian::Query constructor to specify my window
    size, but I can't find the right syntax, nothing worked :(

    This is my PHP code:


    $queryOP = XapianQuery::OP_NEAR;
    $proximity = 30;

    $queryparser->set_default_op(XapianQuery::OP_NEAR);
    $query = $queryparser->parse_query($searchexp,XapianQueryParser::FLAG_DEFAULT);


    where searchexp is, for example, "vierge marie".

    I've got my query, but I don't know how I can use Xapian::Query constructor or
    any function of this class to specify my $proximity.

    I have to admit I'm a little lost!

    Thanks in advance

    Nat
  • Olly Betts at Jan 4, 2012 at 1:32 am

    On Tue, Jan 03, 2012 at 08:46:12AM +0000, Nat wrote:
    $queryOP = XapianQuery::OP_NEAR;
    $proximity = 30;

    $queryparser->set_default_op(XapianQuery::OP_NEAR);
    $query = $queryparser->parse_query($searchexp,XapianQueryParser::FLAG_DEFAULT);
    You can't currently set the window size used by QueryParser if you set
    default_op to OP_NEAR.
    I've got my query, but I don't know how I can use Xapian::Query
    constructor or any function of this class to specify my $proximity.
    If you build the phrase Query object by hand, you would do it like so:

    $query = new XapianQuery(XapianQuery::OP_NEAR, array('hello', 'world'), 30);

    Cheers,
    Olly
  • Nat at Jan 4, 2012 at 9:58 am
    Olly Betts <olly <at> survex.com> writes:
    If you build the phrase Query object by hand, you would do it like so:

    $query = new XapianQuery(XapianQuery::OP_NEAR, array('hello', 'world'), 30);

    Cheers,
    Olly
    OK! Thank you, I understand now :)

Related Discussions

Discussion Navigation
viewthread | post

3 users in discussion

Nat: 6 posts James Aylett: 2 posts Olly Betts: 1 post