0

Normally in Whoosh phrase queries to search exact math are obtained using double quotes. It seems to work most but not all the time in bw2 (e.g. see here).

db.search('"{}"'.format("Carbon dioxide, from soil or biomass stock"))

['Carbon dioxide, from soil or biomass stock' (kilogram, None, ('air','non-urban air or from high stacks')), 
'Carbon dioxide, to soil or biomass stock' (kilogram, None, ('soil', agricultural')), 
'Carbon dioxide, from soil or biomass stock' (kilogram, None, ('air', 'urban air close to ground')),
'Carbon dioxide, from soil or biomass stock' (kilogram, None, ('air',)),
'Carbon dioxide, to soil or biomass stock' (kilogram, None, ('soil', 'forestry')),
'Carbon dioxide, from soil or biomass stock' (kilogram, None, ('air', 'indoor')),
'Carbon dioxide, from soil or biomass stock' (kilogram, None, ('air', 'lower stratosphere + upper troposphere')),
'Carbon dioxide, to soil or biomass stock' (kilogram, None, ('soil', 'industrial')),
'Carbon dioxide, from soil or biomass stock' (kilogram, None, ('air', 'low population density, long-term')),
'Carbon dioxide, to soil or biomass stock' (kilogram, None, ('soil',))]

Any idea on how to get exact match search?

Community
  • 1
  • 1
Giuseppe Cardellini
  • 135
  • 1
  • 2
  • 12

1 Answers1

2

The easiest way to find things which seem to be difficult in the Whoosh search index is to simply skip it, and filter the raw datasets, e.g.

[ds for ds in db if ds['name'].startswith('Carbon dioxide, from soil or biomass stock')]

It is quite easy to add arbitrary complexity because you are just adding Python functions.

Chris Mutel
  • 2,549
  • 1
  • 14
  • 9