Skip to content

Commit

Permalink
Merge pull request #8 from alyon011/Development
Browse files Browse the repository at this point in the history
Version 3.0
  • Loading branch information
AlexanderLyon authored Feb 24, 2018
2 parents 899a2da + 2843075 commit b8302f1
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 11 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 5 additions & 3 deletions Haystack.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Haystack.js
* By: Alexander Lyon
* Version 2.2
* Version 3.0
* https://github.com/alyon011/Haystack
*/

Expand All @@ -11,7 +11,7 @@
this.caseSensitive = null; // Does capitalization matter?
this.flexibility = null; // How strict or loose search matches and suggestions are
this.stemming = null; // Reduces words to a more basic form
this.exclusions = null; // Which characters are omitted from search queries
this.exclusions = null; // Which characters are ignored in search queries
this.ignoreStopWords = null; // Ignore words unimportant to query

// Default options:
Expand Down Expand Up @@ -342,7 +342,7 @@



/* Removes unimportant words from the query */
/* Removes stop words from the query */
function removeStopWords(query) {
let words = query.split(" ");
let newQuery = [];
Expand All @@ -356,6 +356,7 @@
case "on":
case "in":
case "is":
case "of":
case "and":
words[i] = undefined;
break;
Expand All @@ -373,4 +374,5 @@
}



}());
2 changes: 1 addition & 1 deletion Haystack.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Alexander Lyon

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,45 @@
# Haystack
A Lightweight search plugin for JavaScript with zero dependencies
<p align="center">
<img src="https://raw.githubusercontent.com/alyon011/Haystack/Development/assets/header.png" alt="Haystack"/>
</p>

Just provide the input form and the source data to search (as an array or object)
## Overview:

Haystack is a simple search / suggestion plugin that doesn't require any dependencies to run. Just provide a way for your users to enter their query and the source data to search (as an array or object), and Haystack will return a list of approximate matches. The lower the `flexibility` the more strict your matches will be.

## To initialize Haystack:

`const haystack = new Haystack({
```javascript
const haystack = new Haystack({
caseSensitive: false,
flexibility: 2,
stemming: false,
exclusions: /[0-9]+/g,
ignoreStopWords: true
});`
});
```

## Methods:

`haystack.search(searchTerm, source, [limit]);`
```javascript
haystack.search(searchTerm, source, [limit]);
```

Returns either an array of matches within your `flexibility` range, or `null` if there are no matches. If no limit is given, the default length of results will be 1.

```javascript
haystack.tokenize(searchTerm, [delimiter]);
```

`haystack.tokenize(searchTerm, [delimiter]);`
By default this splits on whitespaces, but you can define a custom delimiter to use instead.

## Features coming soon:

Contributions and suggestions for improvement are always welcome! Some features planned for future versions include:

- Recursive object property searching

- Improved stemming

## License

MIT
Binary file added assets/header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b8302f1

Please sign in to comment.