How to do this in Site Search

crawler

#1

We’re using crawler-based site search for our product documentation, and it works fine. However, we’d like to provide access to documentation for our previous versions, each of which is stored in a subdirectory of our docs web.

We currently have those subdirectories excluded in the crawl rules, because we don’t want searches to find results in the current And previous versions. So, for example, if you’re looking at the v2.5 docs subdirectory, your searches would return results only in the 2.5 docs, and if you’re looking at the 2.6 docs directory, your searches only look within there.

If it were free, I could just create a separate engine for each version’s subdirectory. What would be a way to do this without creating an engine per version?

Thanks in advance,
gary


#2

Hey Gary,

Great question! This is a great use case for using meta-tags and filtering. For setting the tags, you could define a custom tag for the documentation version of that page.

ex.

<meta class="swiftype" name="version" data-type="enum" content="2.5" />

Then for straight-forward, contextual based filtering, you could then modify the standard embed script based on the section of the site the end-user is searching from. Here’s a gist of that syntax: https://gist.github.com/mikeisonthenets/49767dae6d554bfa65382f0745b05a32

For more advanced filtering/implementations we recommend using our jQuery client(s): https://swiftype.com/documentation/clients


#3

Background:
We’re using swiftype in a documentation web built with Jekyll. I build
and test the web locally on my Mac; when release time comes, I upload it to
doc.splicemachine .com for customers, or to docstest.splicemachine .com for
internal use. For this effort, I’m building and working with the docstest
version.

Searches in my local version are linking to the previously-crawled
docstest engine (recrawled yesterday).

Test Goal:
I want to limit search results to only pages that have a specific value
(2.7) in the ‘buildversion’ metatag.

Method:

On docstest.splicemachine.com, add this tag to just a handful of pages:

Is on these pages on docstest.splicemachine .com:
    docstest.splicemachine .com/sqlref_statements_altertable.html
    docstest.splicemachine .com/sqlref_statements_createrole.html
    docstest.splicemachine .com/sqlref_statements_revoke.html
    docstest.splicemachine .com/tutorials_connect_cognos.html
    docstest.splicemachine .com/developers_fundamentals_triggers.html
    docstest.splicemachine .com/cmdlineref_run.html
    docstest.splicemachine .com/dbaas_cmd_initialstartup.html
    docstest.splicemachine .com/onprem_install_cloudera.html

The other 500+ pages do not contain that tag.

After adding those tags last night, I re-indexed each of those 8 pages.

In the local build (on my mac, not live on docstest), every page contains
this swiftype script:

<script type="text/javascript">
(function(w,d,t,u,n,s,e){w['SwiftypeObject']=n;w[n]=w[n]||function(){
(w[n].q=w[n].q||[]).push(arguments);};s=d.createElement(t);

e=d.getElementsByTagName(t)[0];s.async=1;s.src=u;e.parentNode.insertBefore(s,e);
})(window,document,‘script’,’//s.swiftypecdn.com/install/v2/st.js
’,’_st’);

_st('install','<docstest engine id is here>','2.0.0', {
  install: {
    hooks: {
      query_filter: function(query) {
        query.setFilterDataByDocumentTypeSlugAndFilterField('page',

‘buildversion’, { values: [ ‘2.7’], type: “and” });

        return query;
      }
    }
  }
});
</script>

According to my understanding, when I search in my local build with this
script in place, the search results should only include pages that contain
the ‘buildversion’ metatag set to value=‘2.7’.

But what I’m seeing is that the results of local searches are including all
pages. Either I’m missing something, or my understanding of what should
happen is wrong.

Can you help?