Search improvements (#31)

* Update lunr to 2.3.6
* Trim whitespace from query string
* Tokenize URLs
* Remove stemmer
main
Marian Steinbach 3 years ago committed by GitHub
parent be15bd5217
commit 6ed2a4b72b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      package.json
  2. 2
      src/SitesSearch.js
  3. 12
      src/index.js
  4. 8
      yarn.lock

@ -32,7 +32,7 @@
"html-webpack-plugin": "2.29.0",
"jest": "20.0.4",
"lodash": "^4.17.11",
"lunr": "^2.3.4",
"lunr": "^2.3.6",
"merge": "1.2.1",
"object-assign": "4.1.1",
"postcss-flexbugs-fixes": "3.2.0",

@ -139,7 +139,7 @@ class SearchField extends Component {
this.setState({value: q});
if (q.length > minTermLength && q !== this.state.lastQuery) {
var searchResult = this.props.searchIndex.search(q + "*");
var searchResult = this.props.searchIndex.search(q.trim() + "*");
this.setState({
lastQuery: q,
hits: searchResult.length,

@ -62,17 +62,25 @@ class App extends React.Component {
})
}
tokenizeURL = (url) => {
return url.replace(/[:.-/]+/gi, ' ');
}
createSearchIndex = (sites) => {
var tu = this.tokenizeURL;
let searchIndex = lunr(function() {
this.pipeline.remove(lunr.stemmer)
this.searchPipeline.remove(lunr.stemmer)
this.field('url');
this.field('state');
this.field('district');
this.field('city');
for (var site of sites) {
this.add({
"id": site.input_url,
"url": [site.input_url],
"url": tu(site.input_url),
"state": site.meta.state,
"district": site.meta.district,
"city": site.meta.city,

@ -4937,10 +4937,10 @@ lru-cache@^4.0.1:
pseudomap "^1.0.2"
yallist "^2.1.2"
lunr@^2.3.4:
version "2.3.4"
resolved "https://registry.yarnpkg.com/lunr/-/lunr-2.3.4.tgz#ecc045a48a6ecd96f1bb812fff70b33731753412"
integrity sha512-o0D846XyAlPkBMVK3ZgVYrLHho3yhJHgpm0BxZT3dGdFa+tpQwdQdI4EUihsmWz8Fr3aaux4eahO9Ih7Z3e1eQ==
lunr@^2.3.6:
version "2.3.6"
resolved "https://registry.yarnpkg.com/lunr/-/lunr-2.3.6.tgz#f278beee7ffd56ad86e6e478ce02ab2b98c78dd5"
integrity sha512-swStvEyDqQ85MGpABCMBclZcLI/pBIlu8FFDtmX197+oEgKloJ67QnB+Tidh0340HmLMs39c4GrkPY3cmkXp6Q==
make-dir@^1.0.0:
version "1.3.0"

Loading…
Cancel
Save