The content of the invention
In order to realize foregoing invention purpose, for important object be associated other object search difficulties the problem of, this hairA kind of bright affiliated partner search method based on full-text search of offer, including,
S1, establish the object data model of different classes of object;
S2, using Map and Reduce methods, establish the relational data model of incidence relation between object;
S3, the full-text search that incidence relation database is established according to S2 result index;
S4, the search key provided according to user, incidence relation database index is searched for, the institute extracted in relational model is relevantJoin object, and return to user.
Preferably, by the object sequence number in objects association it is ID values in a manner of Map, and object is in itself in the S2Mapped, be then combined ID identical objects in a manner of Reduce, form correlation model, and travel through all possibilityObject relationship form.
Preferably, in the S3, carried out in full in incidence relation database index by using the search key of offerRetrieval, for the candidate result of matching, further obtain associated all objects.
Preferably, the object model of the S1 comprises at least people, car, space, case;
Wherein, people's object model comprises at least name, identification card number, native place attribute, and car object model comprises at least car plate, vehicleAttribute;Spatial object model comprises at least title, address properties;Case object model comprises at least personnel, criminal type attribute.
Preferably, the object relationship that the data model of incidence relation comprises at least between object in the S2 is:Subordinate, familyFront yard, rent, go together;According to the object relationship between each object model of the S1;Established pair by Map and Reduce modesRelational model as between, the ID values and object of object relationship are mapped in itself in the Map stages, will be closed in the Reduce stagesIt is that ID identical objects are combined, forms correlation model;All possibility object relationship forms are traveled through, to include all objectsRelation.
Preferably, the step of S4 is the keyword used when user is searched for and the full text rope established in the S3Row matching search is introduced, according to the order of matching degree from high to low, obtains initial search result;Then each search is tiedFruit, its relational model stored in the S3 is obtained respectively, all objects included in relational model are extracted, as finalSearch result returns to user.
The beneficial effect that technical scheme provided in an embodiment of the present invention is brought is:Depth is excavated associated with important objectOther object informations, be the powerful of management of enhancing public security.Big data is used in a creative way in public safety fieldAnalytical technology, compared with general search engine technique, the search result using object as base unit can be more accurately obtained,Criminal investigation, the clue solved a case etc. between object be particularly suitable for use in as the application scenarios being oriented to., can be straight centered on searched objectConnect to obtain the information of each related object, for further analysis cutback in demand search complexity.
Embodiment 1
The present invention provides a kind of affiliated partner search method based on full-text search, including,
S1, establish the object data model of different classes of object;
S2, using Map and Reduce methods, establish the relational data model of incidence relation between object;
S3, the full-text search that incidence relation database is established according to S2 result index;
S4, the search key provided according to user, incidence relation database index is searched for, the institute extracted in relational model is relevantJoin object, and return to user.
In S2, the ID values in objects association and object are mapped in itself in a manner of Map, then with Reduce sideID identical objects are combined by formula, form correlation model, and travel through all possibility object relationship forms.
In S3, the search key provided by user carries out full-text search in incidence relation database index, forThe candidate result of matching, further obtain associated all objects.
S1 object model comprises at least people, car, space, case;
Wherein, people's object model comprises at least name, identification card number, native place attribute, and car object model comprises at least car plate, vehicleAttribute;Spatial object model comprises at least title, address properties;Case object model comprises at least personnel, criminal type attribute.
The object relationship that the data model of incidence relation comprises at least between object in S2 is:Subordinate, family, rent, togetherOK;According to the object relationship between S1 each object model;The relation mould established by Map and Reduce modes between objectType, the ID values and object of object relationship are mapped in itself in the Map stages, in the Reduce stages by relations I D identical objectsIt is combined, forms correlation model;All possibility object relationship forms are traveled through, to include all object relationships.
The step of S4 is that the full-text index established in the keyword and S3 used when user is searched for carries out matching search,According to the order of matching degree from high to low, initial search result is obtained;Then to each search result, obtain respectively itsThe relational model stored in S3, all objects included in relational model are extracted, user is returned to as final search result.
Referring to Fig. 1, the present invention provides a kind of affiliated partner search method based on full-text search.The operating procedure of the present inventionIt is as follows:
Step 1, establish a variety of object models.Common object type someone, car, space, case etc., typical people's object modelForm is as follows:
| Name | ID | Height |
| Li Si | 18 identification card numbers | 170 |
Typical car object model form is as follows:
| Car owner | Car owner ID | Car plate | Color |
| Li Si | 18 identification card numbers | X XXXX | In vain |
Typical spatial object model form is as follows:
| Lodging person | ID | Hotel title | Address |
| Li Si | 18 identification card numbers | XXXX | Beijing XXX |
Typical case object model form is as follows:
| Name | ID | Criminal type | Tool used in crime |
| Li Si | 18 identification card numbers | Theft | Waddy |
Model above is stored into database.
Step 2, the relational model established between object.By taking subordinate relation as an example, typical Object Relational Model form is such asUnder:
| ID | Name | Car plate |
| 18 identification card numbers | Li Si | X XXXX |
The typical model is associated people's object model and car object model by identical ID values.
Step 3, the full-text search index for establishing Object Relational Model.The Object Relational Model obtained in step 2 is storedEnter database, and establish and be indexed for full-text search.
Step 4, search procedure.By taking search key " Li Si " as an example, illustrate specific search procedure.First from step 3" Li Si " is searched in the index database of foundation, " ID " and " car plate " of correlation is obtained, by incidence relation, further obtains people's modelAs a result with vehicle model result, and user is returned to as the search result of " Li Si ".
Above procedure can use following codes to realize:
public void map(ImmutableBytesWritable key, Result result, Contextcontext) throws IOException, InterruptedException {
TableSplit sp = ((TableSplit)context.getInputSplit());
String table = Bytes.toString(sp.getTable().getName());
try {
BaseModel bean=(BaseModel) database Util.resultToBean(result, table);
MergeUtil.json2str(bean);
if(bean instanceof Person){
Person entity = (Person)bean;
write(context, bean, entity.getCardNo());
}else if(bean instanceof Vehicle){
Vehicle entity = (Vehicle)bean;
write(context, bean, entity.getPaperNumber());
}else if(bean instanceof AlarmList){
AlarmList entity = (AlarmList)bean;
write(context, bean, entity.getId());
}else if(bean instanceof Mrza){
Mrza entity = (Mrza)bean;
write(context, bean, entity.getId());
}else if(bean instanceof Case){
Case entity = (Case)bean;
if(StringUtils.isNotBlank(entity.getCardNos())){
String[] cardNos = entity.getCardNos().split(",");
for (String cardNo : cardNos) {
write(context, bean, cardNo);
}
}else{
write(context, bean, entity.getId());
}
}else if(bean instanceof PawnshopRecord){
PawnshopRecord entity = (PawnshopRecord)bean;
write(context, bean, entity.getCardNo());
}
Catch (Cdc databases Exception | CdCommonException |IllegalArgumentException | IllegalAccessException e) {
logger.error(e,e);
throw new IOException(e);
}
}
private void write(Context context, BaseModel bean, String rowkey)throws IOException, InterruptedException, CdCommonException {
if(StringUtils.isNotBlank(rowkey)){
context.write(new Text(String.valueOf(rowkey)), new Text(SeralizeFactory.original().serializa(bean)));;}}
protected void reduce(Text key, Iterable<Text> values, Context context)throws IOException, InterruptedException {
List<SolrAIOAttr> personList = new ArrayList<SolrAIOAttr>();
List<SolrAIOAttr> caseList = new ArrayList<SolrAIOAttr>();
List<SolrAIOAttr> vehicleList = new ArrayList<SolrAIOAttr>();
List<SolrAIOAttr> alarmLists = new ArrayList<SolrAIOAttr>();
List<SolrAIOAttr> mrzaLists = new ArrayList<SolrAIOAttr>();
List<SolrAIOAttr> pawnshops = new ArrayList<SolrAIOAttr>();
int size = 0;
try {
String date = null;
for (Text text : values) {
size++;
if(size>10){
return;
}
PhoenixBaseBean bean = (PhoenixBaseBean)SeralizeFactory.original().unSerializa(text.getBytes());
if(bean instanceof Person){
SolrAIOAttr aio = new SolrAIOAttr(JsonUtil.bean2json(bean), null);;
personList.add(aio);
}else if(bean instanceof Case){
Case cases = (Case)bean;
SolrAIOAttr aio = new SolrAIOAttr(JsonUtil.bean2json(bean), cases.getAlarmTime());
caseList.add(aio);
date = updateDate(date, cases.getAlarmTime());
}else if(bean instanceof Vehicle){
Vehicle vehicle = (Vehicle)bean;
String title = vehicle.getVehicleNum();
if(StringUtils.isBlank(title)){
vehicle.getCardNum();
}
SolrAIOAttr aio = new SolrAIOAttr(JsonUtil.bean2json(bean), vehicle.getRegisterDate());
vehicleList.add(aio);
date = updateDate(date, vehicle.getRegisterDate());
}else if(bean instanceof AlarmList){
AlarmList alarmList = (AlarmList)bean;
if(alarmList.getAlarmNumber()!=null && !alarmList.getAlarmNumber().trim().equals("") && alarmList.getAlarmDescribe()!=null && !alarmList.getAlarmDescribe().trim().equals("")){
SolrAIOAttr aio = new SolrAIOAttr(JsonUtil.bean2json(bean), alarmList.getCallTime());
alarmLists.add(aio);
date = updateDate(date,alarmList.getCallTime());
}
}else if(bean instanceof Mrza){
Mrza mrza = (Mrza)bean;
SolrAIOAttr aio = new SolrAIOAttr(JsonUtil.bean2json(bean), mrza.getTitle());
mrzaLists.add(aio);
date = updateDate(date, mrza.getTitle());
}else if(bean instanceof PawnshopRecord){
PawnshopRecord pawnshop= (PawnshopRecord)bean;
SolrAIOAttr aio = new SolrAIOAttr(JsonUtil.bean2json(bean), pawnshop.getDate());
pawnshops.add(aio);
date = updateDate(date, pawnshop.getDate());
}
}
Collections.sort(vehicleList);
Collections.sort(caseList);
Collections.sort(pawnshops);
logger.info("key:"+key.toString());
SolrAIO bean = new SolrAIO(key.toString());
bean.setPerson(JSONArray.fromObject(personList).toString());
bean.setVehicles(JSONArray.fromObject(vehicleList).toString());
bean.setCases(JSONArray.fromObject(caseList).toString());
bean.setAlarmList(JSONArray.fromObject(alarmLists).toString());
bean.setMrzas("");
bean.setPawnshop(JSONArray.fromObject(pawnshops).toString());
bean.setDateTime(date);
context.write(null, new Text(bean.toCSV()));
} catch (CdCommonException e) {
logger.error(e, e);
} catch (Exception e) {
logger.error(e, e);
throw new IOException(e);
}
}
Presently preferred embodiments of the present invention is the foregoing is only, is not intended to limit the invention, it is all in the spirit and principles in the present inventionWithin, any modification, equivalent substitution and improvements made etc., it should be included in the scope of the protection.