Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the build #459

Merged
merged 1 commit into from
Jan 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions Distribution/Server/Features/Search/SearchEngine.hs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ insertDoc :: (Ord key, Ix field, Bounded field, Ix feature, Bounded feature) =>
SearchEngine doc key field feature ->
SearchEngine doc key field feature
insertDoc doc se@SearchEngine{ searchConfig = SearchConfig {
documentKey,
documentKey,
extractDocumentTerms,
documentFeatureValue
}
Expand Down Expand Up @@ -279,9 +279,7 @@ rankResults se@SearchEngine{searchIndex} exactMatch queryTerms docids =
, let (dockey, doctermids, docfeatvals) = SI.lookupDocId searchIndex docid ])
where
prependExactMatch :: DocId -> [key] -> [key]
prependExactMatch docid keys = dockey : keys
where
(dockey, _, _) = SI.lookupDocId searchIndex docid
prependExactMatch docid keys = SI.lookupDocId' searchIndex docid : keys

relevanceScore :: (Ix field, Bounded field, Ix feature, Bounded feature) =>
SearchEngine doc key field feature ->
Expand Down Expand Up @@ -361,12 +359,14 @@ queryExplain se@SearchEngine{ searchIndex,
paramResultsetHardLimit
docidsets

in rankExplainResults se termids (DocIdSet.toList unrankedResults)
in ( fmap (SI.lookupDocId' searchIndex) exactMatch
, rankExplainResults se termids (DocIdSet.toList unrankedResults)
)

rankExplainResults :: (Ix field, Bounded field, Ix feature, Bounded feature) =>
SearchEngine doc key field feature ->
SearchEngine doc key field feature ->
[TermId] ->
[DocId] ->
[DocId] ->
[(BM25F.Explanation field feature Term, key)]
rankExplainResults se@SearchEngine{searchIndex} queryTerms docids =
sortBy (flip compare `on` (BM25F.overallScore . fst))
Expand All @@ -378,7 +378,7 @@ explainRelevanceScore :: (Ix field, Bounded field, Ix feature, Bounded feature)
SearchEngine doc key field feature ->
[TermId] ->
DocTermIds field ->
DocFeatVals feature ->
DocFeatVals feature ->
BM25F.Explanation field feature Term
explainRelevanceScore SearchEngine{bm25Context, searchIndex}
queryTerms doctermids docfeatvals =
Expand All @@ -403,4 +403,3 @@ noFeatures _ = error "noFeatures"

instance MemSize key => MemSize (SearchEngine doc key field feature) where
memSize SearchEngine {searchIndex} = 25 + memSize searchIndex

13 changes: 9 additions & 4 deletions Distribution/Server/Features/Search/SearchIndex.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module Distribution.Server.Features.Search.SearchIndex (
lookupTerm,
lookupTermId,
lookupDocId,
lookupDocId',
lookupDocKey,
lookupDocKeyReal,

Expand Down Expand Up @@ -170,6 +171,11 @@ lookupDocId SearchIndex{docIdMap} docid =
where
errNotFound = error $ "lookupDocId: not found " ++ show docid

lookupDocId' :: SearchIndex key field feature -> DocId -> key
lookupDocId' searchIndex docId = dockey
where
(dockey, _, _) = lookupDocId searchIndex docId

lookupDocKey :: Ord key => SearchIndex key field feature -> key -> Maybe (DocTermIds field)
lookupDocKey SearchIndex{docKeyMap, docIdMap} key =
case Map.lookup key docKeyMap of
Expand Down Expand Up @@ -223,7 +229,7 @@ getDocTermIds SearchIndex{docIdMap} docid =
-- delete indexdoc

-- | This is the representation for documents to be added to the index.
-- Documents may
-- Documents may
--
type DocTerms field = field -> [Term]
type DocFeatureValues feature = feature -> Float
Expand Down Expand Up @@ -278,7 +284,7 @@ deleteDoc key si@SearchIndex{docKeyMap}
. deleteDocEntry docid key
. deleteTermToDocIdEntries (Set.toList oldTerms) docid
$ si

| otherwise = si


Expand Down Expand Up @@ -312,7 +318,7 @@ docTermIdsTermSet si doctermids =
--

-- | Add an entry into the 'Term' to 'DocId' mapping.
insertTermToDocIdEntry :: Term -> DocId ->
insertTermToDocIdEntry :: Term -> DocId ->
SearchIndex key field feature ->
SearchIndex key field feature
insertTermToDocIdEntry term !docid si@SearchIndex{termMap, termIdMap, nextTermId} =
Expand Down Expand Up @@ -406,4 +412,3 @@ instance MemSize TermInfo where

instance MemSize key => MemSize (DocInfo key field feature) where
memSize (DocInfo a b c) = memSize3 a b c