Another talk Compass: integrated site Search

Source: Internet
Author: User
Tags final

Some time ago has written an article about Compass, I believe that we have a certain understanding of the compass

Since the most recent project involves site search and is based on the JPA annotation form and has been on the web for a long time, there are few examples of JPA integration compass, some of which are xml-based, and very few based on annotations, There is no way only to Compass's official website download English documents themselves research, spent the afternoon to debug out, integrated into the project!

Here to share with you, I hope you can take some detours less!

1. Go to the official website to download the Compass jar package, I use the 2.1 version

http://www.compass-project.org/

Productinfo.java

Java code

@Entity


@Searchable


public class ProductInfo implements serializable{


private static final long serialversionuid = -8860864584425256200l;


private Integer ID;


/** Item Number **/


private String Code;


/** Product Name **/


private String name;


/** Product Type **/


private ProductType type;


/** Product Style **/


private set<productstyle> styles = new hashset<productstyle> ();





public ProductInfo () {}





@OneToMany (Cascade={cascadetype.remove,cascadetype.persist}, mappedby= "Product", Fetch=fetchtype.eager)


@OrderBy ("Visible desc, id ASC")


@SearchableReference


public set<productstyle> Getstyles () {


return styles;


  }


public void Setstyles (set<productstyle> styles) {


this.styles = styles;


  }





@Id @GeneratedValue


@SearchableId


public Integer getId () {


return ID;


  }


public void setId (Integer id) {


this.id = ID;


  }


@Column (length=30)


@SearchableProperty (index = index.tokenized, store = store.yes)


public String GetCode () {


return code;


  }


public void Setcode (String code) {


This.code = code;


  }


@Column (Length=50,nullable=false)


@SearchableProperty (index = index.tokenized, store = store.yes)


public String GetName () {


return name;


  }


public void SetName (String name) {


this.name = name;


  }





@ManyToOne (Cascade=cascadetype.refresh,optional=false)


@JoinColumn (name= "typeID")


@SearchableReference


public ProductType GetType () {


return type;


  }


public void SetType (ProductType type) {


this.type = type;


  }





@Override


public int hashcode () {


final int prime = 31;


int result = 1;


result = Prime * result + ((id = = null) 0:id.hashcode ());


return result;


  }


@Override


public boolean equals (Object obj) {


if (this = = obj)


return true;


if (obj = null)


return false;


if (getclass ()!= obj.getclass ())


return false;


final ProductInfo other = (productinfo) obj;


if (id = = NULL) {


if (other.id!= null)


return false;


} else if (!id.equals (other.id))


return false;


return true;


  }


}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.