python - What is the best way to allow users to search for items -


i have search feature in application allows users search products. query

select * products title '%search_term%'

this quick , hacky way of implementing this. want improve , wondering how can this.

three short examples

  1. being able search plurals.

my title product might golden delicious apple if users searches apples. because of plural row not returned.

  1. when words one/two words

my title product might lemon cupcakes if user searches cup cakes

  1. if user searches apples , lemons should return both rows in example 1 , 2 or should return nothing? considered best practice.

fyi using python , peewee. can think of ideas how gets complicated fast.

well, depending on database using, have couple options.

sqlite has full-text search extension supports stemming (normalizes plural forms, etc). peewee has rich support sqlite fts:

postgresql has full-text via tsvector data type. peewee supports this:

finally, mysql supports full-text search, though have not experimented using peewee i'm pretty sure should work out of box:


regarding question 2, "cup cakes" -> "cupcakes", i'm not sure best solution going in case.

with question 3, know sqlite correctly handle boolean expressions in queries, e.g. "apples , lemons" match documents containing both, whereas "apples or lemons" match documents containing 1 or other. imagine postgres , mysql same.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -