Skip to content

Commit

Permalink
Merge pull request #1831 from folio-org/FOLIO-4165-search-endpoints
Browse files Browse the repository at this point in the history
FOLIO-4165 Add search-endpoints
  • Loading branch information
dcrossleyau authored Jan 20, 2025
2 parents 9033e38 + 5dfce3b commit 99775c0
Show file tree
Hide file tree
Showing 16 changed files with 282 additions and 56 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ _site
.bundle
tmp/
vendor
node_modules
package-lock.json
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ plugins:
- jekyll-gist
- jekyll-feed

exclude: [bin, CONTRIBUTING.md, README.md, tmp, work]
exclude: [bin, CONTRIBUTING.md, README.md, tmp, work, assets/js/node_modules, assets/js/package-lock.json]

collections:
faqs:
Expand Down
19 changes: 19 additions & 0 deletions _includes/column-2-search-endpoints.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

<!-- include tertiary-column.html -->
{%- comment -%}<!-- This widget separator will only show up when the tertiary column content is merged into the secondary column-->{%- endcomment %}
<div class="tertiary-widget-separator"></div>
<div>
<p>Search terms are combined with 'AND'.</p>
<p>Using <a href="https://github.com/bvaughn/js-search">js-search</a>.</p>
<p>See its <a href="https://github.com/bvaughn/js-search">assistance notes</a>.</p>
<p>
Using its "AllSubstringsIndexStrategy".
So "c", "ca", "cat", "a", "at", and "t" will all match the term "cat".
</p>
<p>
This search is constrained to the
<a href="https://github.com/folio-org/folio-org.github.io/tree/master/_data/config-api-endpoints.json">list</a>
of API documentation endpoints.
</p>
</div>
<!-- end of include tertiary-column.html -->
6 changes: 2 additions & 4 deletions _includes/column-2-search.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
<div>
<p>Search terms are combined with 'AND'.</p>
<p>Using <a href="https://github.com/bvaughn/js-search">js-search</a>.</p>
<p>See its <a href="https://github.com/bvaughn/js-search/blob/master/README.md#tokenization">assistance notes</a>.</p>
<p>See its <a href="https://github.com/bvaughn/js-search">assistance notes</a>.</p>
<p>
Using its prefix-based search.
Using its "PrefixIndexStrategy".
So term "cat" is indexed as "c", "ca", and "cat".
</p>
<p>
This search is constrained to dev.folio.org only.
See <a href="/search-other/">other search facilities</a>
for GitHub, FOLIO Wiki, etc.
</p>
<p>
A specific set of important <a href="/faqs/where-is-developer-documentation-located/">other</a> documents are also indexed.
Expand Down
10 changes: 10 additions & 0 deletions assets/js/eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import globals from "globals";
import pluginJs from "@eslint/js";


/** @type {import('eslint').Linter.Config[]} */
export default [
{files: ["**/*.js"], languageOptions: {sourceType: "script"}},
{languageOptions: { globals: globals.browser }},
pluginJs.configs.recommended,
];
11 changes: 11 additions & 0 deletions assets/js/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"license": "Apache-2.0",
"devDependencies": {
"@eslint/js": "^9.18.0",
"eslint": "^8.57.1",
"eslint-config-airbnb-base": "latest",
"eslint-config-jquery": "^3.0.2",
"eslint-plugin-import": "^2.25.2",
"globals": "^15.14.0"
}
}
96 changes: 50 additions & 46 deletions assets/js/search-dev.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,55 @@
var debug = false;
jQuery(function() {
window.data = $.getJSON('/search_data.json', function() {
if (debug) { console.log('Okay'); }
})
.done(function(searchData) {
if (debug) { console.log('Got JSON data'); }
window.idx = new JsSearch.Search('id');
window.idx.addIndex('id');
window.idx.addIndex('title');
window.idx.addIndex('content');
window.idx.addIndex('categories');
if (debug) { console.log('Processing'); }
if (debug) { console.time('Build index'); }
window.idx.addDocuments(searchData);
if (debug) { console.timeEnd('Build index'); }
var idxCount = searchData.length;
if (debug) { console.log('Ready: idx: ' + idxCount); }
JsSearch.StopWordsMap.issue = false;
JsSearch.StopWordsMap.environment = false;
})
.fail(function() {
console.log('Error with getting search data');
})
.always(function() {
if (debug) { console.log('Complete'); }
});
let idx = [];
$( (searchDev) => {
window.data = $.getJSON( "/search_data.json", () => {
if ( debug ) { console.log( "Setup okay." ); }
} )
.done( ( searchData ) => {
if ( debug ) { console.log( "Loaded JSON data." ); }
idx = new JsSearch.Search( "id" );
idx.indexStrategy = new JsSearch.PrefixIndexStrategy();
idx.addIndex( "title" );
idx.addIndex( "content" );
idx.addIndex( "categories" );
if ( debug ) { console.log( "Processing ..." ); }
if ( debug ) { console.time( "Build index" ); }
idx.addDocuments( searchData );
if ( debug ) { console.timeEnd( "Build index" ); }
const idxCount = searchData.length;
if ( debug ) { console.log( `Ready: idx: ${ idxCount } items` ); }
JsSearch.StopWordsMap.issue = false;
JsSearch.StopWordsMap.environment = false;
} )
.fail( () => {
console.log( "Error with getting search data." );
} )
.always( () => {
if ( debug ) { console.log( "Complete." ); }
} );

$('#searchDev').submit(function(event) {
event.preventDefault();
var query = $('#searchInput').val();
if (debug) { console.log('Query: ' + query); }
var results = window.idx.search(query);
displayResults(results);
});

function displayResults(results) {
var $searchResults = $('#searchResults');
if (debug) { console.log('Hits: ' + results.length); }
if (results.length) {
$searchResults.empty();
results.forEach(function(result) {
if (debug) { console.log('Result: ' + result.url); }
var appendString = '<li><a href="' + result.url + '">' + result.title + '</a></li>';
$searchResults.append(appendString);
});
function displayResults( results ) {
const searchResults = $( "#searchResults" );
const hits = $( "#hits" );
if ( debug ) { console.log( `Hits: ${ results.length }` ); }
if ( results.length ) {
searchResults.empty();
hits.html( `Hits: ${ results.length }` );
results.forEach( ( result ) => {
if ( debug ) { console.log( `Result: ${ result.url }` ); }
const appendString = `<li><a href="${ result.url }">${ result.title }</a></li>`;
searchResults.append(appendString);
} );
} else {
$searchResults.html('<li>No results found.</li>');
hits.html( `Hits: 0` );
searchResults.html( "<li>No results found.</li>" );
}
}
});

$( "#searchDev" ).submit( ( event ) => {
event.preventDefault();
const query = $( "#searchInput" ).val();
if ( debug ) { console.log( `Query: ${ query }` ); }
const results = idx.search( query );
displayResults( results );
} );
} );
95 changes: 95 additions & 0 deletions assets/js/search-endpoints.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const debug = true;
let idx = [];
$( (searchEndpoints) => {
window.data = $.getJSON( "/search_endpoints.json", () => {
if ( debug ) { console.log( "Setup okay." ); }
} )
.done( ( searchData ) => {
if ( debug ) { console.log( "Loaded JSON data." ); }
idx = new JsSearch.Search( "id" );
idx.indexStrategy = new JsSearch.AllSubstringsIndexStrategy();
idx.addIndex( "id" );
idx.addIndex( "moduleName" );
idx.addIndex( "path" );
idx.addIndex( "interface" );
idx.addIndex( "methods" );
idx.addIndex( "apiDescription" );
idx.addIndex( "apiType" );
if ( debug ) { console.log( "Processing ..." ); }
if ( debug ) { console.time( "Build index" ); }
idx.addDocuments( searchData );
if ( debug ) { console.timeEnd( "Build index" ); }
const idxCount = searchData.length;
if ( debug ) { console.log( `Ready: idx: ${ idxCount } items` ); }
JsSearch.StopWordsMap.issue = false;
JsSearch.StopWordsMap.environment = false;
} )
.fail( () => {
console.log( "Error with getting search data." );
} )
.always( () => {
if ( debug ) { console.log( "Complete." ); }
} );

function displayResults( results ) {
const searchResults = $( "#searchResults" );
const hits = $( "#hits" );
const urlRepoBase = "https://github.com/folio-org/";
const urlS3Base = "https://s3.amazonaws.com/foliodocs/api/";
if ( debug ) { console.log( `Hits: ${ results.length }` ); }
if ( results.length ) {
searchResults.empty();
hits.html( `Hits: ${ results.length }` );
results.forEach( ( result ) => {
if ( debug ) { console.log( `Result: ${ result.path }` ); }
const urlRepo = `${ urlRepoBase }${ result.moduleName }`;
const urlS3Repo = `${ urlS3Base }${ result.moduleName }`;
const apath = result.apiDescription;
const filenameDoc = apath.substring( apath.lastIndexOf( "/" ) + 1 );
const basenameDoc = filenameDoc.replace( /\.[^/.]+$/, "" );
const urlApiDesc = `${ urlRepo }/blob/master/${ result.apiDescription }`;
const methods = result.methods.split( " " );
let methodsList = "";
methods.forEach( ( method ) => {
const opParts = method.split( ":" );
let nullNote = "";
if ( opParts[ 1 ] === "null" ) {
nullNote = " (missing operationId)"
}
let urlS3 = `${ urlS3Repo }/`;
if ( result.apiType === "RAML" ) {
urlS3 += "p/";
}
urlS3 += `${ basenameDoc }.html#${ opParts[ 1 ] }`;
methodsList += `<li><a href="${ urlS3 }">${ opParts[ 0 ] }</a> ${nullNote}</li>`;
} );
const appendString = `
<li> ${ result.path }
<ul>
<li>module: <a href="${ urlRepo }">${ result.moduleName }</a></li>
<li>interface: ${ result.interface } </li>
<li>path: ${ result.path } </li>
<li>methods:
<ul>${ methodsList }</ul>
</li>
<li>api description: <a href="${ urlApiDesc }">${ result.apiDescription }</a></li>
<li>api type: ${ result.apiType } </li>
</ul>
</li>
`;
searchResults.append( appendString );
} );
} else {
hits.html( `Hits: 0` );
searchResults.html( "<li>No results found.</li>" );
}
}

$( "#searchEndpoints" ).submit( ( event ) => {
event.preventDefault();
const query = $( "#searchInput" ).val();
if ( debug ) { console.log( `Query: ${ query }` ); }
const results = idx.search( query );
displayResults( results );
} );
} );
4 changes: 2 additions & 2 deletions reference/api/endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ menuSubIndex: 3

This API documentation is automatically [generated](#gathered-lists) from each repository's API description files.

Use the web browser "Find in page" facility.
Use the web browser "Find in page" facility to locate items in this table. Also [search endpoints](/search-endpoints/).

Each link in the "API documentation" column goes directly to the relevant entry in the tables of the [API documentation](/reference/api/).
Each link in the "Methods" column goes directly to that section of the relevant API documentation.
Expand Down Expand Up @@ -119,7 +119,7 @@ $("[data-column]").on("click", function () {
The list of endpoints (also known as "entry-points") is gathered and published during the CI [generation](/reference/api/#generated-during-ci) of each module's API documentation, when there is a merge to their mainline branch.
A daily Workflow [assembles](/reference/api/#explain-gather-config) the published lists of endpoints.

### Some missing links
### Some missing method links

For some OpenAPI-based modules, there might be missing links in the "Methods" column.
That is because their API description has omitted the "`operationId`" property for that method.
Expand Down
2 changes: 1 addition & 1 deletion reference/glossary.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ permalink: /reference/glossary/
menuInclude: yes
menuTopTitle: Reference
menuSubTitle: Glossary
menuSubIndex: 5
menuSubIndex: 6
---

FOLIO is a new open source, cloud hostable, app-store based library platform,
Expand Down
10 changes: 9 additions & 1 deletion reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@ menuTopIndex: 3
menuSubTitle: Reference introduction
menuSubIndex: 1
menuSubs:
- title: Search API endpoints
url: /search-endpoints/
index: 4
- title: Reference environments
url: /guides/automation/
anchorId: reference-environments
index: 4
index: 5
---

Standards and reference documentation.

- The set of automatically generated [API documentation](/reference/api/) and list of [endpoints](/reference/api/endpoints/).
- The [reference environments](/guides/automation/#reference-environments) resulting from the continuous integration automated [builds](/guides/automation/#software-build-pipeline).
- A [FOLIO glossary](/reference/glossary/) of some terms and technologies used in FOLIO.

## Search facilities

* [API documentation endpoints](/search-endpoints/)

50 changes: 50 additions & 0 deletions search-endpoints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
layout: page
title: Search API endpoints
titleLeader: "Search |"
permalink: /search-endpoints/
menuInclude: yes
menuLink: yes
menuTopTitle: Search
menuSubTitle: "Search API endpoints"
menuSubIndex: 3
tertiary-column: present
tertiary-column-content: column-2-search-endpoints.html
---

<div class="form">
<form action="get" id="searchEndpoints">
<input type="text" size="25" id="searchInput" autofocus>
<input type="submit" value="Search">
</form>
</div>

<div id="hits"></div>

<ul id="searchResults"></ul>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/js-search.min.js"></script>
<script src="/assets/js/search-endpoints.js"></script>

## Other information

### Some missing method links

As [explained](/reference/api/endpoints/#some-missing-method-links) at the Endpoints documentation, a small set of OpenAPI-based modules are missing links for the "Methods".
These will be marked in the search results with "(missing operationId)".

Some of these are unimplemented "stub" endpoints (do a search for "stub" to find them).

Others are actual endpoints, but their API description has omitted the "operationId" property for that method.

### Interfaces

Some "interface" properties might be missing. See the [explanation](/reference/api/endpoints/#interfaces) at the Endpoints documentation.

### Other documentation

* [API documentation](/reference/api/)
* [API documentation endpoints](/reference/api/endpoints/)

<div class="folio-spacer-content"></div>

2 changes: 1 addition & 1 deletion search-other.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ menuInclude: yes
menuLink: yes
menuTopTitle: Search
menuTopIndex: 100
menuSubTitle: "Search other"
menuSubTitle: "Search other places"
menuSubIndex: 2
menuSubs:
-
Expand Down
Loading

0 comments on commit 99775c0

Please sign in to comment.