Permalink
Browse files

adding search facility, and improving submit form. still some functio…

…nality to add though. should still work as previously, just setting some foundations for extra stuff to come
  • Loading branch information...
1 parent f8a9a94 commit 98143649eaa54aa992c893645d38da0c297b74ae @markmacgillivray markmacgillivray committed Nov 13, 2011
View
@@ -1,12 +1,12 @@
WhatID - Got an ID? Not sure what it is? What you can do with it? Well, use this!
-More info: http://whatid.cottagelabs.com
+More info: http://idhelp.cottagelabs.com
How It Works
============
-Further information at http://whatid.cottagelabs.com
+Up and running at http://idhelp.cottagelabs.com
Install
View
@@ -0,0 +1,93 @@
+{
+ # service
+ "service_name" : "ID Help",
+
+ # provide site address URL if you need to overwrite what it might otherwise be calculated to be
+ #"SITE_URL" : "http://idhelp.cottagelabs.com"
+
+ # base URL of search service
+ "base_url" : "/search",
+
+ # elasticsearch settings
+ "ELASTIC_SEARCH_HOST" : "127.0.0.1:9200",
+ "ELASTIC_SEARCH_DB" : "idhelp",
+
+ # default results and paging options
+ "results_per_page" : 10,
+ "results_per_page_options" : [10, 20, 50, 100],
+
+ # The fields for which faceting should be made available on, and their default settings
+ # these can be nested fields, e.g. links.url
+ "facet_fields" : [
+ {
+ "key":"collection",
+ "order":"term",
+ "size":200
+ },
+ {
+ "key":"type",
+ "order":"count"
+ },
+ {
+ "key":"journal"
+ },
+ {
+ "key":"author",
+ "order":"term",
+ "size":1000
+ },
+ {
+ "key":"year",
+ "order":"reverse_term"
+ }
+ ],
+
+
+ # functions to perform on particular result fields on display - these are defined in iomanager
+ "display_value_functions" : {
+ "author":{"authorify":{}},
+ "collection": {"collectionify":{}},
+ "links": {"bibsoup_links":{}}
+ },
+
+ # a dict of the ES mappings. identify by name, and include name as first object name
+ "mappings" : {
+ "record" : {
+ "record" : {
+ "dynamic_templates" : [
+ {
+ "default" : {
+ "match" : "*",
+ "match_mapping_type": "string",
+ "mapping" : {
+ "type" : "multi_field",
+ "fields" : {
+ "{name}" : {"type" : "{dynamic_type}", "index" : "analyzed", "store" : "no"},
+ "exact" : {"type" : "{dynamic_type}", "index" : "not_analyzed", "store" : "yes"}
+ }
+ }
+ }
+ }
+ ]
+ }
+ },
+ "collection" : {
+ "collection" : {
+ "dynamic_templates" : [
+ {
+ "default" : {
+ "match" : "*",
+ "mapping" : {
+ "index" : "not_analyzed"
+ }
+ }
+ }
+ ]
+ }
+ }
+ },
+
+ # identifier for how non-analyzed fields for faceting are differenetiated in the mappings
+ "facet_field" : ".exact"
+
+}
View
@@ -6,6 +6,6 @@
for r in j:
print json.dumps(r)
conn = httplib.HTTPConnection('localhost', '9200')
- fullpath = "/whatid/test"
+ fullpath = "/idhelp/test"
conn.request('POST', fullpath, json.dumps(r))
- print conn.getresponse().status
+ print conn.getresponse().status
View
@@ -4,24 +4,24 @@
"regex": "[\\da-fA-F]{8}-[\\da-fA-F]{4}-4[\\da-fA-F]{3}-[89ABab][\\da-fA-F]{3}-[\\da-fA-F]{12}",
"url_prefix": "",
"url_suffix": "",
- "useful_links": "http://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29",
+ "useful_links": ["http://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29"],
"description": "Version 4 UUIDs use a scheme relying only on random numbers. This algorithm sets the version number as well as two reserved bits. All other bits are set using a random or pseudorandom data source. Version 4 UUIDs have the form xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and y is one of 8, 9, A, or B. e.g. f47ac10b-58cc-4372-a567-0e02b2c3d479. (Wikipedia)"
},
{
"name": "DOI",
"regex": "^((http:\/\/){0,1}dx.doi.org/|(http:\/\/){0,1}hdl.handle.net\/|doi:|info:doi:){0,1}(?P<id>10\\..+\/.+)",
"url_prefix": "http://dx.doi.org/",
"url_suffix": "",
- "useful_links": "http://www.doi.org/",
+ "useful_links": ["http://www.doi.org/"],
"description": "The Digital Object Identifier (DOI®) System is for identifying content objects in the digital environment. to any entity for use on digital networks. They are used to provide current information, including where they (or information about them) can be found on the Internet. Information about a digital object may change over time, including where to find it, but its DOI name will not change. (doi.org)"
},
{
"name": "ISSN",
"regex": "[\\d]{4}-[\\d]{3}[\\dX]",
"url_prefix": "",
"url_suffix": "",
- "useful_links": "http://www.issn.org/",
+ "useful_links": ["http://www.issn.org/"],
"description": "The ISSN is the standardized international code which allows the identification of any serial publication, including electronic serials, independently of its country of publication, of its language or alphabet, of its frequency, medium, etc. (issn.org)"
}
-]
+]
View
@@ -17,7 +17,7 @@ def init_db():
def get_conn():
host = "127.0.0.1:9200"
- db_name = "whatid"
+ db_name = "idhelp"
conn = pyes.ES([host])
return conn, db_name
@@ -57,11 +57,6 @@ def get(cls, id_):
raise
@classmethod
- def get_mapping(cls):
- conn, db = get_conn()
- return conn.get_mapping(cls.__type__, db)
-
- @classmethod
def upsert(cls, data, state=None):
'''Update backend object with a dictionary of data.
If no id is supplied an uuid id will be created before saving.'''
@@ -139,7 +134,6 @@ class Description(DomainObject):
class Identifier(DomainObject):
__type__ = 'identifier'
-
class Account(DomainObject, UserMixin):
__type__ = 'account'
View
@@ -22,12 +22,9 @@ def _check_regexes(self, identifier, regexes):
success = []
for r in regexes:
r = r['_source']
- print r
- print identifier
match = self._check_expression(identifier, r)
if match is None:
continue
- print match.group()
if not r['url_prefix']:
success.append(r)
continue
View
@@ -10,26 +10,28 @@ def __init__(self, owner):
self.owner = owner
def submit(self, request):
- '''Import a regex or an identifer description into the database.'''
- pre = request.values.get("url",'')
+ '''Import an identifer test or description into the index.'''
+ pre = request.values.get("url_suffix",'')
+ useful_links = [request.values.get("useful_link1",'')]
if not pre.endswith('/'):
pre += '/'
if not ( pre.startswith('http://') or pre.startswith('https://') ):
pre = 'http://' + pre
record = {
- "name": request.values["name"],
- "regex": request.values["regex"],
+ "name": request.values.get("name",''),
+ "regex": request.values.get("regex",''),
"url_prefix": pre,
- "url_suffix": request.values["suffix"],
- "description": request.values["description"],
+ "url_suffix": request.values.get("url_suffix",''),
+ "description": request.values.get("description",''),
# TODO: refactor useful links handling below (and perhaps submit.html template) to allow for multiple useful links
- "useful_links": request.values["useful_link1"],
- "tags": request.values["tags"].split(","),
- "timestamp": datetime.now().isoformat(),
+ "useful_links": useful_links,
+ "tags": request.values.get("tags",'').split(","),
+ "created": datetime.now().isoformat(),
+ "modified": datetime.now().isoformat(),
"owner": self.owner.id
}
if request.values["type"] == "regex":
whatid.dao.Test.upsert(record)
- if request.values["type"] == "identifier":
+ if request.values["type"] == "description":
whatid.dao.Description.upsert(record)
View
@@ -1,12 +1,15 @@
import urllib2
from copy import deepcopy
import whatid.dao
+import whatid.config
class IOManager(object):
def __init__(self, results, args={}, path=""):
self.results = results
self.args = args
self.path = path
+ self.config = whatid.config.Config()
+
def get_q(self):
return self.args.get('q','')
@@ -18,39 +21,6 @@ def get_path_params(self,myargs):
if self.showkeys:
param += 'showkeys=' + self.showkeys + '&'
return param
-
- def get_result_display(self,counter):
- '''use the result_display object as a template for search results'''
- display = self.config.result_display
- output = ""
- if not display:
- return output
-
- for item in display:
- line = ""
- for pobj in item:
- if 'key' in pobj:
- keydisp = self.get_str(self.set()[counter],pobj['key'])
- if keydisp:
- try:
- keydisp = unichr(keydisp)
- except:
- pass
- line += pobj.get('pre','') + keydisp + pobj.get('post','') + " "
- if 'default' in pobj:
- line += pobj.get('default','') + " "
- if line:
- output += line.strip().strip(",") + "<br />"
-
- if self.get_showkeys():
- output += '<table>'
- keys = [i for i in self.get_showkeys().split(',')]
- for key in keys:
- out = self.get_str(self.set()[counter],key)
- if out:
- output += '<tr><td><strong>' + key + '</strong>: ' + out + '</td></tr>'
- output += '</table>'
- return output
'''get all currently available keys in ES'''
def get_keys(self,rectype='Regex'):
@@ -36,3 +36,7 @@ input.frontin:hover{
background-color:white;
border:1px solid #373737;
}
+
+.help-block{
+ color:green;
+}
@@ -36,7 +36,6 @@ jQuery(document).ready(function() {
}
jQuery('#collection').bind('keyup',checkcoll);
-
});
@@ -2,12 +2,10 @@
{% block content %}
<div class="action_box">
- <h2>The answer</h2>
+ <h1>{{string}}</h1>
{% if answer %}
- <h3>We think this is a:</h3>
-
<h1>{{answer[0]['name']}}</h1>
<p>Here are the successful matches on this identifier, and some useful info:</p>
@@ -18,12 +16,17 @@
<h3>{{item['name']}}</h3>
<p>{{item['description']}}</p>
</td>
- <td>
+ <td class="span6">
{% if item['url_prefix'] %}
- <p>Find it here: <a href="{{item['url_prefix']}}{{item['string']}}{{item['url_suffix']}}">{{item['url_prefix']}}{{string}}{{item['url_suffix']}}</a></p>
+ <p>Find it here: <a href="{{item['url_prefix']}}{{string}}{{item['url_suffix']}}">{{item['url_prefix']}}{{string}}{{item['url_suffix']}}</a></p>
{% endif %}
{% if item['useful_links'] %}
- <p>Learn more: <a href="{{item['useful_links']}}">{{item['useful_links']}}</a></p>
+ <p>Learn more</p>
+ <ul>
+ {% for link in item['useful_links'] %}
+ <li><a href="{{link}}">{{link}}</a></li>
+ {% endfor %}
+ </ul>
{% endif %}
</td>
</tr>
@@ -35,8 +35,8 @@
<div class="container">
<h3><a href="/">ID Help</a></h3>
<ul class="nav">
+ <li><a href="/browse">Browse</a></li>
<li><a href="/identify">Identify</a></li>
- <li><a href="/parse">Parse</a></li>
<li><a href="/submit">Submit</a></li>
<li><a href="/rate">Rate</a></li>
</ul>
@@ -4,13 +4,20 @@
<div class="hero-unit">
<form action="/identify" method="POST" enctype="multipart/form-data">
- <input class="frontin" type="text" name="string" value="/^(IDHelp).*?$/" />
+ <input class="frontin" type="text" name="q" value="/^(IDHelp).*?$/" />
</form>
<p>Got an ID? Not sure what it is? What you can do with it? Just paste above and hit enter!</p>
<p><small>example: 10.1186/1758-2946-3-47</small></p>
</div>
<div class="row">
+ <div class="span4 column">
+ <div class="alert-message block-message info">
+ <h2>Browse</h2>
+ <p>Have a look at the tests, descriptions and identifiers in our catalogue.</p>
+ <p><a href="/browse" class="btn">Browse &raquo;</a></p>
+ </div>
+ </div>
<div class="span4 column info">
<div class="alert-message block-message info">
<h2>Identify</h3>
@@ -20,15 +27,8 @@
</div>
<div class="span4 column">
<div class="alert-message block-message info">
- <h2>Parse</h2>
- <p>You got some text, and there may be an identifier in it. But where?</p>
- <p><a href="/parse" class="btn">Parse &raquo;</a></p>
- </div>
- </div>
- <div class="span4 column">
- <div class="alert-message block-message info">
<h2>Submit</h2>
- <p>You have a method for identifying identifiers - tell us about it</p>
+ <p>Help us identify identifiers - submit a test or a description</p>
<p><a href="/submit" class="btn">Submit &raquo;</a></p>
</div>
</div>
Oops, something went wrong.

0 comments on commit 9814364

Please sign in to comment.