Skip to content
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## [0.0.5 - 2019-09-21]

New features:
- Render docs as markdown (#15)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "purescript-docs-search",
"version": "0.0.4",
"version": "0.0.5",
"description": "Search frontend for the documentation generated by the PureScript compiler.",
"directories": {
"test": "test"
Expand Down
14 changes: 11 additions & 3 deletions src/Docs/Search/Engine.purs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module Docs.Search.Engine where

import Docs.Search.PackageIndex (PackageIndex, PackageResult)
import Docs.Search.SearchResult (SearchResult)
import Docs.Search.TypeQuery (TypeQuery(..), parseTypeQuery)
import Docs.Search.SearchResult (SearchResult, typeOfResult)
import Docs.Search.TypeQuery (TypeQuery(..), parseTypeQuery, penalty)

import Prelude

Expand Down Expand Up @@ -95,7 +95,7 @@ query engine state input =

response <- engine.queryTypeIndex state.typeIndex typeQuery

pure { results: response.results <#> TypeResult
pure { results: sortByDistance typeQuery (response.results) <#> TypeResult
, index: state { typeIndex = response.index }
}

Expand All @@ -104,3 +104,11 @@ isValuableTypeQuery :: TypeQuery -> Maybe TypeQuery
isValuableTypeQuery (QVar _) = Nothing
isValuableTypeQuery (QConst _) = Nothing
isValuableTypeQuery other = Just other


sortByDistance
:: TypeQuery
-> Array SearchResult
-> Array SearchResult
sortByDistance typeQuery =
Array.sortWith (map (penalty typeQuery) <<< typeOfResult)
2 changes: 1 addition & 1 deletion src/Docs/Search/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ main = do
case fromMaybe defaultCommands args of
BuildIndex cfg -> IndexBuilder.run cfg
Search cfg -> Interactive.run cfg
Version -> log "0.0.4"
Version -> log "0.0.5"


getArgs :: Effect (Maybe Commands)
Expand Down
19 changes: 5 additions & 14 deletions src/Docs/Search/NodeEngine.purs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module Docs.Search.NodeEngine where

import Docs.Search.Extra (stringToList)
import Docs.Search.PackageIndex as PackageIndex
import Docs.Search.Engine (Engine, Query, Index)
import Docs.Search.SearchResult (SearchResult, typeOfResult)
import Docs.Search.TypeQuery (TypeQuery, penalty)
import Docs.Search.Engine (Engine, Query, Index, sortByDistance)
import Docs.Search.SearchResult (SearchResult)
import Docs.Search.TypeQuery (TypeQuery)

import Prelude

Expand Down Expand Up @@ -41,15 +41,6 @@ queryIndex index input =
queryTypeIndex
:: Query Identity (Array SearchResult) TypeQuery SearchResult
queryTypeIndex index typeQuery =
pure { index, results:
Array.take 100 $
sortByDistance typeQuery index
pure { index
, results: Array.take 100 $ sortByDistance typeQuery index
}


sortByDistance
:: TypeQuery
-> Array SearchResult
-> Array SearchResult
sortByDistance typeQuery =
Array.sortWith (map (penalty typeQuery) <<< typeOfResult)