GithubHelp home page GithubHelp logo

gunnarmorling / gsoc-hsearch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mincong-h/gsoc-hsearch

0.0 3.0 0.0 1.92 MB

Example usages of Hibernate Search for GSoC (Google Summer of Code)

License: Apache License 2.0

Java 98.91% HTML 1.09%

gsoc-hsearch's Introduction

badge license badge build

gsoc-hsearch

Example usages of Hibernate Search for GSoC (Google Summer of Code)

Before started

These examples are created under Eclipse IDE with JDK 1.8.

Examples

zoo-jpa

This is an example to demonstrate the how to build a web application integrating Hibernate Search feature and JPA 2.1. If you want to run the demo, you should use MySQL database and import data from script src/main/resources/zoo.sql.

There're 3 types of Lucene query in the demo, they're

  • keyword query
  • Fuzzy search
  • Wildcard search

You can switch them by commenting / uncommenting lines 101 - 103 in class io.github.mincongh.servlet.AnimalSearchServlet.

Keyword query

The most basic form of search. As the name suggests, this query type searches for one or more particular words.

private Query keywordQuery(String searchString) {
    return queryBuilder
            .keyword()
            .onFields("name", "type")
            .matching(searchString)
            .createQuery();
}

All entities containing the target keyword(s) will be reached.

Fuzzy search

With a fuzzy search, keywords match against fields even when they are off by one or more characters. Check wikipedia to know more about the Edit Distance.

private Query fuzzyQuery(String searchString) {
    return queryBuilder
            .keyword()
            .fuzzy()
//          .withThreshold(0.7f)        // deprecated
//                                      // use withEditDistanceUpTo(int)
            .withEditDistanceUpTo(2)    // default 2 (can be 0, 1, 2)
            .onFields("name", "type")
            .matching(searchString)
            .createQuery();
}

Wildcard search

Lucene supports single and multiple character wildcard searches within single terms (not within phrase queries)

  • To perform a single character wildcard search, user the ? symbol
  • To perform a multiple character wildcard search, user the * symbol
private Query wildcardQuery(String searchString) {
    return queryBuilder
            .keyword()
            .wildcard()
            .onFields("name", "type")
            .matching(searchString)
            .createQuery();
}

gsoc-hsearch's People

Contributors

mincong-h avatar

Watchers

Gunnar Morling avatar James Cloos avatar  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.