Permalink
Browse files

Fuzzy Suche .. langsam leider

  • Loading branch information...
ronnyhartenstein committed Sep 28, 2016
1 parent 7aee336 commit c81bb31aeed0d5ec8590ef5695bc8e407e1b90d2
Showing with 18 additions and 19 deletions.
  1. +4 −3 README.md
  2. +2 −1 package.json
  3. +1 −1 src/components/Kopfzeile.js
  4. +3 −0 src/components/ListeItemDetails.js
  5. +8 −14 src/components/ReduxListe.js
View
@@ -6,6 +6,7 @@ TODOs:
- [x] React App Komponenten Liste + Kopfzeile
- [x] Redux Integration
- [x] Beispieldaten einlesen in State der Liste (JSON-Datensatz)
- [ ] Suchbegriff als State halten
- [ ] Suchbegriff zum Filtern der Liste nutzen
- [ ] Szene mit Details + Bild zum Pilz (externe URL)
- [x] Suchbegriff als State halten
- [x] Suchbegriff zum Filtern der Liste nutzen
- [x] nach Tap auf Item Details + Bild zum Pilz (externe URL)
- [ ] Bottom-Navi für Anzahl Treffer und "Neuer Eintrag"
View
@@ -6,7 +6,8 @@
"start": "node node_modules/react-native/local-cli/cli.js start"
},
"dependencies": {
"fuzzy-search": "^1.3.5",
"fuzzy": "^0.1.2",
"lodash": "^4.16.2",
"react": "15.3.1",
"react-native": "0.33.0",
"react-native-elements": "^0.5.0",
@@ -14,7 +14,7 @@ class Kopfzeile extends Component {
super(props);
}
onChange(searchterm) {
console.log("suche nach .. ", searchterm, this.props)
// console.log("suche nach .. ", searchterm, this.props)
this.props.doSearch(searchterm);
}
render() {
@@ -3,6 +3,9 @@ import { ScrollView, View, StyleSheet, Text, Image } from 'react-native'
import escapeUri from '../lib/escapeUri'
// Text: https://facebook.github.io/react-native/docs/text.html
// Image: https://facebook.github.io/react-native/docs/images.html
// Stylesheet: https://facebook.github.io/react-native/docs/stylesheet.html
class Infozeile extends Component {
render() {
@@ -3,8 +3,10 @@ import Liste from './Liste'
import { connect } from 'react-redux'
import { createSelector } from 'reselect'
import _ from 'lodash'
import fuzzy from 'fuzzy'
// Memoized Selectors -> http://redux.js.org/docs/recipes/ComputingDerivedData.html
// Memoized Selectors: http://redux.js.org/docs/recipes/ComputingDerivedData.html
// Fuzzy Search: https://github.com/mattyork/fuzzy
const getSearch = (state) => state.search
const getItems = (state) => state.items
@@ -16,19 +18,11 @@ const getVisibleItems = createSelector(
return items
} else {
const r = new RegExp(search, 'i')
return _.filter(items, itm => (
r.test(itm.name)
|| r.test(itm.lat)
|| r.test(itm.gattung)
|| r.test(itm.hut_oben)
|| r.test(itm.hut_unten)
|| r.test(itm.stiel)
|| r.test(itm.fleisch)
|| r.test(itm.vorkommen)
|| r.test(itm.zeitraum)
|| r.test(itm.bedeutung)
|| r.test(itm.merkmal)
))
const result = fuzzy.filter('bcn', items, { extract: item => (_.join(_.values(item), ' ')) })
const indexes = _.map(result, res => (res.index))
const founded = _.filter(items, (itm, idx) => _.indexOf(indexes, idx) !== -1)
console.log(indexes.length, "found", founded)
return founded
}
}
)

0 comments on commit c81bb31

Please sign in to comment.