Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/front/solstice
A simple Solr wrapper for AngularJS apps
https://github.com/front/solstice
Last synced: 2 months ago
JSON representation
A simple Solr wrapper for AngularJS apps
- Host: GitHub
- URL: https://github.com/front/solstice
- Owner: front
- Archived: true
- Created: 2013-11-27T10:56:12.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2017-11-09T12:30:28.000Z (about 7 years ago)
- Last Synced: 2024-11-07T22:13:30.338Z (2 months ago)
- Language: JavaScript
- Size: 22.5 KB
- Stars: 36
- Watchers: 17
- Forks: 7
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-solr - Solstice - A simple Solr wrapper for AngularJS apps. (Interfaces)
README
Solstice
========
A simple Solr wrapper for AngularJS (1.x) appsSolstice is an AngularJS module, developed by [Frontkom](http://www.frontkom.no/), that enables simple querying of Solr indexes.
Solstice provides a search **service** and a companion **directive** that can be used in any Angularjs project.Solstice is inspired by [Restangular](https://github.com/mgonto/restangular) - an Angularjs service to handle Rest API resources.
### Installation
Solstice can be installed using **Bower** or manually.#### Using bower
```
bower install solstice
```#### Manually
Clone or download this repository and add the **dist/solstice.js** or **dist/solstice.min.js** file to your html.```
```
### Configuration
To use Solstice, just add it as a dependency to your app and set the default Solr index url in the config function.
```
var app = angular.module('my-app', ['solstice']);app.config(function(SolsticeProvider) {
SolsticeProvider.setEndpoint('url-to-your-index');
});```
###Using Solstice
#### As service:
To use Solstice, you just need to add it as a dependency to the controller function.```
app.controller('MyController', function($scope, Solstice) {
Solstice.search({
q: 'bundle:article AND status:true',
fl: 'title, teaser, published',
sort: 'published desc',
rows: 10
})
.then(function (_){
var data = _.data.response;
$scope.results = data.docs;
console.log(data.docs);
});
});
```##### Using a Diferent endpoint
For some queries you may need to use a different index than the global one. In that case, you need to create a new service that extends Solstice.
In the following example, we create a new service called **Equinox** that uses a different Solr index.
```
app.provider('Equinox', function(Solstice) {
return Solstice.withEndpoint('a-diferent-solr-index-url');
});app.controller('AnotherController', function($scope, Equinox) {
Equinox.search({
q: '*',
fl: 'title, teaser, published'
rows: 2
})
.then(function (_){
var data = _.data.response;
$scope.results = data.docs;
console.log(data.docs);
});
});
```####Usage as directive:
Solstice can also be used directly as a directive, if the use of the service is not required. This can be particularly usefull if the Solr querying is just a small part of a larger project.To use it, just add the directive `solr-search` to any element in the html. This directive provides the following options:
- `index-url`: The Solr index to be used. Only required if it wasn't set in the config.
- `q`: The query string. See the Apache solr [documentation](http://wiki.apache.org/solr/SolrQuerySyntax) for details.
- `rows`: The number of results to retrieve.
- `start`: The number of results to skip.
- `sort`: The sort params.
- `fl`: The field list to be retrieved.```
Found {{ solr.found }} results.
- {{ item.title }}
```
The module provides the $scope with a `solr` object. It has the following properties:
- `results`: the list of results
- `found`: the total number of results found.
##Future Features
- Full caching with Angularjs cacheFactory
- Support more SOLR features
- Querystring parsing
- Query language support