How to use SOLR in OpenCms

How to use SOLR in OpenCms

To set a new language for SOLR you have to configure de analyzer for the new locale. But first check if you acredit for the local here Lucene Analyzer. Then you have to configure the SOLR file of the OpenCms, how to /WEB-INF/config/opencms-search.xml , in the next section you have to set the new languge and the class for the analyzer:

<analyzers>
.
.
.
<analyzer>
<class>org.apache.lucene.analysis.es.SpanishAnalyzer</class>
<locale>es</locale>
</analyzer>
</analyzers>

To set the class is just for a best match with the words, also you can use a snowballanalyser for the accents. After the changes save and restart your server.

Now return to the workplace to set a new index for your locale, to this we have to:

  1. Go to Administration View> Search Managment>New Index
  2. Fill fields
    1. Name
    2. Rebuild mode: 
      1. auto: this will be automatic after you publish some elements.
      2. manual: this will be a manual reconstruction.
      3. offline: this will be used just for the offline elements.
  3. Locale: The language of the elements
  4. Project
    1. online: just for elements online
    2. offline: just for elements offline
  5. Field Configuration:
    1. Standar: text
    2. gallery fields
      1. Image
      2. HTML
      3. Table
      4. Download
Now you have to set a new index source or just set a previously one, to set a new one we have to:
  1. go to Administration View > Search Management > New Index Source
  2. Set a name
  3. ok
  4. click in your new index
  5. Click on "Assign document types".
    1. Select the documents you want to be indexed.  
  6. Click on "Assign resources".
  7. Set the resources you want be indexed
Now we have the index and the index source, but they aren't binding we have to set the source in the new index. We have to:

  1. click in the index you create
  2. Click in "Assign index source"
  3. Add your index source
  4. Remove the index source by default
  5. Return to the "Search Management"
  6. Select the rebuild button of your index
  7. Wait for the rebuild finish

Now you have to test if you get the correct search, ( See also 16.2.2.1 Send a REST-like query on OpenCms v9.0.1)  for this we will use the next uri
  • http://localhost:8080/opencms/opencms/handleSolrSelect?fq=con_locales:es
This will returns the result to the local Specified, we also can specified the elements, date, text, category or for a custom field.

But this just work for the element List, to set a SOLR Index we have to:
  1. go to /WEB-INF/opencms-search.xml
  2. Find <index> with the <name> Solr Online and copy it
  3. Rename it
  4. Change de locale for yours
  5. Change your index source for yours in the section <sources><source>solr_fields</source></sources>
  6. Save
  7. Restart the server
  8. Rebuild the index
Now we can test the core with this url:
  • http://localhost:8080/handleSolrSelect?fq=con_locales:es&core=Your index

Se also 16.3.1.2 Search Index and 16.3.1.3 Search Source of the OpenCms-9.0.1 Documentation

Set a custom field with SOLR

In the schema of our element  we have to set the next 
<xsd:appinfo>
.
.
.
<searchsettings containerPageOnly="true">
<searchsetting element="Category" searchcontent="true"><solrfield targetfield="caty" sourcefield="*_s"/></searchsetting>
</searchsettings>
</xsd:appinfo>

Explanation

If we set containerPageOnly on true the index just take the page and not the uri of the element, the next section i set the field Category to be catch in the searching we have to set "searchcontent" on true. The next we have to set is a field to be match in the search, we do this with the targetfield with this field we wild used with the uri or in the element list, to configure the type of the field, we have to set the string, int...

  • To know the types of fields we have to go /WEB-INF/solr/conf/schema.xml
  • In the section <fields>
Sorry for the bad English i will update later

Comentarios

Entradas populares