As explained in the Search introduction, all indexed assets can be returned as search results. Developers can create their own assets, so your installation might have additional asset types beyond the ones included by default.
Search Bar
Users enter the search context in the search bar. Users enter search terms, hit their Enter button (or click the magnifying glass icon), and they’re taken to a search page with various search widgets deployed.
If using the Search Bar in the legacy search portlet, users see a maximized view of the search portlet displaying any results and facets that apply. See the article on configuring search pages to learn more about these options.
Entering Search Terms
Liferay’s search infrastructure supports full text search as implemented by its supported search engines (Elasticsearch and Solr).
Full text search compares all the words entered in a search query (for example, space vacation) to all the words in each index document. A search engine like Elasticsearch calculates relevance scores to ensure the best results are returned first (like a Blogs Entry titled Is a vacation in space right for you?) and lots of matching results are returned (anything with either the word vacation or space is returned).
In addition to full text search, advanced search syntax is supported. Liferay DXP relies on the underlying search engine for this behavior, so consult the Elasticsearch or Solr documentation for the details.
Matching Exact Phrases: Quoted Search
What if users want their search terms (for example, space vacation) to produce only results with the exact phrase, as typed? In a regular full text search, searching space vacation returns search results containing just the terms space and vacation, and hits containing both terms but separated by other text, as well as results with the exact phrase match. To ensure that only hits with the exact phrase are returned, enclose it in quotes: “space vacation”.
Prefix Searching
If you’re searching in a site for classical musicians, you might search for the term instrument. This search returns documents with the full word in them, but it also returns variants with instrument as the prefix. For example, results with instruments, instrumental, and instrumentation are also returned.
Another way to ensure users see results is through search suggestions.
Configuring the Search Bar
Configure the Search Bar’s behavior via its portlet configuration screen.
There are several options:
- Keywords Parameter Name
- Edit the parameter name for the keywords entered in the search. For example,
the default URL when searching for the keyword term data looks like
this:
http://localhost:8080/web/guest/search?q=data
If you change the Keywords Parameter Name to keyword it looks like this:
http://localhost:8080/web/guest/search?keyword=data
- Scope
- Choose between three options: This Site (default), Everything, and Let the User Choose. This Site means only the assets associated with the site where the search is executed are searched. Expand the scope of the search to all sites by selecting Everything. To let users choose which scope they want to search, select Let the User Choose.
Scope Parameter Name : Set the URL parameter name for the scope where the search is taking place. This parameter only appears in the URL if the scope Let the User Choose is selected. The default value is scope, so searching for the word data produces the default URL of
http://localhost:8080/web/guest/search?q=data&scope=this-site
Changing scope to target would produce this URL:
http://localhost:8080/web/guest/search?q=data&target=this-site
- Destination Page
- Provide a friendly URL to the search page. If not configured or if it points to a page that doesn’t exist, a message appears for administrators that the search bar must be configured for it to appear to users.
- Use Advanced Search Syntax
- If using Elasticsearch, enabling this allows users to enter Query String Syntax into the Search Bar. If using Solr, consult its documentation for the proper syntax.
Search Suggestions
Suggest search terms to users when their initial queries are suboptimal. Spell check settings allow administrators to configure the Search application so that if a user types a search term that doesn’t return many results (for example, a slightly misspelled werd), the user can be prompted to improve the search.
To configure the spell check settings,
-
You must first reindex the spell check indexes. Go to Control Panel → Configuration → Search, then click Execute next to Reindex all spell check indexes.
-
Add the Suggestions widget to the search page.
-
Open its configuration screen. Click the widget Options button () and select Configuration.
There are three main settings here:
- **Display “Did you mean…” if the number of search results does not meet the
- threshold.**
- Present users alternate, spell checked search queries if their search did not return a minimum number of results (50 by default).
- Display Related Queries
- If the number of search results doesn’t meet the specified threshold (50 by default), display up to a maximum number of alternative queries (10 by default).
- Add New Related Queries Based on Successful Queries
- Index a user’s search query if it produces a minimum number of results (50 by default), so it can be displayed to users as a suggestion. If the Display Related Queries setting is enabled, it’s used as a related query for similar search queries that don’t produce enough results.