kerighan / eldar

Boolean text search in Python
MIT License
44 stars 7 forks source link

match_word unable to handle multi-words and short words #26

Open Shaun-Tan-DJ opened 1 month ago

Shaun-Tan-DJ commented 1 month ago

Hi,

There is an issue with the match_word arg. If match_word=True, it will not be able to handle multi-words, but able to handle short words.

import eldar
eldar_query = eldar.Query('cake shop', match_word=True)
print(eldar_query('cake shop'))
# False, this is incorrect as it should match
import eldar
eldar_query = eldar.Query('cn', match_word=True)
print(eldar_query('cny'))
# False, this is correct

But if match_word=False, it will not be able to handle short words, but able to handle multi-words.

import eldar
eldar_query = eldar.Query('cake shop', match_word=False)
print(eldar_query('cake shop'))
# True, this is correct
import eldar
eldar_query = eldar.Query('cn', match_word=False)
print(eldar_query('cny'))
# True, this is incorrect as it should not match

I've tried testing with quotation marks and wildcards around multi-words, but it still does not work.

import eldar
eldar_query = eldar.Query('"cake shop"', match_word=True)
print(eldar_query('cake shop'))
# False, this is incorrect as it should not match

eldar_query = eldar.Query('cake*shop', match_word=True)
print(eldar_query('cake shop'))
# False, this is incorrect as it should not match

eldar_query = eldar.Query('"cake*shop"', match_word=True)
print(eldar_query('cake shop'))
# False, this is incorrect as it should not match