ndmitchell / hoogle

Haskell API search engine
http://hoogle.haskell.org/
Other
738 stars 134 forks source link

Difficult to use custom database path for search #122

Open bjornfor opened 9 years ago

bjornfor commented 9 years ago

(Haskell + hoogle newbie here, please be aware!)

What I wanted: Download hoogle database for offline use.

What I tried: Generate database (worked fine, the --datadir option was documented in hoogle data --help):

hoogle data --datadir=$HOME/.hoogle-datadir

Search, using my --datadir (didn't work):

$ hoogle --datadir=$HOME/.hoogle-datadir map
Unknown flag: --datadir

Uh oh, why doesn't it understand --datadir now?

I installed hoogle with the nix package manager, so the installation directory is read-only. I need the custom datadir not just for having multiple databases on my system, but it is the only way to use the program:

$ hoogle data
hoogle: /nix/store/mdvxcf25a0gr6lrbnwv6waisanrhbc81-haskell-hoogle-4.2.41/share/x86_64-linux-ghc-7.10.1/hoogle-4.2.41/databases: createDirectory: permission denied (Read-only file system)

Workaround Because I couldn't find a way to tell hoogle to use --datadir= for searching, I made a wrapper script that uses cd $datadir && exec hoogle ....

Solution What I think should have been needed to be done. Configure datadir with one of these options:

$ echo "datadir=$HOME/.hoogle-datadir" >> ~/.hooglerc
$ export HOOGLE_DATADIR=$HOME/.hoogle-datadir
(or all commands that use the database/datadir accept the --datadir=... option)

Now search:

$ hoogle data
$ hoogle <search>
ndmitchell commented 9 years ago

So it sounds like you eventually managed to get it all working. albeit with pretty grim hacks, and this is more a request to make it better for those that come after, rather than any help for yourself?

At the moment I'm actively developing Hoogle 5, which I hope to be much easier and faster. It doesn't yet work locally, but it's set up so it should be able to do so. I was going to put database in the app data directory (~/.hoogle on Linux) which is writeable, and should then mean the defaults "just work" for you. Does that seem reasonable?

bjornfor commented 9 years ago

Yes, I have something working now. I just think it could/should be easier (e.g. if echo "datadir=$HOME/.hoogle-datadir" >> ~/.hooglerc was a real option), for me and for others :-)

(It also felt like a bug that --datadir was only supported when creating the DB but not when reading/searching the DB.)

Yes, what you say about Hoogle 5 sounds very reasonable, looking forward to it. Everything that "just work" is a big win :-)

Any idea how long until Hoogle 5 will be able to do what Hoogle 4 does now (local db search)?

ndmitchell commented 9 years ago

Hoogle 5 can already do a local DB search. Currently it's limited in that there is no real option to put the databases anywhere sane and it doesn't do type search. I hope to solve the first of those relatively easily (it's mostly a case of wiring up options everywhere), and the second I have a plan to tackle. Once that's done, I'll make Hoogle 5 the default.

ndmitchell commented 9 years ago

I've just solved the first issue, so now you should be able to get the git repo and have everything you wanted, apart from sensible type search. If you do try that, let me know how it goes for you.

bjornfor commented 9 years ago

That was quick, thanks! Building and testing now...

bjornfor commented 9 years ago

It works out of the box. Great!

$ cd hoogle
$ git pull
$ git rev-parse HEAD
776bc64937760d9bd6d112a33274922a39f191b3
$ cabal2nix --shell . > shell.nix
$ nix-build shell.nix
/nix/store/mfp9c60qa0z2wklzlcx734m8qwfgcc78-hoogle-5.0
$ ./result/bin/hoogle --version
Hoogle 5.0, http://hoogle.haskell.org/
$ ./result/bin/hoogle 
Error, database does not exist (run 'hoogle generate' first)
    Filename: /home/bfo/.hoogle/default.hoo
$ ./result/bin/hoogle generate
Starting generate
Downloading https://www.stackage.org/lts/cabal.config... 1.41s
Downloading https://raw.githubusercontent.com/haskell/haskell-platform/master/hptool/src/Releases2015.hs... 0.62s
Downloading https://hackage.haskell.org/packages/index.tar.gz... 
...
$ ./result/bin/hoogle map
map :: (a -> b) -> [a] -> [b]
map :: (a -> b) -> IntMap a -> IntMap b
map :: (Key -> Key) -> IntSet -> IntSet
map :: (a -> b) -> Map k a -> Map k b
map :: Ord b => (a -> b) -> Set a -> Set b
map :: (Word8 -> Word8) -> ByteString -> ByteString
map :: (Char -> Char) -> ByteString -> ByteString
map :: (Char -> Char) -> Text -> Text
map :: (Char -> Char) -> Stream Char -> Stream Char
map :: (a -> b) -> Vector a -> Vector b
-- plus more results not shown, pass --count=20 to see more
ndmitchell commented 9 years ago

Great news!