packages feed

bloodhound-0.22.0.0: src/X.hs

{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeApplications #-}

module X where

import Control.Monad (forM_)
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import GHC.Generics

-- type family X :: k0 -> '[k1] where
--   X V1 = '[]
--   X U1 = '[]
--   X (Par1 p) = '[]
--   X (Rec1 p) = '[]
--   X (K1 R c) = '[c]
--   X (K1 i c) = X c
--   X (M1 i c f) = X f
--   X (f :+: g) =

main :: IO ()
main = do
  let depsOf x = Map.findWithDefault mempty x direct
      transitiveDependencies :: String -> Set.Set String
      transitiveDependencies x = go (Set.singleton x) mempty
      go :: Set.Set String -> Set.Set String -> Set.Set String
      go queue walked =
        case Set.maxView queue of
          Nothing ->
            walked
          Just (x, xs)
            | Set.member x walked -> go xs walked
          Just (x, xs) ->
            go (depsOf x `Set.union` xs) (Set.insert x walked)
      queryDeps :: Map.Map String (Set.Set String)
      queryDeps = Map.fromSet transitiveDependencies $ depsOf "Query"
      queryNoRecDeps :: Map.Map String (Set.Set String)
      queryNoRecDeps = Map.filter (not . Set.member "Query") queryDeps
      countDeps = Set.size . Set.unions . Map.elems
      commons = Set.unions [Set.intersection xs ys | (x, xs) <- Map.toList queryNoRecDeps, (y, ys) <- Map.toList queryNoRecDeps, x /= y]
      queryNoRecDepsNoCommons = Map.filter (not . Set.null) $ (Set.\\ commons) <$> queryNoRecDeps
      dropQuery s =
        case s of
          "" -> ""
          "Query" -> ""
          (x : xs) -> x : dropQuery xs

  forM_ (Map.toList queryNoRecDepsNoCommons) $ \(k, ds) -> putStrLn $ k <> " -> " <> show (Set.toList ds)
  print ("total", countDeps queryDeps)
  print ("extractable", countDeps queryNoRecDeps)
  print ("commons", Set.size commons, Set.toList commons)

-- forM_ (Map.toList queryNoRecDepsNoCommons) $ \(k, ds) -> putStrLn $ "Database.Bloodhound.Internal.Versions.Common.Types.Query." <> dropQuery k

direct :: Map.Map String (Set.Set String)
direct =
  Map.fromList
    [ ("Query", Set.fromList ["Term", "MatchQuery", "MultiMatchQuery", "BoolQuery", "BoostingQuery", "CommonTermsQuery", "Query", "Boost", "FunctionScoreQuery", "DisMaxQuery", "FuzzyLikeThisQuery", "FuzzyLikeFieldQuery", "FuzzyQuery", "HasChildQuery", "HasParentQuery", "IndicesQuery", "MoreLikeThisQuery", "MoreLikeThisFieldQuery", "NestedQuery", "PrefixQuery", "QueryStringQuery", "SimpleQueryStringQuery", "RangeQuery", "RegexpQuery", "WildcardQuery"]),
      ("MatchQuery", Set.fromList ["QueryString", "BooleanOperator", "ZeroTermsQuery", "CutoffFrequency", "MatchQueryType", "Analyzer", "MaxExpansions", "Lenient", "Boost", "Fuzziness"]),
      ("MultiMatchQuery", Set.fromList ["QueryString", "BooleanOperator", "ZeroTermsQuery", "Tiebreaker", "MultiMatchQueryType", "CutoffFrequency", "Analyzer", "MaxExpansions", "Lenient"]),
      ("BoolQuery", Set.fromList ["Query", "Filter", "MinimumMatch", "Boost", "DisableCoord"]),
      ("BoostingQuery", Set.fromList ["Boost", "Query"]),
      ("CommonTermsQuery", Set.fromList ["QueryString", "CutoffFrequency", "BooleanOperator", "BooleanOperator", "CommonMinimumMatch", "Boost", "Analyzer", "DisableCoord"]),
      ("FunctionScoreQuery", Set.fromList ["FunctionScoreFunctions", "Query", "Boost", "Boost", "BoostMode", "Double", "ScoreMode"]),
      ("DisMaxQuery", Set.fromList ["Boost", "Tiebreaker", "Query"]),
      ("FuzzyLikeThisQuery", Set.fromList ["MaxQueryTerms", "IgnoreTermFrequency", "Fuzziness", "PrefixLength", "Boost", "Analyzer"]),
      ("FuzzyLikeFieldQuery", Set.fromList ["MaxQueryTerms", "IgnoreTermFrequency", "Fuzziness", "PrefixLength", "Boost", "Analyzer"]),
      ("FuzzyQuery", Set.fromList ["PrefixLength", "MaxExpansions", "Fuzziness", "Boost"]),
      ("HasChildQuery", Set.fromList ["RelationName", "Query", "ScoreType", "IgnoreUnmapped", "MinChildren", "MaxChildren"]),
      ("HasParentQuery", Set.fromList ["RelationName", "Query", "AggregateParentScore", "IgnoreUnmapped"]),
      ("IndicesQuery", Set.fromList ["Query", "IndexName"]),
      ("MoreLikeThisQuery", Set.fromList ["PercentMatch", "MinimumTermFrequency", "MaxQueryTerms", "StopWord", "MinDocFrequency", "MaxDocFrequency", "MinWordLength", "MaxWordLength", "BoostTerms", "Boost", "Analyzer"]),
      ("MoreLikeThisFieldQuery", Set.fromList ["PercentMatch", "MinimumTermFrequency", "MaxQueryTerms", "StopWord", "MinDocFrequency", "MaxDocFrequency", "MinWordLength", "MaxWordLength", "BoostTerms", "Boost", "Analyzer"]),
      ("NestedQuery", Set.fromList ["QueryPath", "ScoreType", "Query", "InnerHits"]),
      ("PrefixQuery", Set.fromList ["Boost"]),
      ("QueryStringQuery", Set.fromList ["QueryString", "BooleanOperator", "Analyzer", "AllowLeadingWildcard", "LowercaseExpanded", "EnablePositionIncrements", "MaxExpansions", "Fuzziness", "PrefixLength", "PhraseSlop", "Boost", "AnalyzeWildcard", "GeneratePhraseQueries", "MinimumMatch", "Lenient", "Locale"]),
      ("SimpleQueryStringQuery", Set.fromList ["QueryString", "FieldOrFields", "BooleanOperator", "Analyzer", "SimpleQueryFlag", "LowercaseExpanded", "Locale"]),
      ("RangeQuery", Set.fromList ["RangeValue", "Boost"]),
      ("RegexpQuery", Set.fromList ["Regexp", "RegexpFlags", "Boost"]),
      ("WildcardQuery", Set.fromList ["Boost"]),
      ("CommonMinimumMatch", Set.fromList ["MinimumMatchHighLow", "MinimumMatch"]),
      ("Filter", Set.fromList ["Query"]),
      ("FunctionScoreFunctions", Set.fromList ["FunctionScoreFunction", "ComponentFunctionScoreFunction"]),
      ("FunctionScoreFunction", Set.fromList ["Script", "Seed", "FieldValueFactor"]),
      ("RangeValue", Set.fromList ["LessThanEqD", "LessThanD", "GreaterThanEqD", "GreaterThanD", "LessThanEq", "LessThan", "GreaterThanEq", "GreaterThan"]),
      ("MinimumMatchHighLow", Set.fromList ["MinimumMatch"]),
      ("FieldValueFactor", Set.fromList ["Factor", "FactorModifier", "FactorMissingFieldValue"]),
      ("ComponentFunctionScoreFunction", Set.fromList ["Filter", "FunctionScoreFunction", "Weight"])
    ]