Install Solr

Download and extract latest binary version (see Solr download page)

Launch and create taack core

cd solr-<version>
bin/solr start
bin/solr create_core -c taack
bin/solr config -c taack -p 8983 -action set-user-property -property update.autoCreateFields -value false
On a production server, port 8983 should not be reachable from outside.

Copy the file mapping-ISOLatin1Accent.txt in solr configuration dir

The file mapping-ISOLatin1Accent.txt is located in the intranet folder:

cp intranet/mapping-ISOLatin1Accent.txt solr-9.6.1/server/solr/taack/conf/mapping-ISOLatin1Accent.txt

The rest of the configuration should be made at runtime. Only this file is mandatory.

Adding objects to solr index

Indexing a domain class

In the intranet project, look at CrewSearchService.groovy

@PostConstruct
private void init() {
    taackSearchService.registerSolrSpecifier(
        this,
        new SolrSpecifier(User,
            CrewController.&showUserFromSearch as MethodClosure,    (1)
            this.&labeling as MethodClosure, { User u ->            (2)
        u ?= new User()
        indexField "User Name (without Accents)",
            SolrFieldType.TXT_NO_ACCENT, u.username_
        indexField SolrFieldType.TXT_GENERAL, u.username_
        indexField SolrFieldType.TXT_NO_ACCENT, u.firstName_
        indexField SolrFieldType.TXT_NO_ACCENT, u.lastName_
        indexField SolrFieldType.POINT_STRING, "mainSubsidiary", true, u.subsidiary?.toString()
        indexField SolrFieldType.POINT_STRING, "businessUnit", true, u.businessUnit?.toString()
        indexField SolrFieldType.DATE, 0.5f, true,  (3)
            u.dateCreated_
        indexField SolrFieldType.POINT_STRING,      (3)
            "userCreated",  // Faceting String
            0.5f,           // Boost factor
            true, u.userCreated?.username
    }))
}

You have different choices to process text:

  • POINT_STRING will not modify the string when indexing

  • TXT_NO_ACCENT will remove accents

  • …​

You can index the same field more than once.

Labeling objects found

String labeling(Long id) {
    def u = User.read(id)
    "User: ${u.firstName} ${u.lastName} ($id)"
}

Displaying the selected object

Here CrewController.&showUserFromSearch is used when clicking on the object found:

def showUserFromSearch(User u) {
    taackUiService.show(new UiBlockSpecifier().ui {
        show u.username, crewUiService.buildUserShow(u), BlockSpec.Width.MAX
    }, buildMenu())
}
private UiMenuSpecifier buildMenu(String q = null) {
    new UiMenuSpecifier().ui {
        menu CrewController.&index as MC
        menu CrewController.&listRoles as MC
        menu CrewController.&hierarchy as MC
        menuIcon ActionIcon.CONFIG_USER, this.&editUser as MC
        menuIcon ActionIcon.EXPORT_CSV, this.&downloadBinPdf as MC
        menuIcon ActionIcon.EXPORT_PDF, this.&downloadBinPdf2 as MC
        menuSearch this.&search as MethodClosure, q     (1)
        menuOptions(SupportedLanguage.fromContext())
    }
}
1 Add menuSearch entry

Search action

def search(String q) {
    taackUiService.show(crewSearchService.buildSearchBlock(q), buildMenu(q))
}
UiBlockSpecifier buildSearchBlock(String q) {
    taackSearchService.search(q, CrewController.&search as MethodClosure, User) (1)
}
1 the last parameter is a list of classes we want to target into this search block

We can have more than 1 search result block into a page.