I am attempting to run a SOLR query using a notion of "fuzzy searching" on some book titles. I am letting the user input keywords in which I will split up and check against the title of the book to return a result set to the user. With words that exceed 4 characters, I was going to add a fuzzy search of "~1" to allow for any misspellings or similar words within the result set.
An example of searching the keywords of "Mouse" and "give" would yield: (I am only providing this snippet here as proof that my index should contain my desired results)
{
"responseHeader":{
"status":0,
"QTime":1,
"params":{
"q":"(CatalogTitle:Mouse AND CatalogTitle: give)",
"fl":"CatalogTitle, score",
"start":"0",
"rows":"50",
"_":"1663261699801"}},
"response":{"numFound":9,"start":0,"maxScore":13.280009,"numFoundExact":true,"docs":[
{
"CatalogTitle":"If You Give A Mouse An Iphone",
"score":13.280009},
{
"CatalogTitle":"If You Give a Mouse a Cookie",
"score":13.280009},
{
"CatalogTitle":"If You Give A Mouse A Cookie",
"score":13.280009},
{
"CatalogTitle":"If You Give A Mouse A Brownie",
"score":13.280009},
{
"CatalogTitle":"If You Give A Mouse A Cookie",
"score":13.280009},
{
"CatalogTitle":"If You Give A Mouse A Cookie",
"score":13.280009},
{
"CatalogTitle":"If You Give A Mouse A Cookie (Big Book)",
"score":10.967654},
{
"CatalogTitle":"If You Give a Mouse A Cookie Shared Reading Pack",
"score":10.089267},
{
"CatalogTitle":"Si Le Das Una Galletita A Un Raton (If You Give A Mouse A Cookie)",
"score":7.641327}]
}}
This is exactly what I would expect for these two keywords.
Now I try "Moose" and "give" but put a ~1 on "Moose" to allow a fuzzy search of it, which I would expect "mouse" to be returned as well:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"(CatalogTitle:Moose~1 AND CatalogTitle: give)",
"fl":"CatalogTitle, score",
"start":"0",
"rows":"50",
"_":"1663261699801"}},
"response":{"numFound":3,"start":0,"maxScore":12.92557,"numFoundExact":true,"docs":[
{
"CatalogTitle":"If You Give A Moose A Muffin",
"score":12.92557},
{
"CatalogTitle":"If You Give A Moose A Muffin (Big Book)",
"score":10.674932},
{
"CatalogTitle":"Si Le Das Un Panecillo A Un Alce (If You Give A Moose A Muffin)",
"score":7.4373817}]
}}
As you see, it does not return what I would expect.
I attempt to change it to ~2 to see what happens:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"(CatalogTitle:Moose~2 AND CatalogTitle: give)",
"fl":"CatalogTitle, score",
"start":"0",
"rows":"50",
"_":"1663261699801"}},
"response":{"numFound":4,"start":0,"maxScore":12.4069805,"numFoundExact":true,"docs":[
{
"CatalogTitle":"If You Give A Moose A Muffin",
"score":12.4069805},
{
"CatalogTitle":"If You Give A Moose A Muffin (Big Book)",
"score":10.246639},
{
"CatalogTitle":"Si Le Das Un Panecillo A Un Alce (If You Give A Moose A Muffin)",
"score":7.1389856},
{
"CatalogTitle":"The Law Of Rewards: Giving What You Can't Keep To Gain What You Can't Lose",
"score":5.767641}]
}}
This baffles me as it brings back a title with "lose" in it, which does match the ~2 for "moose" by removing the m and swapping an "o" for an "l".
What am I doing wrong here? Is there something that I am overlooking? Clearly fuzzy searching is working for me with the 2nd example, but I can't seem to get it to work when just using "~1".