Verified Commit 05998593 authored by Camil Staps's avatar Camil Staps 🙂

Early fail for bad matches of small queries (e.g. one-letter queries from the...

Early fail for bad matches of small queries (e.g. one-letter queries from the VSCode plugin) to speed up ranking
parent 12d1a74a
......@@ -392,34 +392,39 @@ where
idxs = foldr merge [] $ map (\xs->[x\\x<-:xs]) $ catMaybes $ map (flip get module_map) ss
filterName :: !String !*CloogleDB -> *CloogleDB
filterName s wrap=:{db,name_ngrams,syntax,abc_instrs}
# (indices,db) = mapSt (uncurry getIndexWithDistance) ('Data.NGramIndex'.search s name_ngrams) db
# db = 'Database.Native'.searchIndices Intersect indices db
filterName query wrap=:{db,name_ngrams,syntax,abc_instrs}
# (indices,db) = mapSt (uncurry getIndexWithDistance) ('Data.NGramIndex'.search query name_ngrams) db
# db = 'Database.Native'.searchIndices Intersect (catMaybes indices) db
# db = 'Database.Native'.searchWithIndices` syntaxSearch syntax db
# db = 'Database.Native'.searchWithIndices` abcSearch abc_instrs db
= {wrap & db=db}
where
getIndexWithDistance :: !Index !Int !*(NativeDB CloogleEntry Annotation)
-> *(!(!Index, ![Annotation]), !*NativeDB CloogleEntry Annotation)
-> *(!Maybe (!Index, ![Annotation]), !*NativeDB CloogleEntry Annotation)
getIndexWithDistance idx n db
# (e,db) = 'Database.Native'.getIndex idx db
# name = getName $ fromJust $ getLocation e.value
# rn = toReal n
# annots =
[ MatchingNGramsQuery (rn / qsize)
, MatchingNGramsResult (rn / toReal (size name))
#! (e,db) = 'Database.Native'.getIndex idx db
#! name = getName $ fromJust $ getLocation e.value
#! rn = toReal n
#! query_ratio = rn / qsize
#! result_ratio = rn / toReal (size name)
| result_ratio < 0.2 && (size query <= NGRAMS_N || query_ratio < 0.8)
/* Prevent large amount of results for small queries to speed up ranking */
= (Nothing, db)
#! annots =
[ MatchingNGramsQuery query_ratio
, MatchingNGramsResult result_ratio
]
= ((idx, annots), db)
= (Just (idx, annots), db)
cs = [c \\ c <-: s]
qsize = toReal $ max 1 $ length $ 'Data.NGramIndex'.ngrams NGRAMS_CI NGRAMS_N s
cs = [c \\ c <-: query]
qsize = toReal $ max 1 $ length $ 'Data.NGramIndex'.ngrams NGRAMS_CI NGRAMS_N query
syntaxSearch :: CloogleEntry -> (Bool, [a])
syntaxSearch (SyntaxEntry se) = (any (not o isEmpty o flip match cs) se.syntax_patterns, [])
syntaxSearch _ = (False, [])
abcSearch :: CloogleEntry -> (Bool, [a])
abcSearch (ABCInstructionEntry ie) = (ie.aie_instruction == s, [])
abcSearch (ABCInstructionEntry ie) = (ie.aie_instruction == query, [])
abcSearch _ = (False, [])
filterExactName :: !String !*CloogleDB -> *CloogleDB
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment