Implementation of substring search in omegascript

James Aylett james-xapian at tartarus.org
Mon Feb 15 00:41:38 GMT 2016


On 14 Feb 2016, at 18:52, Ayush Gupta <ayushgp10 at gmail.com> wrote:

> I tried implementing the bite sized project idea posted here: https://trac.xapian.org/wiki/ProjectIdeas#AddnewOmegaScriptcommandtodoasubstringsearch but could not understand what needs to be returned when this command is called. 

Hi, Ayush. It’s probably worth you creating a short plan as you figure out what’s needed here. Having a plan before you write code is always a good idea, and if you create it as a gist or similar, you can share it with other people on the list when asking questions. It’ll help others know where you’ve got to and what you’ve tried, and is good practice for when you get into larger projects (such as GSoC) which last weeks or months.

> This line is not so clear to me: expand to the offset of the first occurrence of fish from the start of the string if $query, or to if $query doesn't contain the substring fish.

Based on the description, here are some examples of what `$contains{fish,$query}` would expand to based on different values of `$query`:

$query		$contains{fish,$query}
--------------------------------------
hello		(empty string)
fish		0
hello fish	6

So you’d be able to do things like `$if{$contains{fish,$query},fish present,no fishes}`.

Hopefully that makes it more clear.

> Also in query.cc file in omega dir, when defining function descriptions, what does the evalargs and ensure arguments mean? 

ensure means that the command requires either a query (‘Q’) or a query and a match (‘M’) to have been evaluated in the script up to that point. (See lines 1246–1248 of query.cc.)

evalargs (ll 1238–1244) controls the number of arguments to the command that are evaluated, ie that themselves can contain OmegaScript commands. (Some commands explicitly evaluate some of their arguments themselves, so this is more convenience where a number of the arguments need evaluating unconditionally — such as for `$def{}` where the macroname is evaluated, but the expansion of the macro is not, and `$if{}` where we only want to evaluate one of the result branches, not both.)

Ideally they’d both be explained in comments in the source code (around the structure definition and macro). Feel free to make a small patch and pull request to cover that!

(Note that it looks to me like there’s a bug in the evalargs handling, where minargs == N.)

J

-- 
 James Aylett, occasional trouble-maker
 xapian.org




More information about the Xapian-devel mailing list