Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
epicbot-hs/src/Epicbot/Data/Index/SearchEngine.hs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
59 lines (50 sloc)
1.77 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Epicbot.Data.Index.SearchEngine | |
( SearchEngine, | |
fromCards, | |
search, | |
) | |
where | |
import Data.Ix (Ix) | |
import Data.SearchEngine (NoFeatures, SearchConfig (..), SearchRankParameters (..)) | |
import qualified Data.SearchEngine as SE | |
import Data.Text (Text) | |
import qualified Data.Text as Text | |
import Epicbot.Data.Card (Card) | |
import qualified Epicbot.Data.Card as Card | |
newtype SearchEngine = SearchEngine | |
{ searchEngine :: SE.SearchEngine Card Text SearchField NoFeatures | |
} | |
data SearchField = NameField | |
deriving (Eq, Ord, Enum, Bounded, Ix, Show) | |
search :: Text -> SearchEngine -> [Text] | |
search query SearchEngine {searchEngine} = | |
SE.query searchEngine $ Text.words query | |
fromCards :: [Card] -> SearchEngine | |
fromCards cards = | |
SearchEngine $ SE.insertDocs cards $ SE.initSearchEngine searchConfig searchRankParams | |
searchConfig :: SearchConfig Card Text SearchField NoFeatures | |
searchConfig = | |
SearchConfig | |
{ documentKey = Card.externalId, | |
extractDocumentTerms = extractTerms, | |
transformQueryTerm = transformQuery, | |
documentFeatureValue = const SE.noFeatures | |
} | |
extractTerms :: Card -> SearchField -> [Text] | |
extractTerms card NameField = | |
Text.words $ Text.replace "," "" $ Text.toLower $ Card.name card | |
transformQuery :: Text -> SearchField -> Text | |
transformQuery query NameField = Text.replace "," "" $ Text.toLower query | |
searchRankParams :: SearchRankParameters SearchField NoFeatures | |
searchRankParams = | |
SearchRankParameters | |
{ paramK1 = 1.5, | |
paramB = const 1, | |
paramFieldWeights = const 1, | |
paramFeatureWeights = SE.noFeatures, | |
paramFeatureFunctions = SE.noFeatures, | |
paramResultsetSoftLimit = 200, | |
paramResultsetHardLimit = 400, | |
paramAutosuggestPrefilterLimit = 500, | |
paramAutosuggestPostfilterLimit = 500 | |
} |