Skip to content
This repository has been archived by the owner on Nov 10, 2020. It is now read-only.

Commit

Permalink
fixed issues with search query
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffery Keene authored and Jeffery Keene committed Jul 1, 2019
1 parent a0f37f0 commit bdf7852
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -8,3 +8,5 @@ yarn.lock
/public
.DS_Store
_site
launch.json
.vscode
2 changes: 1 addition & 1 deletion gatsby-config.js
Expand Up @@ -102,7 +102,7 @@ let config = {
MarkdownRemark: {
title: node => node.frontmatter.title,
tags: node => node.frontmatter.tag || node.frontmatter.tags,
path: node => node.frontmatter.unique_id ? '/explore/'+state.frontmatter.unique_id+"/" : node.frontmatter.permalink,
path: node => node.frontmatter.unique_id ? '/explore/'+node.frontmatter.unique_id+"/" : node.frontmatter.permalink,
},
},
// Optional filter to limit indexed nodes
Expand Down
32 changes: 16 additions & 16 deletions src/pages/search-results/index.js
@@ -1,12 +1,11 @@
import React, {useState, useEffect} from 'react'
import React, { useState, useEffect } from 'react'
import Helmet from 'react-helmet'
import { useStaticQuery, graphql } from "gatsby"
import { Index } from "elasticlunr"
import { useStaticQuery, graphql } from 'gatsby'
import { Index } from 'elasticlunr'

import Link from '../../components/utils/temp-link'
import GlossaryTerm from '../../components/utils/glossary-term.js'


import DefaultLayout from '../../components/layouts/DefaultLayout'

const SearchResults = () => {
Expand All @@ -17,20 +16,21 @@ const SearchResults = () => {
}
}
`
)
)

const index = Index.load (data.siteSearchIndex.index)
const index = Index.load(data.siteSearchIndex.index)
let urlParams = new URLSearchParams()

if (typeof window !== 'undefined' && window) {
urlParams = new URLSearchParams(window.location.search)
}

const queryString = urlParams.get('q')
const [results, setSearchResults] = useState (index
const [results, setSearchResults] = useState(index
.search(queryString, {})
// Map over each ID and return the full document
.map(({ ref }) => index.documentStore.getDoc(ref))
)
)

return (
<DefaultLayout>
Expand All @@ -47,16 +47,16 @@ const SearchResults = () => {
<div className="container-page-wrapper ribbon ribbon-column landing-section_top">
<div className="container-left-8 ribbon-hero ribbon-hero-column">
<h1 id="introduction">Search Results</h1>
</div>
<ul>
{results &&
</div>
<ul>
{results &&
results.map((item, index) => {
return <li key={ index }>{ item.title }</li>
}
)
}
</ul>
</div>
}
)
}
</ul>
</div>
</section>
</div>
</DefaultLayout>
Expand Down

0 comments on commit bdf7852

Please sign in to comment.