Commit ee5c67be authored by Markus Opolka's avatar Markus Opolka
Browse files

Add autocomplete and fix some bugs in feature search

parent 302932aa
...@@ -177,7 +177,7 @@ app.get('/api/search/:letter?', function (req, res, next) { ...@@ -177,7 +177,7 @@ app.get('/api/search/:letter?', function (req, res, next) {
res.send(data) res.send(data)
}) })
app.get('/api/features/', function (req, res) { app.get('/api/glossary/features', function (req, res) {
// Feature Glossary // Feature Glossary
res.send(lib.glossary(loadDocuments(DIR))) res.send(lib.glossary(loadDocuments(DIR)))
}) })
...@@ -185,9 +185,10 @@ app.get('/api/features/', function (req, res) { ...@@ -185,9 +185,10 @@ app.get('/api/features/', function (req, res) {
app.get('/api/features/:letter?', function (req, res) { app.get('/api/features/:letter?', function (req, res) {
// Feature Search Endpoint with query parameters // Feature Search Endpoint with query parameters
// <feature category="diakritika" type="akut" subtype="akutstattgravis" ref="26"> // <feature category="diakritika" type="akut" subtype="akutstattgravis" ref="26">
if (!req.query.category){
res.send({}) if (!req.query) {
return next('No Query provided') res.status(400).send('No Query provided')
return
} }
let query = { let query = {
...@@ -207,6 +208,11 @@ app.get('/api/features/:letter?', function (req, res) { ...@@ -207,6 +208,11 @@ app.get('/api/features/:letter?', function (req, res) {
for (let doc of documents) { for (let doc of documents) {
let obj = loadDocument(doc) let obj = loadDocument(doc)
if (!obj) {
continue
}
if (obj.valid) { if (obj.valid) {
let results = lib.features(obj, query) let results = lib.features(obj, query)
if (results !== null) { if (results !== null) {
......
...@@ -188,12 +188,29 @@ function featureGlossary (objs) { ...@@ -188,12 +188,29 @@ function featureGlossary (objs) {
} }
} }
let featureArray = [] let categories = []
let types = []
let subtypes = []
for (let feat of featureList) { for (let feat of featureList) {
featureArray.push(featureToString(feat)) if (feat.category !== undefined) {
categories.push(feat.category)
}
if (feat.type !== undefined) {
types.push(feat.type)
}
if (feat.subtype !== undefined) {
subtypes.push(feat.subtype)
}
} }
return Array.from(new Set(featureArray)) let ret = {
categories: Array.from(new Set(categories)),
types: Array.from(new Set(types)),
subtypes: Array.from(new Set(subtypes))
}
return ret
} }
function metadataTable (objs) { function metadataTable (objs) {
......
...@@ -8,23 +8,7 @@ ...@@ -8,23 +8,7 @@
<v-flex xs12> <v-flex xs12>
<p>Features are annotated properties of each letter. They have a category, a type and a subtype. These properties are hierarchical.</p> <p>Features are annotated properties of each letter. They have a category, a type and a subtype. These properties are hierarchical.</p>
<p>With the feature search you can quickly lookup the annotated features within all categories. The search supports regular expressions and can be restricted to a single letter.</p> <p>With the feature search you can quickly lookup the annotated features within all categories. The search supports regular expressions and can be restricted to a single letter.</p>
</v-flex>
<v-flex xs12>
<v-expansion-panel>
<v-expansion-panel-content>
<div slot="header">Glossary</div>
<v-card>
<v-card-text class="grey lighten-3">
<ul>
<li v-for="feat in feature_glossary">
{{feat}}
</li>
</ul>
</v-card-text>
</v-card>
</v-expansion-panel-content>
</v-expansion-panel>
</v-flex> </v-flex>
<!-- Select Letter --> <!-- Select Letter -->
...@@ -34,34 +18,37 @@ ...@@ -34,34 +18,37 @@
v-model="selected" v-model="selected"
label="Select" label="Select"
single-line single-line
bottom
prepend-icon="local_post_office" prepend-icon="local_post_office"
></v-select> ></v-select>
</v-flex> </v-flex>
<!-- Input Fields for Search --> <!-- Input Fields for Search -->
<v-flex xs12 md3> <v-flex xs12 md3>
<v-text-field <v-autocomplete
v-model="feature_category" v-model="feature_category"
type="text" label="Category" :items="feature_categories_glossary"
@keyup.enter.native="validate"> label="Category"
</v-text-field> @keyup.enter.native="validate"
>
</v-autocomplete>
</v-flex> </v-flex>
<v-flex xs12 md3> <v-flex xs12 md3>
<v-text-field <v-autocomplete
v-model="feature_type" v-model="feature_type"
type="text" :items="feature_types_glossary"
label="Type" label="Types"
@keyup.enter.native="validate"> @keyup.enter.native="validate"
</v-text-field> >
</v-autocomplete>
</v-flex> </v-flex>
<v-flex xs12 md3> <v-flex xs12 md3>
<v-text-field <v-autocomplete
v-model="feature_subtype" v-model="feature_subtype"
type="text" :items="feature_subtypes_glossary"
label="Subtype" label="Subtypes"
@keyup.enter.native="validate"> @keyup.enter.native="validate"
</v-text-field> >
</v-autocomplete>
</v-flex> </v-flex>
<!-- Search Buttons --> <!-- Search Buttons -->
...@@ -108,7 +95,9 @@ export default { ...@@ -108,7 +95,9 @@ export default {
header: 'Feature Search', header: 'Feature Search',
invalid: false, invalid: false,
searching: false, searching: false,
feature_glossary: [], feature_categories_glossary: [],
feature_types_glossary: [],
feature_subtypes_glossary: [],
feature_category: '', feature_category: '',
feature_type: '', feature_type: '',
feature_subtype: '', feature_subtype: '',
...@@ -116,25 +105,24 @@ export default { ...@@ -116,25 +105,24 @@ export default {
letters: [ letters: [
{ text: 'All' } { text: 'All' }
], ],
selected: { text: 'All' } selected: 'All'
} }
}, },
methods: { methods: {
clear () { clear () {
// Clears the search input fields // Clears the search input fields
this.feature_category = null this.feature_category = ''
this.feature_type = null this.feature_type = ''
this.feature_subtype = null this.feature_subtype = ''
}, },
find () { find () {
// Call feature search API with parameters // Call feature search API with parameters
this.searching = true this.searching = true
let url = 'http://localhost:3000/api/features/' let url = 'http://localhost:3000/api/features/'
// TODO: this is a bit silly
// Adding the lettername to the API endpoint // Adding the lettername to the API endpoint
if (this.selected.text !== 'All') { if (this.selected !== 'All') {
url = url + this.selected.text.replace(/ /g, '_') + '/' url = url + this.selected
} }
let params = { let params = {
...@@ -173,14 +161,18 @@ export default { ...@@ -173,14 +161,18 @@ export default {
}, },
created () { created () {
// Get feature glossary // Get feature glossary
this.$http.get('http://localhost:3000/api/features').then(function (data) { this.$http.get('http://localhost:3000/api/glossary/features').then(function (data) {
this.feature_glossary = data.body this.feature_categories_glossary = data.body.categories
this.feature_types_glossary = data.body.types
this.feature_subtypes_glossary = data.body.subtypes
}) })
// Create list of all letters // Create list of all letters
this.$http.get('http://localhost:3000/api/metadata/table').then(function (data) { this.$http.get('http://localhost:3000/api/metadata/table').then(function (data) {
for (let letter of data.body) { for (let letter of data.body) {
this.letters.push({text: letter.name}) if (letter.valid) {
this.letters.push({text: letter.title})
}
} }
}) })
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment