Giter Site home page Giter Site logo

bighunter513 / mod_search_solr Goto Github PK

View Code? Open in Web Editor NEW

This project forked from arjan/mod_search_solr

0.0 0.0 0.0 29.53 MB

Zotonic module for Solr support

License: MIT License

Erlang 5.24% Shell 0.07% HTML 4.90% CSS 7.70% JavaScript 82.08%

mod_search_solr's Introduction

SOLR support for Zotonic

This module adds support for Solr to Zotonic. It comes with Solr built in: just install this module and off you go.

Once set up, Zotonic will push each resource it saves into Solr, so the database can be queried. To reindex the whole site into Solr, press the 'rebuild search indexes' button in the admin.

Installation

You need to manually add a 'core' to the embedded Solr instance for each site you want to enable Solr support for. This is done in the priv/cores/solr.xml file inside the module: copy the solr.xml.in file to solr.xml and add as many cores as you have sites, naming them the same way.

Regular query syntax

Most of the query options are similar to the query-search syntax: http://zotonic.com/docs/0.9/manuals/datamodel/search.html, but you can do more nice things with Solr.

You can refactor your existing queries (from m.search[{query ....}]):

{% with m.search[{solr text="collage" cat="media" }] as r %}
    {% print r %}
{% endwith %}

Works exactly the same, including paging using the pager scomp. Only thing that is different are that there are no custom pivots, and some sort fields might be named differently.

Finding similar resources

Using Solr's MoreLikeThis feature we implemented a simple matcher. Following example finds 4 resources which are closely related to resource nr 332:

{% for id in m.search[{match id=332 pagelen=4}] %}
{{ m.rsc[id].title }},
{% endfor %}

Full-text search and text highlighting

Fulltext search works out of the box. You can tell solr to highlight the relevant sections of a document for you. Currently this does only work for the title and the summary (the document body is only indexed in solr, not stored).

Note that if you use highlighting you get an extended search result format. Following query searches fulltext for the string "hello world" in docs with the category "text" (or below). It tells solr to highlight the found titles and summaries (with tags):

{% with m.search[{solr text="hello world" highlight="title,summary" cat="text"}] as r %}

The Ids are now in "r.result.ids":

{% for id in r.result.ids %}

And to show the title highlighted:

{{ r.result.highlight[id].title|default:m.rsc[id].title }}

..and the summary:

{{ r.result.highlight[id].summary|default:m.rsc[id].summary }}


{% endfor %}

Facetting

Facetting is the subdivision of the search result into a couple of relevant groups, like Zotonic's categories for instance. With a single search result, you can show the division of how many items are in a certain group.

The following tells Solr to facet on the rsc category:

{% with m.search[{solr text="hello world" facet="category"}] as r %}

{% for category_name,count in r.result.facet_fields.category %}
    <li>{{ category-name}} contains {{ count }} items.</li>
{% endfor %}

{% endwith %}

Indexing extra properties

By listening to the solr_props notification you can add extra fields to the indexed document. Implementing modules are expected to return lists of [{Key, Value}] properties, which will be indexed with the resource in Solr.

Custom Solr queries

By listening to the {solr_search, Query} notification you can handle specific cases for m.search[{solr ...}].

You are expected to return a {QueryString, SolrOptions} tuple.

mod_search_solr's People

Contributors

mworrell avatar arthurclemens avatar

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.