Issues in Example code
James Aylett
james-xapian at tartarus.org
Tue Feb 16 12:13:02 GMT 2016
[Please keep replies on list, so that everyone can help and benefit.]
On 15 Feb 2016, at 20:39, Shiv Kandikuppa <shiv12095 at iiitd.ac.in> wrote:
> I initially misunderstood the guide and wrongly tried the above steps. Now I have gone over the documentation for the parts pertaining to indexing, searching and range queries.
Great.
> I could not understand the part [The xapian.DateValueRangeProcessor is working on value slot 2, with an “epoch” of 1860 (so two digit years will be considered as starting at 1860 and going forward as far 1959).]. I have tried the command:
>
> python code/python/search_ranges2.py statesdb 61..64
>
> hoping to get all states that were admitted between 1861 and 1864 but instead got the output as INFO:xapian.search:'61..64'[0:100]
>
> Could you help me as to how do we use the 2 digit years in our range queries.
Okay, this isn’t quite as clear as it should be in the documentation. The _DateValueRangeProcessor_, operating on slot 2, is dealing with dates in the form “mm/dd/yy” and “mm/dd/yyyy”, and that’s the one that copes with two-digit years. The _NumberValueRangeProcessor_, operating on slot 1, and doesn’t have this feature (because it doesn’t know anything about dates or years).
If you needed this functionality, you could write a custom _ValueRangeProcessor_ to do the processing, like _PopulationValueRangeProcessor_ at the end of the section. (You’d want to make the adjustments in `__call__()` before calling to the wrapped _NumberValueRangeProcessor_.)
I’ll see if I can improve the way that part’s written so it’s less confusing.
> python code/python/search_ranges2.py statesdb 10..
>
> causes an Exception
> File "code/python/search_ranges2.py", line 97, in <module>
> search(dbpath = sys.argv[1], querystring = " ".join(sys.argv[2:]))
> File "code/python/search_ranges2.py", line 72, in search
> population = support.format_numeral(fields.get('population', 0))
> File "/home/shiv/Xapian-doc/xapian-docsprint/code/python/support.py", line 140, in format_numeral
> raise ValueError("Numeral must be an int type to format")
> ValueError: Numeral must be an int type to format
That’s a problem with the states dataset, which I’ve now fixed; if you update from github it should work properly. Sorry about that!
J
--
James Aylett, occasional trouble-maker
xapian.org
More information about the Xapian-devel
mailing list