Click here to Skip to main content
15,888,271 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys!!

I am facing problem when user search any number or string then it treated both same.

Suppose - You want to search any book which name is "10 things to improve your skills". So either user enter 10 or Ten, in both cases the same results shown and other books which name exists 10 or Ten, they are also shown.

So please give me your valuable response ASAP.

Thanks in Advance!!

What I have tried:

I Make a method which converts Number Into Words.
Suppose You enter 50 then it returns Fifty but I didn't have any logic that enter Fifty and return 50. There are no any logic behind that.

So I am getting stuck on this point.
Posted

surely all you need is the reverse function of what you have already - you need to store words for

"one" through "nine"
"eleven" through "nineteen"
"ten", "twenty", ... "ninety"
(and possibly "hundred", "thousand", "million")

possibly in a dictionary, with their integer value - then it becomes a matter of matching the input text and adding up the numeric values of the numbers ie

'fifty one' ==> fifty -> 50 + one -> 1 = return int 51

I can think of variants on this, but this is simple enough
 
Share this answer
 
Comments
Gr8AmitTiwari 16-Feb-16 8:14am    
Hi Garth,

Really Sorry for late response !!!

I have tried the same concept as you have explained above. Thanks for that.

Make 2 functions, 1st is returned Number and 2nd is returned String of that number.

For using 1st function I have done this :-

Suppose I want to search book name - "Line 135".
Then First it will pick 135, convert it into string using function and then i have replaced that section with old search string.

So my first wish is complete.

Now comes to the 2nd point :-

Suppose I want to search book name - "Line One Hundred Thirty Five".
So how can i get One Hundred Thirty Five in above string? and then convert it into 135.

Thanks
Garth J Lancaster 16-Feb-16 19:31pm    
off the top of my head, I would

a) split that string by space to an array - so you end up with

0 : Line
1 : One
2 : Hundred
3 : Thirty
4 : Five

b) discard any elements in the array that dont match 'number' words in the dictionary, ie 'Line'

0 : One
1 : Hundred
2 : Thirty
3 : Five

c) step backwards through the array, keeping track of where you are wrt to a single element of units, tens, hundreds, thousands, and adding to an accumulator. Hundreds & thousands and millions positions require 2 array elements, the 'hundred' for example, and the multiplier ie 'one'

so

five, units position, add 5 to accumulator
thirty, tens position, add 30 to accumulator
hundred, hundreds position, hold 100 in a variable
one, hundreds multiplier, add 1 x 100 to accumulator

its almost as if you'd need a small state machine to do this - I guess a loop and a switch/case might suffice - btw, Sascha's answer is correct, obviously this solution here depends on having spaces between the words else it'll fall apart

Gr8AmitTiwari 17-Feb-16 6:34am    
Hi Garth & Sascha,

Successfully completed.

Now it is working fine.

Thanks a lot to both of you.
You would have to write a custom analyzer which converts all numbers (50) in a title into the spelled form (fifty) - or the other way around (but I think that would be a bit more difficult). You would have to use this analyzer for indexing and then also for querying so that the converted titles are the same both in the index and in the search term.

Google for "lucene custom analyzer" and you will find plenty of samples on how to do this.

However, I don't think it would result in a 100% satisfactory solution because there could be titles already containing the spelled form of a number but slightly different to what your analyzer produces for querying when someone enters it as a number, e.g. 101 could be "one hundred and one" or "onehundredandone" or "hundredone".

That's why I would suggest to educate your users to just skip numbers from the search term altogether. A book titled "10 things to improve your skills" will (should) also be found by searching for "things to improve your skills" - and then also a book titled "101 things to improve your skills" will show up which probably is in the users best interest.
 
Share this answer
 
Comments
Gr8AmitTiwari 16-Feb-16 8:19am    
Hi Sascha,

Thanks for your response.

Actually I am very new in Lucene Search. So not much more idea about the inbuilt dot net classes. I have tried above concepts as Garth describes above.

If getting stuck then comes to your point.

Thanks
Sascha Lefèvre 16-Feb-16 8:33am    
Alright! :)
Garth J Lancaster 16-Feb-16 19:33pm    
you make some good points about 'training your user(s)' :-)
Sascha Lefèvre 17-Feb-16 3:23am    
thank you :)
Gr8AmitTiwari 16-Mar-16 2:12am    
Hi All,

I am stuck one more thing.
The above problem has been fixed and working fine now.
But one more thing arises that suppose a user enter misspell the word what he search, then it will show the result also.

Ex- Suppose user enter Figty Shades of Grey. Figty spell is wrong. The correct is Fifty, then it will also show the same result.

So how I can identify using Lucene .Net search Engine?

Please help Sascha and Garth.


Thanks in Advance to both of you.

Amit Tiwari

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900