{"action":"created","issue":{"url":"https://api.github.com/repos/fmmfonseca/completely/issues/4","labels_url":"https://api.github.com/repos/fmmfonseca/completely/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/fmmfonseca/completely/issues/4/comments","events_url":"https://api.github.com/repos/fmmfonseca/completely/issues/4/events","html_url":"https://github.com/fmmfonseca/completely/issues/4","id":93265109,"number":4,"title":"Support multiple lookup types using one index","user":{"login":"fabiankessler","id":2506130,"avatar_url":"https://avatars.githubusercontent.com/u/2506130?v=3","gravatar_id":"","url":"https://api.github.com/users/fabiankessler","html_url":"https://github.com/fabiankessler","followers_url":"https://api.github.com/users/fabiankessler/followers","following_url":"https://api.github.com/users/fabiankessler/following{/other_user}","gists_url":"https://api.github.com/users/fabiankessler/gists{/gist_id}","starred_url":"https://api.github.com/users/fabiankessler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabiankessler/subscriptions","organizations_url":"https://api.github.com/users/fabiankessler/orgs","repos_url":"https://api.github.com/users/fabiankessler/repos","events_url":"https://api.github.com/users/fabiankessler/events{/privacy}","received_events_url":"https://api.github.com/users/fabiankessler/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/fmmfonseca/completely/labels/question","name":"question","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-07-06T12:16:51Z","updated_at":"2015-07-07T16:05:19Z","closed_at":null,"body":"There are different concepts built-in already for index lookups. It's very flexible. Some examples:\r\n\r\n* *exact match, lower case*:\r\n  using a HashMultiMap in the Index, EqualityAutomaton in the index lookup, and a LowerCaseTransformer as the Analyzer in the engine\r\n* *starts-with exact match, lower case*: \r\n  using a PatriciaTrie in the Index, EqualityAutomaton in the index lookup, and a LowerCaseTransformer as the Analyzer in the engine\r\n* *stats-with fuzzy match, lower case*: \r\n  using a PatriciaTrie in the Index, EditDistanceAutomaton in the index lookup, and a LowerCaseTransformer as the Analyzer in the engine\r\n\r\nIn my use case, with a million of indexed entries, I want to perform \"exact starts-with\" matching first. If that brings good results, fine, I take it. If not, then I go ahead and thry the \"fuzzy starts-with\" matching.\r\n\r\nFor this I currently either need 2 indexes (not an option, and technically not necessary), or some ugly syntax.\r\n\r\nThe problem is that the IndexLookupStrategy.lookup() method is not flexible. One option would be to pass in a closure how I want the lookup to be done. Then it could be controlled from the outside.\r\n\r\nMy current solution is this:\r\nCreate a PatriciaTrie instance.\r\nCreate 2 instances of IndexAdapter, give both the same trie. One uses the EqualityAutomaton and the other the EditDistanceAutomaton.\r\nCreate 2 engines, one per IndexAdapter, \r\nNow feed my data for indexing only to 1 engine.\r\nNow both engines are ready for querying.\r\n\r\nWhat do you think?\r\n"},"comment":{"url":"https://api.github.com/repos/fmmfonseca/completely/issues/comments/119250750","html_url":"https://github.com/fmmfonseca/completely/issues/4#issuecomment-119250750","issue_url":"https://api.github.com/repos/fmmfonseca/completely/issues/4","id":119250750,"user":{"login":"fabiankessler","id":2506130,"avatar_url":"https://avatars.githubusercontent.com/u/2506130?v=3","gravatar_id":"","url":"https://api.github.com/users/fabiankessler","html_url":"https://github.com/fabiankessler","followers_url":"https://api.github.com/users/fabiankessler/followers","following_url":"https://api.github.com/users/fabiankessler/following{/other_user}","gists_url":"https://api.github.com/users/fabiankessler/gists{/gist_id}","starred_url":"https://api.github.com/users/fabiankessler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fabiankessler/subscriptions","organizations_url":"https://api.github.com/users/fabiankessler/orgs","repos_url":"https://api.github.com/users/fabiankessler/repos","events_url":"https://api.github.com/users/fabiankessler/events{/privacy}","received_events_url":"https://api.github.com/users/fabiankessler/received_events","type":"User","site_admin":false},"created_at":"2015-07-07T16:05:19Z","updated_at":"2015-07-07T16:05:19Z","body":"Yes, I tried it, but for my case it was better with separate searches. I'll explain:\r\n\r\nFor short strings (like 3 chars) the approximate search finds thousands of options. My sorting is expensive (it sums up with so many). I'd need a 2 step sorting phase, to get rid of all the fuzzy matches first. And that makes no sense for my use case. It complicates it all. \r\n\r\nI got good performance and results with the 2 searches: \r\nMost of the times the first exact starts-with search is enough. It finds relatively few, sorting is fast, done. This is what most users want anyway.\r\nIf nothing \"good\" was found nothing at all, or only rare words) then it's likely that the user typed something wrong. The first search found almost nothing. Therefore it finished fast. Now I go with the fuzzy search.\r\n"}}