hunt-framework / hunt

A flexible, lightweight search platform
59 stars 10 forks source link

Remove Score from ApiDocument and Document #75

Closed chrisreu closed 10 years ago

chrisreu commented 10 years ago

ApiDocument is used to insert Documents - Document is stored in document table. Both do not really need a score assigned to them right away.

Score gets computed with a search query and thatby should be assigned to a search result. The search results JSON should stay the same though.

UweSchmidt commented 10 years ago

That's a bit problematic. The ApiDocument is not only used for reading documents but also for delivering documents in search response, (JSON Document instances are done via ApiDocument) and in that case the score disappears, but the client may be interested in the score.

chrisreu commented 10 years ago

I think Document's are returned with Results right now.

The idea is to return something like [(Score,x)] in the LimitedResult datatype for lrResult (Perhaps create a separate type instead of using Tuple) instead. Having the Score in the ApiDocument is somehow confusing. And in the Document it is not only confusing, but also wastes space, because the (unused) field is stored in the DocTable as well.

Would that be a problem for the ranking?

data CmdResult
  = ResOK
  | ResSearch       { crRes :: LimitedResult Document }
  | ResCompletion   { crWords :: [(Text, [Text])] }
  | ResGeneric      { crGen :: Value }
  deriving (Show, Eq)

data LimitedResult x = LimitedResult
    { lrResult :: [x] -- ^ The list with at most 'lrMax' elements.
    , lrOffset :: Int -- ^ The offset of the result.
    , lrMax    :: Int -- ^ The limit for the result.
    , lrCount  :: Int -- ^ The size of the complete result.
    }
    deriving (Show, Eq)
sebastian-philipp commented 10 years ago

I don't like [(Score,x)] as a result, instead we could return something like this, but also add accessor functions for the document itself:

data DocumentWithScore = DocumentWithScore {
  dwsScore ::: Score,
  dwsDocument :: Document
}

dwsDescription :: DocumentWithScore -> Description
dwsWeight :: DocumentWithScore -> Score
dwsUri :: DocumentWithScore -> Uri
chrisreu commented 10 years ago

I'd be okay with that.