solralfrescoalfresco-sharecmis

Switch between Solr and DB for Query Execution alfresco cmis


Using Alfresco Community - 5.0.0 version.

Tried below properties in alfresco-global.properties file:

queryConsistency=EVENTUAL then all queries are going to Solr. queryConsistency=TRANSACTIONAL then all queries are going to DB. And Default mode executes all queries from DB first then Solr in case of failure from DB.

Q1: Is there any mode by which I can query Solr first and if there are no results from Solr then query DB in one transaction?

Q2: Can we execute some queries from Solr and some from DB from JAVA side?


Solution

  • Alfresco calls this a Transactional Metadata Query, where the query can fall back to the database when Solr returns no results.

    Details on configuring this behavior can be found here, but basically queryConsistency should be set to TRANSACTIONAL_IF_POSSIBLE.

    It's important to note, especially if you're converting Lucene queries to CMIS, that certain query parameters (e.g., +PATH:) and wildcards (e.g., @docs:pageId:homepage) require Solr to function, and cannot refer to the database directly in the event of a Solr failure. You can test whether a given parameter requires Solr in Alfresco under Admin Tools / Node Browser. Run your query selecting different types; type: solr-fts-alfresco is Solr-only; type: db-afts to query Solr first and fallback to the database if Solr returns nothing.

    And to answer your second question, the second link above mentions:

    The solr.query.cmis.queryConsistency and solr.query.fts.queryConsistency properties can also be set per query on the SearchParameters and QueryOptions objects.

    So it seems you can accomplish what you want within your Java code, but I have not tried this myself. I find it most desirable, as a general rule, to hit Solr first for its performance gains then fallback to the database only if necessary. I can't think of a good case for embedding the data source selection within your business logic.