Skip to content

Aims to integrate Elasticsearch features into the Gollum wiki project.

License

Notifications You must be signed in to change notification settings

beporter/gollum_search

Repository files navigation

Gollum + Search

Aims to improve the Gollum wiki project's default git grep-based searching by integrating Elasticsearch features. A secondary goal is to allow for additional search services to be plugged into Gollum via this one.

⚠️ This is all very much pre-release! The current version doesn't actually do anything yet.

  • Improved relevancy of search results.
  • Ability to tune search results for specific topic domains.
  • Find-as-you-type search results.
  • Perhaps improved search performance in very large wikis(?) (Should be tested!)
  • FUTURE: Per-user search conversion tracking.
  • FUTURE: Make this project pluggable to support additional search backends.

Based on gollum/gollum#1768.

Requirements

  • An active and functional Gollum installation.
  • An available Elasticsearch v7+ server instance.
    • A Docker container is provided for development of this plugin.

Installation

Add this line to your application's Gemfile:

gem 'gollum_search', '~> LATEST_VERSION'

Then execute bundle.

Or install the gem yourself:

$ gem install gollum_search

Configuration

TODO: Explain how to active that plugin in Gollum. Hopefully just adding a line to your gollum config file.

Usage

Creating (or recreating) an index can be done from the command line using bundle exec gollum_search_reindex /path/to/your/wiki branch_name.

This plugin is implemented as Rack middleware that overrides the /gollum/search request path. This means you must run Gollum as a Rack app via config.ru and inject this plugin before Gollum.

# config.ru

# Engage the `/gollum/search` request override.
require 'gollum_search'
#use GollumSearch::Middleware

# Trigger "live" updates to the index as pages are edited.
Gollum::Hook.register(:post_commit, :update_search_index) do |committer, sha1|
  GollumSearch::Indexer.hook(committer, sha1)
end

# Monkey-patch `Gollum::Wiki.search` to use GollumSearch::Indexer.search instead.
# This is (arguably) cleaner than overriding the entire route with Sinatra middleware.
# TODO: Move this to `GollumSearch::included` to patch automatically ?
module Gollum
  class Wiki
    def search(query)
      $stderr.puts "Query = #{query}"
      GollumSearch::Indexer.search(query)
    end
  end
end

# Load and run Gollum (as normal).
require 'gollum/app'
Precious::App.set(:gollum_path, '/path/to/your/wiki/repo/dir')
Precious::App.set(:wiki_options, { your_wiki_options })
run Precious::App

This plugin uses Elasticsearch by default and therefore looks for an ELASTICSEARCH_URL to establish a connection to Elasticsearch. This can be defined in the above config.ru file, or in the runtime environment for your server. In development, this is set by the docker-compose.yml file to point to the elasticsearch Docker container.

Please check config.ru for example usage. Further documentation about launching Gollum via Rack is available in Gollum's own wiki

Contributing

Code of Conduct

Everyone interacting in the gollum_search project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Getting Help or Reporting Issues

Create an issue.

TODO: Better details.

Development

  • Create an issue to propose and discuss the contribution.
    • The authors have little time to maintain this project. Your contributions are invited, but we wish to not waste anyone's time. A quick conversation to determine alignment and fit is usually a good investment.
  • If the contribution is a good fit, clone the repo, start a topic branch, and open a pull request.

Workflow

  • Clone the repository.
  • Run docker-compose up to launch the development environment, which contains a ruby container running gollum and a test wiki, and an Elasticsearch container.
  • Visit http://localhost:4567 to check the running copy of Gollum with this plugin injected.
    • Changes to the code in this plugin should be reloaded automatically.
    • You can override the exposed port by creating a local .env file and placing GOLLUM_PORT=4568 in it.
    • You can confirm that the gollum container can reach the elasticsearch container by running docker compose run gollum bash, then curl $ELASTICSEARCH_URL/_cluster/state?pretty.
  • Visit http://localhost:9200/ to check the Elasticsearch instance.
    • You can override the exposed port by creating a local .env file and placing ELASTICSEARCH_PORT=9201 in it.
  • All normal ruby/bundler commands should be prefixed with docker compose exec gollum YOUR COMMAND HERE.

To check the local docker elasticsearch index:

Testing

It is recommended to run the test suite inside the provided Docker Compose environment.

  • docker-compose gollum bundle exec rspec - The test suite should continue to pass.
  • docker-compose gollum bundle exec rubocop - Rubocop should emit no warnings or errors.

Releasing

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Copyright & License

Copyright © 2021 Brian Porter.

This software is released under the MIT License.

TODO

  • Write a search method that returns results compatible with Wiki.search() results.
  • Figure out how to monkeypatch our search method on top of Gollum::Wiki.search: https://github.com/gollum/gollum-lib/blob/master/lib/gollum-lib/wiki.rb#L492 (This would be "easier" and less invasive than overriding the /gollum/search route.)
  • Make this plugin able to register Gollum hooks for after_commit (to write the updated page into the ES index) and Gollum::Hook.register(:post_wiki_initialize, :hook_id) (we can save a reference to that wiki instance for use), and update "installation" docs for how to do that in your own Gollum wiki.
  • Register our own sinatra routes for search-as-you-type.
  • Override the necessary Mustache templates to offer search as you type.
    • Pull in the minimum necessary Javascript to query the new route and use the results.

Refs

About

Aims to integrate Elasticsearch features into the Gollum wiki project.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published