The objective of this page is to provide some relatively short and easy-to-get-started documentation for the Synonyms module 7.x version. Unless explicitly stated otherwise, the documentation below describes the features that are available in the newest release of the mentioned module.

Within the scope of this module, a synonym is considered to be a textual (string) value that is similar (synonymous) by its meaning to the meaning of the entity, to which it belongs. Example: United States (synonyms: U.S., The U.S.), United Kingdom (synonyms: U.K.). Therefore synonyms do not exist on their own but belong to entities. There are few key concepts tightly integrated into Synonyms module that are worth knowing for the end user. They are:

Storage independency
Synonyms can be stored in various manners be it in your database or querying 3rd party API or alike. This means you can keep your synonyms in the most convenient way for you.
Synonyms behaviors
Having a list of synonyms doesn't really help much; what you want to do is something productive with them. That's where synonyms behaviors whatsoever come on stage. They are abstract self sufficient units of behavior that do something productive with synonyms. For example, here we have the autocomplete behavior, which introduces autocomplete text fields that do look up not only by entity name but by its synonyms too. Synonyms behaviors can be added through other contributed modules, you're not locked down to what Synonyms module has to offer you.
Synonyms behavior implementations
Lastly, here is yet more abstract unit. Behavior implementations bridge between existing synonyms behaviors and existing types of synonyms storage. Imagine as if you had a table, where rows are fields attached to your entities and the columns are the existing synonyms behaviors. Behavior implementations fill in the cells of this table. So, for example, for autocomplete behavior you could have entity reference field type implementation. It means that synonyms stored in entity reference fields can participate in the autocomplete functionality.

Let's cover each of these important concepts in details. But before we take off, let's stick with some simple real-world scenario example. Let's say you have a node-type sightseeing, among other fields you have created a term reference field that points to the Country vocabulary. Keep this sample in mind while reading the next paragraphs.

Storage independency

As stated above, your synonyms can be saved in different storage types. Synonyms module ships support for storing synonyms in a number of field types and entity properties, namely:

  • Text field type
  • Term reference field type
  • Entity reference field type
  • Number field type
  • Decimal field type
  • Float field type
  • Commerce product reference field type
  • Commerce price field type
  • Any entity property stored in database (as opposed to being calculated on the fly)

Other modules may extend this list by implementing synonyms behaviors for other kinds of storage. If you do see the list above insufficient for your needs, consult the advanced help of this module for details about how to implement your own storage.

Synonyms behaviors

Synonyms behaviors are some useful for the end user features that leverage the synonyms data. Synonyms module ships with the following behaviors:

  • Autocomplete: allows synonyms to participate in the synonyms friendly autocomplete functionality.
  • Select: allows synonyms to participate in the synonyms friendly selects (drop-downs).
  • Search: behavior that integrates synonyms with Search module, i.e. your nodes can be found not only by names of the terms they reference, but also by the synonyms of those terms. It also integrates with Term Search module in the same manner: when searching for terms you can also find them by their synonyms.

Similarly, as with storage independency, other modules can introduce their own behaviors. If you are interested in introducing your own behavior, refer to the advanced help of Synonyms module.

User interface

Now that you have some theoretical understanding, let's proceed to the practical part. Think through in what storage you want to keep synonyms (fields, entity properties, etc), enable necessary Synonyms submodules, add necessary fields to your entity type (if you decide to keep synonyms in fields). Then head off to Admin -> Structure -> Synonyms. On that page you will find a table of entity types for which you could enable synonyms behaviors. Pick the entity type and bundle of your interest and go to edit. You will see a table of available behaviors and storage types. Rows in that table will correspond to fields that are eligible for synonyms behaviors. The columns will represent the synonyms behaviors. Now you can enable or disable checkboxes therefore indicating what fields of the entity should participate in what behaviors. Some behaviors may expose settings, so once you enable them, you can specify those settings (for example, it could be autocomplete wording).

Search API integration

Eventually you can use synonyms in Facets and Apache Solr too.

Synonyms module exposes all synonyms of an entity as entity property called "synonyms" (duh). Therefore you can access the full list of an entity synonyms via entity meta wrappers. Through such exposure Search API module can pick them up from there and use them as any other property, on which you can build your search indexes.

For example, coming back to our example of sightseeing node: let's suppose we want to make those nodes to be "searchable" by referenced terms' synonyms via Search API. In order to achieve it, when you are creating your Search API index, include "synonyms" and (optionally) "term name" fields into the index. If you do not include "term name" into the index, you will be able to find content only by synonyms, but not by the term name.

Views contextual filter

All enabled behaviors also participate in the synonyms friendly contextual filter. If you set up a contextual filter on term name it is possible to configure things so, that actual argument will be not a term's name, but one of its synonyms. So you can have paths for your view like this path/to/view/[synonym] instead of path/to/view/[term-name]. At the moment such functionality is only implemented for taxonomy terms and not the rest of entity types.

This could be handy if term names are long and clumsy in your case and you do not want to have them in your URL. You could add a text field to your vocabulary and enable any synonyms behavior for it, then you'd place some short synonym names into that field for each term. Here is a step by step instruction on how to do it:

  1. Add contextual filter "term ID" (preferred) or "term name"
  2. Enable validation for input argument (check "Specify validation criteria" checkbox)
  3. Set validator to be Taxonomy Term
  4. Set Filter value type to Term name or synonym converted to Term ID or to Term name or synonym depending on what you have chosen in step 1
  5. Adjust other options to your needs
  6. Save it

After saving, if you try to access path path/to/view/[synonym] your View should act like it is filtering on the taxonomy term, synonym of which you have entered in the URL. Usage of "term ID" is preferred over "term name" because it will boil down to comparing numbers to numbers (term IDs) rather than comparing strings to strings (term names). Number comparison is faster than string comparison in any database.

Feeds Tamper

When you import data into your Drupal from external source via Feeds, you can take advantage of the synonyms machinery. Often, the external source will refer to some entity with a different name than how we have that entity labelled in our Drupal. That's frustrating as you are left with manually pre-editing the external source or renaming entities in your Drupal database.

However, with Synonyms there's a more elegant solution to it - you can use the "Synonyms-friendly entity look up" Feeds tamper to handle the discrepancy in name automatically. All you have to do is to make sure your entities have their corresponding labels from the external source as a synonym. Then during import the tamper plugin will look up entities taking into consideration their synonyms. Configuring synonyms-friendly entity look up plugin is rather easy: just specify the entity type and optionally the bundle of the entity being looked up. In our example, if you are mapping a country by its name, then specify "taxonomy term" entity type and "countries" bundle in the tamper settings.

Panels argument

All synonyms behaviors also participate in Panels argument. Similarly as with Views contextual filters, you can set up your panels so that they can be accessed through its synonym in the path. Again, currently this feature is available exclusively for taxonomy term entity type.

Autocomplete behavior

This behavior allows the field values to participate in autocomplete functionality. When you enable autocomplete behavior, as a setting for it you can supply specific wording for the autocomplete entry. For example, you could have 2 different fields attached to your entity: "Typos" and "Other spellings". Then for the Typos autocomplete your wording can be "@synonym is a common typo of @entity", whereas for Other spellings a better wording would be: "@synonym; @field_name: @entity". An extra tip for the wording: if you have prices stored in any number field, you could enable it for autocomplete and make its wording: "$@synonym is the price of @entity". This would result into: "$100 is the price of Something" when user tries to enter a price into the autocomplete field.

This autocomplete behavior is available through:

  • Taxonomy term reference synonyms-friendly autocomplete widget
  • Entity reference synonyms-friendly autocomplete widget
  • Commerce product reference synonyms-friendly autocomplete widget
  • Views taxonomy term reference autocomplete filter
  • Views entity reference autocomplete filter

For your "sightseeing" node type you have added term reference field. You can choose Synonyms-friendly autocomplete as widget for the taxonomy term reference and then if you go to create a new sightseeing-node and when you start typing in a name of your country in the suggestion text field, you see magic of Synonyms module to happen. If you typed "U.K" the suggestion you would get "U.K. synonym of United Kingdom". Isn't it handy? No matter how your website visitors want to name your country, as long as you have those names added to your term as synonyms, you are covered!

The autocomplete widget has some additional settings worth to be discussed here:

  • Allow auto-creation?: [only available in taxonomy term reference widget] do you want your users to allow creating new terms "on the fly"?
  • Suggestions Size: at most how many entries to show in the suggestion list, when a user is typing in his term
  • Suggest only one entry per entity... this one is a little difficult to explain. I hope not to touch noone's feelings with my example. Let's say some of your users want to name United Kingdom as such, while others will not stand it this way and demand it to be called "Britain". First of all you create a "United Kingdom" term, add a synonym "Britain" to it. Now, if you tick that checkbox, only one suggestion will be shown for "United Kingdom" term, shall it be "United Kingdom" or "Britain". This is not what you are looking for, because some people are looking for "Britain", while your website shows them only "United Kingdom". So uncheck this setting, and then multiple suggestions will be shown per single entity, i.e. your suggestion may contain both "United Kingdom" and "Britain", which is the desired behavior in our example.

Autocomplete in Views filters

The same autocomplete functionality can be utilized within views filters. Set up a filter on the "Country" field (or any other term/entity reference field) and choose synonyms friendly autocomplete type for the filter. The filter will take the form of the same autocomplete text field as what we've discussed a few lines above. Unlikely you'll have any benefit from a non-exposed filter, but if you make it exposed, users of your view can filter the view in a more user-friendly way.

Select behavior

This behavior enables participation of field values in synonyms friendly selects, such selects that include not only entity names but also their synonyms. This behavior also supports custom wording. The default for it is to output an entry as "@synonym", which is quite reasonable, but you can supply your own wording if your use case needs something else.

Such synonyms-friendly selects are found in:

  • Taxonomy term reference synonyms-friendly select widget
  • Entity reference synonyms-friendly select widget
  • Commerce product reference synonyms-friendly select widget
  • Views taxonomy term reference select filter
  • Views entity reference select filter

For example, let's change the widget for our "Country" term reference field to "synonyms friendly select". This widget also has its own settings:

  • Sort: [only available in taxonomy term reference widget] it dictates the sorting logic. We give you 2 options here to choose from:
    • As in taxonomy vocabulary (by weight): will sort the terms as they are sorted in your taxonomy vocabulary and then will put synonyms right after the term name itself.
    • By name of terms and their synonyms: will sort the terms and their synonyms alphabetically within their parents.

Just simple synonyms friendly select is already useful for some audience of this module, but probably the most benefit of it can be achieved if combined with Chosen module.

Search behavior

Lastly, there is search integration behavior provided by Synonyms Search submodule. It was made a submodule, because this one requires core Search module enabled.

This one allows your nodes to be found by synonyms of the terms they reference. In our example of the sightseeing and countries, if you created a "Big Ben" sightseeing node and referenced United Kingdom in its Country field, then if users search for "U.K." in the search, they will find the "Big Ben" node (given, of course, "U.K." happens to be a synonym of United Kingdom term and search integration for that field is enabled in the Country vocabulary).

Search integration is smart enough to recognize node's taxonomy terms whether they are referenced through taxonomy term reference field type or entity reference.

Term search integration

Synonyms Search submodule also integrates with Term Search. That way your users can find terms when searching for their synonyms. The logic is entirely the same as I explained it in the previous paragraph, just that terms are the scope of search instead of nodes.

Comments

Yasmina7575’s picture

Hi,
I have created a field with a Synonym widget and it works very well to tag a node. Thanks for the documentation ! It is very useful ! But this way the node will be tagged only by the "right" term and never by the synonym.
My concern is to create a View which allows to search with the synonym terms. How can I do that ?
For example, if I type Britain I want the nodes tagged by United Kingdom to be displayed, but it doesn't work. It displayed nothing because the node has been automatically tagged with the "right" term.
Thanks

bucefal91’s picture

Hi,

Looking wide, the problem is that some people use Synonyms module for one kind of purposes, and others for another. If you want to keep to minimum amount of terms in your vocabulary, you will create many synonyms to each term you want to keep. Your use-case more looks like you want to have "related" terms, when both exist in the vocabulary, and when whenever one is attached to a node, basically it means another one is also attached to that node. That's the problem, these 2 tasks are different, and you can't really accomplish it using the same module. Mostly Synonyms module aims at the #1. But here's what I can suggest you...

Unfortunately still on you node-view page the term is gonna be saying "United Kingdom" (or whichever you chose to be the term and not the synonym), but your problem with views can be overcome. Please, try this patch #2062751: Synonyms for Views Contextual Filters based on taxonomy name/ID. I believe it is in working conditions and it does exactly what you ask with a view. It fetches argument, searches a term whose synonym is the value of argument, and sticks to that term. That way if Britain is a synonym for United Kingdom, when you type "Britain" Synonyms will pull up "United Kingdom" term and your view will show you a bunch of nodes that are assigned to United Kingdom.

I was waiting for someone to test that patch besides myself, and if you report it working for you - I will be happy to commit it into the module's repository and soon I am hoping to tag a new version of Synonyms module where it will be included.

http://takearest.ru - my Drupal baby :)

Yasmina7575’s picture

Hi,
Thank you very much to take time to answer me. It is really appreciated. The thing is I am not a developer. Could you tell me please how I can use your patch ?
Thanks

bucefal91’s picture

I sent you a private message. Hopefully I'll be able to assist.

http://takearest.ru - my Drupal baby :)

johnreytanquinco’s picture

Hello, thanks for this documentation. But how can I store or connect the synonyms to taxonomy vocabulary terms I created and then display it in views whenever I want to search either the term or its synonyms.

Like if I have 3 listed terms under Taxonomy A and I want each to have synonyms.

Thanks!

zied.ellouze’s picture

Hello,

Please, have you found a solution?

Thanks

jentre’s picture

Sorry for the late response, but I am now just looking at this module. It looks like you are going to need to write some code, see function synonyms_add_entity_as_synonym in synonyms.module.

alkaseram’s picture

Anyone knows where can I find a practical tutorial on using this module?

jandewit6’s picture