/liferay-external-searches

An example on how to build a configurable widget to trigger external searches along with Liferay search to Elasticsearch.

Primary LanguageJavaMIT LicenseMIT

Liferay External Searches

An example on how to build a configurable widget to trigger external searches along with Liferay search to Elasticsearch.

preview

Getting Started

You can either:

  • Clone this repo
  • Run ./gradlew initBundle deploy

Or:

  • Download the modules from the release page
  • Unzip the Java 8 or 11 version.
  • Move the JARs to the deploy folder under your Liferay home.

Once the 3 modules (external-search-api, external-search-service and external-search-results-web) are deployed:

  • Go to the Liferay page where search results are displayed (default: /search)
  • Add the widget External Search Results (under the Search category)
  • Click on Configure an external search engine to be used.
  • Select an External Search Engine from the dropdown list (default options: Reddit, Stack Overflow, Wikipedia)
  • Click Save
  • If the search page is a Content Page, click Publish.

Now when you run a search in Liferay, you should see results from the search engine selected in its own widget.

You can repeat this process and add more instances of the widget External Search Results with different configurations.

Going Further

Search Options

In the configuration, you can find a textarea for Search Options. This is a list of search options to fill as a key-value pairs (one per line). The supported options are search engine dependents, so you need to refer to each external search documentation (e.g. Stack Exchange Search API).

Display Template

This widget supports Application Display Templates (ADT), also called Widget Templates.

By default, you'll find 3 templates:

If you take a look at them, you'll notice that you can have more information than the name and URL of each search result. A map of metadata can be associated with each type of search result. For example to retrieve and display the tags associated with a Stack Overflow topic.

More Searches

If you clone this repo, you can try to add more external search sources in the external-search-service module.

The process is pretty simple and straightforward:

  • Create a new class
  • Annotate with @Component
  • Add a service attribute to the @Component with the value ExternalSearch.class
  • Add a property attribute to the @Component with the value engine= followed by the same of the source
  • Extends BaseExternalSearch and implements required methods

Checkout the RedditService class as an example.

In some cases, you might want to override the search methods. For example, the WikipediaService supports localization and overriding the search methods is needed to pass the right domain prefix depending on the language.

Feedback & Contribution

Feel free to open issues if you have any question/suggestion or pull requests if you want to contribute.

License

MIT