Git Product home page Git Product logo

facetview's Introduction

FacetView is a pure javascript frontend for ElasticSearch search indices.

Facetview2

A more modular codebase is available at https://github.com/CottageLabs/facetview2

Old facetview docs below

(This used to work against SOLR too, but the need to maintain support for that became less, and is now not a priority. So has been removed altogether. If anyone needs it, it could be added back in by writing an alternative to the elasticsearchquery() with a solrsearchquery(), and making sure the returned resultset can be parsed out properly. Used to work fine so it can be done, but as new functionality like nesting and so on was brought in, it became less important.)

It's been developed as a jQuery plugin and lets you easily embed a faceted browse front end into any web page.

Development of this version is NOT currently active. Facetview1 repo: http://github.com/okfn/facetview

Demo

See http://okfnlabs.org/facetview/ or if you have the source just take a look at index.html or simple.html

Status

FacetView is pretty new, and still under active development but is already pretty stable. If you have suggestions or want to make a contribution please check out the github repo.

Using FacetView

Add the following code to your web page:

<script type="text/javascript" src="vendor/jquery/1.7.1/jquery-1.7.1.min.js"></script>
<link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.min.css">
<script type="text/javascript" src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="vendor/linkify/1.0/jquery.linkify-1.0-min.js"></script>
<link rel="stylesheet" href="vendor/jquery-ui-1.8.18.custom/jquery-ui-1.8.18.custom.css">
<script type="text/javascript" src="vendor/jquery-ui-1.8.18.custom/jquery-ui-1.8.18.custom.min.js"></script>
<script type="text/javascript" src="jquery.facetview.js"></script>
<link rel="stylesheet" href="css/facetview.css">
<script type="text/javascript" src="vendor/d3/d3.min.js"></script>
<script type="text/javascript" src="vendor/d3/d3.geom.min.js?2.1.3"></script>
<script type="text/javascript" src="vendor/d3/d3.layout.min.js?2.1.3"></script>
  • BUT change the src URLs to something sensible depending on where you install the files; or something different if you have the files available already. If using your own, NOTE the versions; particularly bootstrap - we are on the 2.x
  • d3 scripts can be dropped if you intend to disable filter visualisations.

Then add a script somewhere to your page that actually calls and sets up the facetview on a particular page element:

<script type="text/javascript">
jQuery(document).ready(function($) {
$('.facet-view-simple').facetview({

search_url: 'http://bibsoup.net/query?', search_index: 'elasticsearch', facets: [

{'field': 'publisher.exact', 'size': 100, 'order':'term', 'display': 'publisher'}, {'field': 'author.name.exact', 'display': 'author'}, {'field': 'year.exact', 'display': 'year'}

],

});

});

</script>

Now that you have everything ready, you will probably want to customize to get it looking the way you want it.

Customization

Once you have FacetView all ready to go, you should probably do some customisation. There are a few ways to do this:

Edit the config in jquery.facetview.js

View the config options near the top of the file to learn more. Some important points:

  • search_url – you need this. Should be an elasticsearch or SOLR query endpoint
  • search_index – your index type, solr or elasticsearch
  • result_display - there is a long example of result display. It is a list of lists; each list represents a line; each line contains objects; the objects specify the field they should output, and pre and post information to surround it with
  • display_images - if this is set to true, then facetview will attempt to find the first http://... that ends with .jpg / .jpeg / .png / .gif in each record; if one is found, it will be displayed in the search result as a 100 x (up to) 150 px thumbnail
  • default_url_params – parameters to pass through with every query; should include “wt”:”json” for SOLR queries to return JSON, and probably “facet.mincount”:1 for SOLR queries to ignore zero counts on facet values
  • predefined_filters – use these to apply some filters that will be appended to every search. For example, customise a facetview display to only show records with a particular owner / collection / tag / whatever

Pass in config settings when calling FacetView

All of the settings can also be defined when calling FacetView, and will overwrite the values set in the file itself. So you can do something like this:

<script type="text/javascript">
jQuery(document).ready(function() {
    jQuery('YOUR-PAGE-PART').facetview({
        "search_index":"elasticsearch",
        ...
    });
});
</script>

Passing config parameters in the URL

Configs can be passed on the URL as query parameters. For example, ?q=blah will set the starting search to "blah". You can add complex queries as JSON objects, such as ?paging={"size":20,"from":10}. Nice...

Providing the location of an external config file

A file can be made available anywhere on the web (depending, keep reading) with any of the above listed settings in it (written in the usual way for a JSON object). Then, just pass the URL of your config file when you call FacetView - as a parameter called "config_file", and it will attempt to read that config file for you.

The first attempt will make a JSONP request to the URL you specify, so if your file is properly set up on a server that enables it to respond to such a request, you can make these calls to any address on the internet.

If JSONP call fails, then a normal GET will be executed. So if the file is under the same domain, it should be retrievable. In this case, the file must be normally readable to a GET request - e.g. it should have a .html extension, or be otherwise set up to return your config as a string to the GET request. The JSON config object is then parsed and read in.

Config precedence

When you introduce a new config object, they are merged into earlier configs with overwrite. So any config you specify in facetview.jquery.js will be overwritten and appended with newer info from any config passed in when calling facetview, which is overwritten by config parameters passed in the URL, and a call to a remote config file will similarly overwrite and append to all previous.

Change the layout by making and using a custom CSS file

Facetview uses the latest twitter bootstrap. When you embed facetview in a page, you need to include the calls to bootstrap js and css files (see the example index.html here for more info). You could restyle facetview any way you want, either with or without bootstrap - although it would be a hassle to strip bootstrap out; recommend working with or around it.

Copyright and License

Copyright 2011 Open Knowledge Foundation and Cottage Labs.

Licensed under the MIT License

facetview's People

Contributors

emanuil-tolev avatar martyn-w avatar mihneasim avatar omarkhan avatar rufuspollock avatar tomoinn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

facetview's Issues

dataobj.response is undefined on return results

Hi folks
Thanks for this, looks really good. I 'almost' have it going but stuck on a simple thing that concerns results returned. My generated elasticsearch query is:
http://localhost:9200/master/master_record/_search?from=0&size=10&facet.field=mxfs_filename&facet.field=title&q=_snow_%20\*
which generates a great deal of nice-looking json and OK in firebug.

However I don't get any textual record display or submenus in the facets? I get the dataobj.request message on return. I have jsonp specified in the config but I'm not sure what [if anything] I need to do with the templating etc. and this is not very clear in the commentary?

Thanks in advance Hugh Barnard

Switch to use template library and JSON2

While these do impose additional vendor dependencies they will simplify the code so greatly and improve its maintanability.

Question: which template library?

  • Ans: would have said jquery.tmpl but that is no longer blessed and is in fact deprecated. My best suggestion at this point is underscore template as that library is a standard utility library that is useful in its own right. Next best alternative would be mustache (?).

Using 'each' as a variable name

Line 848 is currently:
for ( var each = 0; each < options.facets.length; each++ ) {

I've changed mine locally to:
for ( var filter = 0; filter < options.facets.length; filter++ ) {

Paging breaks on new search

I have 1,000 results, and am on page 10 of said results. The pager says "page 91-100 of 1000".

If I then type in "cat", the paging says "page 91 - 5 of 5", displaying no results obviously.

I've quickly hacked this...:

    // update the options with the latest q value
    if ( options.searchbox_class.length == 0 ) {
        options.q = $('.facetview_freetext', obj).val();

... so the paging gets set to 0 before the new search is run

    // update the options with the latest q value
    if ( options.searchbox_class.length == 0 ) {
        options.paging.from = (options.q != $('.facetview_freetext', obj).val()) ? 0 : options.paging.from;
        options.q = $('.facetview_freetext', obj).val();

I'm sure you have a much more elegant solution though!!

Support for range queries

You have done great work here. FacetView provides great experience right out of the box.
It would be great to have support (both UI and backend) for range queries as well. Do you have any plans for adding it back?

Copyright and License

Copyright: individual authors (or for orgs: OKFN + Cottage labs)

License: Suggest MIT for this

FacetsView Custom

Your FacetsView is really great!

But I try to do it, in my own website, but I can't make any request, because my URL is like "http://extremesearch.cloudapp.net:9200/turbomanga/manga".
And I wanna know how to make request in a adresse like that, cause in FacetsView you have "http://bibsoup.net/query?"

So I wanna know how I can make request in my website! I was thinking about change default_url_params, but I failed!

Thx for your job, and to listen me! x) (Sorry if my english is bad...)

HTML syntax errors.

jquery.facetview.js (commit 78eea02947)

  • line 1127: the dot symbol inside closing p tag <p><b>Filter list size</b> can be altered by clicking on the filter size number<./p> \
  • line 1182: missed value for attribute autofocus value="" placeholder="search term" autofocus />';

Compatibility with ElasticSearch 1.3.4

I tried FacetView with ElaticSearch 1.3.4 but it doesn't work. I can't even get the list of documents displayed from the index. Is there any guideline to make it compatible with latest ElasticSearch?

Facetview sends invalid queries if called on an element not currently attached to the dom

I'm creating a BackBone view and calling $('#myelement',this.el).facetView() in the render() method. This is then called before adding the view's element to the DOM, the effect of which appears to be to cause facetview to send an invalid query :

{ query: { query_string: {} },
facets:
{ 'year.exact': { terms: [Object] },
'publisher.exact': { terms: [Object] } },
filter: { type: { value: 'structure' } } }

(the filter is being inserted by my code, but removing doesn't change the response). This fails to parse as there's no query in the query_string property, and the failure then causes facetview to fail on initialisation and not show the rest of the UI. It does show the search box, and subsequent searches from the part of the UI it has put up are well formed, it's just the initial one that fails.

Refactor to use HTML + templating

ATM html is built up with mixture of strings and code. This is very difficult to read and maintain. suggest we switch to using blocks of HTML with variables of form {{varname}} and then doing:

template.replace(/{{...}}/g, variable)

FacetView Not working

Hi,

I am not able to get it to work.
When i connect facetview to ElasticSearch i am getting this error:
SyntaxError: invalid label

This same issue seems to be coming in the demo site.

Please help
Thanks alot
Jaskaran

Custom Formatting on Facet Value

thanks for this awesome library.

I notice that if I pulled datetime data type from ES, it will be formatted in UNIX timestamp.
Would be ideal if we could have the ability to customize the value for display.

URI as result field

result_display formatting doesn't work and filters don't show when URIs are used as field names, for example, in the result below, "http://purl.org/dc/terms/creator" is used instead of "author", since currently the code assumes . is used to get data from an object, the split turns http://purl.org/dc/terms/creator into ["http://purl", "org/dc/terms/creator"] and breakes the functionality.

I forked the code and did a quick fix but my fix will not allow things like http://purl.org/dc/terms/creator.first_name to work, since it skips the split.

In the fix some jQuery selectors have been replaced with [id=""] syntax, as selectors like jQuery('#facetview_http_//purl_org/dc/terms/creator') don't seem to work using the standard syntax.

      {
        "_index": "rdfdata",
        "_type": "resource",
        "_id": "http://www.eea.europa.eu/highlights/check-last-year2019s-water-quality-in-your-favourite-bathing-spot",
        "_score": 1.0,
        "_source": {
          "http://www.eea.europa.eu/portal_types/Highlight#media": "http://www.eea.europa.eu/highlights/check-last-year2019s-water-quality-in-your-favourite-bathing-spot/image_xlarge",
          "http://rdfdata.eionet.europa.eu/amp/ontology/managementPlan": "2011",
          "http://www.eea.europa.eu/portal_types/Highlight#publishDate": "2008-06-02T08:00:00.0",
          "http://www.w3.org/2000/01/rdf-schema#label": "Check last year's water quality in your favourite bathing spot",
          "http://www.eea.europa.eu/portal_types/Highlight#text": "<p>With WISE, users can check the water quality on an interactive map. They can also select a country or a region, download the data for their selection and make comparisons with previous years. The downloaded data can also be visualised in geospatial mapping programmes such as Google Earth and Microsoft Live maps.</p> <p>WISE is a partnership between the European Commission (DG Environment, Joint Research Centre and Eurostat) and the European Environment Agency, closely collaborating with EU Member States. An annual assessment of the bathing water quality in the EU will be presented today by the European Commission.</p> <h3>State of bathing water<br /></h3> <ul><li><a href='http://www.eea.europa.eu/themes/water/status-and-monitoring/state-of-bathing-water/state/state-of-bathing-water' class='external-link'>Visit EEA's thematic site on 'state of bathing water'</a></li></ul> <p>&nbsp;</p> <h3>See also</h3> <ul><li>European Commission's press release: <a class='external-link' href='http://europa.eu/rapid/pressReleasesAction.do?reference=IP/08/834&amp;format=HTML&amp;aged=0&amp;language=EN&amp;guiLanguage=en'>&nbsp;Bathing water quality in the EU remains high<br /></a></li></ul> <p>&nbsp;</p>",
          "http://purl.org/dc/terms/title": "Check last year's water quality in your favourite bathing spot",
          "http://www.w3.org/1999/02/22-rdf-syntax-ns#type": [
            "http://rdfdata.eionet.europa.eu/amp/ontology/Output",
            "http://purl.org/ontology/bibo/Webpage",
            "http://www.eea.europa.eu/portal_types/Highlight#Highlight"
          ],
          "http://www.eea.europa.eu/portal_types/Highlight#themes": [
            "coast_sea",
            "water"
          ],
          "http://purl.org/dc/terms/modified": "2011-04-13T17:17:40.0",
          "http://www.eea.europa.eu/portal_types/Highlight#id": "check-last-year2019s-water-quality-in-your-favourite-bathing-spot",
          "http://purl.org/dc/terms/created": "2008-05-30T11:55:18.0",
          "http://purl.org/dc/terms/creator": "karadgu",
          "http://www.eea.europa.eu/portal_types/Highlight#management_plan": "2011",
          "http://www.eea.europa.eu/portal_types/Highlight#visibilityLevel": "middle",
          "http://purl.org/dc/terms/issued": "2008-06-02T08:00:00.0",
          "http://purl.org/dc/terms/isPartOf": "http://www.eea.europa.eu/highlights",
          "http://cr.eionet.europa.eu/ontologies/contreg.rdf#tag": [
            "coast_sea",
            "water"
          ],
          "http://purl.org/dc/terms/description": "The 'Water Information System for Europe' (WISE) now allows users to view the quality of the bathing water in more than 21 000 coastal beaches and freshwater bathing sites across Europe during the 2007 bathing season. WISE also includes new information on urban wastewater treatment and water quality in European lakes and rivers."
        }
      },

Aggregations instead of facets

With elasticsearch 1.0 aggregations are introduced. Best thing about them is, that you can nest them. Would be fine, if facetview would support that kind of facets with subfacets.

Unexpected result format

Hi,

i have some issues to display the result of my queries.
i may be doing things in the wrong way but i can't find a solution.

the resultdisplay var is simply defined like this :

    var resdisplay = [
            [
                {
                    "field": "personlastname"
                }
            ]
        ];

as a result i get the following string (actually the complete JSON object corresponding the query), instead of the only personlastname field :

{ "Ventes": { "Vente": { "orderid": "78698772", "timestamporder": "20121207130619310000", "orderstatus": "PV", "Client": { "personrole": "C", "persongender": "MME", "personlastname": "GAUTHIER", "personfirstname": "FRANCOISE", "personisoptinoutemail": "N", "personisoptinoutphone": "N", "personisoptinoutpost": "N", "personhomephonenumber": [], "Adresse": { "addrsiebeladdressid": "26652221", "addrisprimary": "1", "addraddress": "", "addraddresscomp1": [], "addrbuildingid": [], "addrstairid": [], "addrfloorid": [], "addrdoorid": [], "addrcountry": "FRANCE", "addrzipcode": "", "addrcity": "" } }, "Lignes": { "itemcodetype": "CO", "itemcode": "3650901", "itemlegacysalesclerkid": "017587", "itemlegacydeliverymode": "EMR", "itemquantity": "1", "itembaseprice": "8990", "itemlegacyvatcode": "1", "itemvatratee": "1960", "itemnetprice": "7516", "itemvatamount": "1474" } } } }

instead of :
GAUTHIER

do you have any idea ?

thanks a lot

Length of querystring in IE

Simple one this; we've found that some IE users, who are behind a proxy, find that FacetView sometimes breaks, as if FV can't talk to the ES server.

We seem to have fixed this by changing the search request from a GET to a POST.

http://stackoverflow.com/a/417184/1947031

Update: Ignore the above, we also removed a load of stats stuff from the query, and it's this that seems to have fixed it. Too many cooks... sorry to bother you basically.

More than 3 levels of nesting in results display

Just echoing a TODO in the code to remind myself (or somebody else) to fix it since one of my indices has fields like "bibjson.journal.title" and it wouldn't take much to tip that over to 4 parts.

var thekey = display[lineitem][object]['field'];
parts = thekey.split('.');
// TODO: this should perhaps recurse..
if (parts.length == 1) {
    var res = record;
} else if (parts.length == 2) {
    var res = record[parts[0]];
} else if (parts.length == 3) {
    var res = record[parts[0]][parts[1]];
}

in the buildrecord function.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.