Git Product home page Git Product logo

searchbox-core's Introduction

searchbox

searchbox is a lightweight search framework built on redis.

searchbox

Prerequisities

  • JDK 1.8.X
  • Maven 3.3.X
  • Redis 2.6.X

Full Documentation

See the Wiki for full documentation, examples, operational details and other information.

Related Articles

Getting Started

  • Download the dependency then Install dependency by using mvn install
  • Add searchbox dependency into your project
  <dependency>
  	<groupId>com.quebic.searchbox</groupId>
  	<artifactId>searchbox-core</artifactId>
  	<version>1.0.0-SNAPSHOT</version>
  </dependency>

Sample application

  • Download the movies-search-app application from GitHub
  • Build the application using mvn package
  • Run the application using java -jar target\movies-search-app-0.0.1-SNAPSHOT.jar
  • Consume web app from localhost:1028

Stand up searchbox

@SpringBootApplication
@EnableSearchBox
public class App 
{
    public static void main( String[] args )
    {
    	SpringApplication.run(App.class, args);
    }
    
}
  • You can easily integrate searchbox with your Spring application by using @EnableSearchBox annotation.

configuration

  • Add some properties into ../src/main/resources/application.properties or ../src/main/resources/application.yml
  • appname is a required property. It is used to identify individual applications.
searchbox.appname = movies-search-app
  • Some of the optional properties.
searchbox.page.length =  # Search result page size. Default value is 10

server.host = # Http server host. Default value is localhost
server.port = # Http server port. Default value is 1028

redis.host = # Redis server host. Default value is localhost
redis.port = # Redis server port. Default value is 6379

Model Annotations

public class Movie {
	
	@Id
	@Index
	private int id;
	
	@Index
	private String title;
	
	@Index
	private String director;

	private int duration;
	
	...
  • @Id annotation is used to mention identity field of the model. Each model has a unique id.
  • @Index annotation is used to mention index fields of the model. Searching is perform only for index fields.

SearchBoxOperations

@RestController
@RequestMapping("/movies")
public class MovieController {
	
	@Autowired
	private SearchBoxOperations searchBoxOperations;
	
	...
	

insert,update and save

<T> void insert(T object) throws SearchBoxOperationsException
<T> void update(T object) throws SearchBoxOperationsException
<T> void save(T object) throws SearchBoxOperationsException
  • insert Check id is exists. Not allow for duplicate ids.
  • update Check id is exists. Then modify perticular model. Otherwise raised Id is not found exception.
  • save Check id is exists. If Id is exists update the model. Otherwise insert a new model.

search by field value

<T> SearchResult<T> searchByField(Class<T> cls, String field, Object searchValue, Page page) throws SearchBoxOperationsException;
  • example searchBoxOperations.searchByField(Movie.class, "id", id)

search by perfix value

<T> SearchResult<T> searchByFieldPerfix(Class<T> cls, String field, Object searchPrefix, Page page, boolean allWords) throws SearchBoxOperationsException;
  • example searchBoxOperations.searchByFieldPerfix(Movie.class, "title", "av") => ["Avatar", "Avengers", ...]

search by text pattern

<T> SearchResult<T> searchByFieldPattern(Class<T> cls, String field, String pattern, Page page) throws SearchBoxOperationsException;
  • example searchBoxOperations.searchByFieldPattern(Movie.class, "title", "*nic") => ["Titanic", ...]

Criteria Api

<T> SearchResult<T> search(Class<T> cls, Query query, Page page) throws SearchBoxOperationsException;
  • you can query your data with Criteria Api
  • example searchBoxOperations.search(Movie.class, new Query(Criteria.where("id").is(7)))

Query Functions

@QueryController
public class QueryFunctions {

	@QueryFunction("query1")
	public QueryHolder query1() throws Exception{
		
		Criteria c = Criteria
				.where("@parm_key").is("@parm_value");
		
		Query query = new Query(c);
		
		return new QueryHolder(Movie.class, query);
		
	}
	...
  • QueryFunctions are used PlaceHolders with '@' prefix to pass runtime values into query. Ex: @parm_key, @parm_value

  • Calling QueryFunctions by using SearchBoxOperations.

<T> SearchResult<T> search(String queryName, Map<String, Object> inputParms, Page page) throws SearchBoxOperationsException;
  • example
String queryName = "query1";
		
Map<String, Object> parms = new HashMap<>();
parms.put("parm_key", "title");
parms.put("parm_value", "Avatar");
	
searchBoxOperations.search("query1", parms);

Authors

License

  • This project is licensed under the Apache Licensed V2

searchbox-core's People

Contributors

quebic-source avatar

Watchers

James Cloos 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.