当前位置:网站首页>Solr search
Solr search
2022-06-30 06:47:00 【Sunny husband】
solr Is based on Lucene Enterprise search server , Put it war Package is deployed in web You can run directly in the container
java operation solr Use solrJ(solr Of java client ),spring data solr frame ( Encapsulates the solrJ) Provides solrTemplate Simplify the development of search services
The content we can search through the search engine is stored in the index library , So you can see the stored content after searching , So these must create domains (field), The stored content does not have to be indexed , Maybe just showing , Such as images , What is stored is a picture url, No one will search this url Also not to url Perform sorting and other operations , So the image field only stores images without indexing
The search process can be simplified , A primitive understanding , Is to query what I want from the database sku data , This process is not restricted by database search , We can search wherever we want , And it has multiple conditions at the same time . What comes out is certainly not a specific , But a relatively specific , Including the brand price range, specifications and models , We can choose more specifically by clicking in .
So I understand , Which domains to set
among id This domain solr It has been defined , It's the only one , We don't define it , But in JavaBean You still need to make notes in id Add up @Field annotation , If the incoming bean There is no id It's a mistake
title ( Search and display )
brand ( Search and display )
Price ( Search for ( For example, search according to the price range ) And display )
picture ( Show )
Brand classification ( Search and display )
The seller ( Search for ( The brand and the seller are not necessarily the same , For example, Huawei is both a seller and a brand , But glory is the seller's brand , If you search Huawei, you will find many Huawei brands ) And display )
spuid( Although not shown to the user , But got , And enter the product details page according to it )
Copying a domain is to copy the values of other domains to this domain , The replication domain is no longer stored , Because other domains already store , Replication domains are multivalued , Because it doesn't make sense to replicate a domain .
For example, I created a project called keywords Replication domain for , Put the title , brand , The seller , The contents of the category field are copied , Then I enter a keyword in the search box , Then it can search results from multiple domains
Dynamic domains are constantly changing domains , Such as specifications , There's a lot of , Such as The Internet :5G Color : Red
In this way, a domain represents all kinds of possibilities , Dynamic adjustment
Use spring-data-solr First, import. spring-data-solr Of jar package Then create solr Of spring The configuration file ( Define two bean) It's equipped with solrTemplate And what it depends on solrServer
In the revision of schema After the configuration file ,solr Server restart will take effect . In addition, the addition, deletion and modification operations must be submitted to take effect
solrTemplate.saveBean(object) Add or modify data
solrTemplate.getById(1, TbItem.class) according to id Inquire about
solrTemplate.deleteById(“1”); Delete... According to the primary key
solrTemplate.saveBeans(list) Save collection , Set to store objects
solrTemplate.queryForPage(query, TbItem.class); Paging query
query Query criteria object Query query=new SimpleQuery(":"); Query all query.setOffset(20);// Start index ( Default 0) query.setRows(20);// Records per page ( Default 10)
Criteria criteria =new Criteria (“item_title”)contains(“2”); Create a query condition object query.addCriteria(criteria); Add the query criteria object to the query criteria
Query query=new SimpleQuery(":"); solrTemplate.delete(query); Delete according to the query object
When we highlight some fields in the search , The front page will be displayed as it is html Content , This is because Angularjs To prevent html Security measures taken for attacks , We can use s c e clothing service in Of t r u s t A S h t m l ( d a t a ) Fang Law Come on Yes this h t m l Into the That's ok discharge That's ok but yes Examination Consideration To this work can yes One individual through use Of work can , the With straight Pick up take it set The righteous To One individual too filter device in a p p . f i l t e ( ′ too filter device Of name word ′ , [ ′ sce In service trustAShtml(data) Methods to this html Release But considering that this function is a general function , So define it directly into a filter app.filte(' The name of the filter ',[' sce clothing service in Of trustAShtml(data) Fang Law Come on Yes this html Into the That's ok discharge That's ok but yes Examination Consideration To this work can yes One individual through use Of work can , the With straight Pick up take it set The righteous To One individual too filter device in app.filte(′ too filter device Of name word ′,[′sce’,function($sce){
return function(data){
return $sce.trustAsHtml(data);
}
}])
Use... On the page ng-bind-html=“item.title | The name of the filter ” Call the filter
service The layer can also call service layer , But what is called must be started first , Judge redis Is there any one key It can be used hasKey To judge
Search out the content to be displayed according to the keyword , And highlight , This is a basic search . We want to show the classification of the search content , The searched content has the field of classification , Let's query the category field separately , Then get the value of the group and put it into a classification set , Classification set and highlight set are our resultMap A value of , Show the brand later , The specifications are all added to resultMap Medium will do .
After obtaining the commodity classification, you can find the template according to the classification id, According to the template id You can also find information about brands and specifications , After processing, we get the data we want , Put it in resultMap in .
Because the template id Query for , Too many queries about brand specifications , We store it in redis in , And then from redis Get data in , To reduce the pressure of database access ( Be careful redis Storage problems , Guarantee redis The data in are all up-to-date , Synchronize with database , Therefore, when adding, deleting and modifying, it is necessary to store them in the third category , We can go back to redis The stored code is written in the query all , Query once after adding, deleting and modifying , Every update can be guaranteed redis The data in are all up-to-date )
redis-server.exe redis.windows.conf windows in redis Start command for loading configuration file , Be sure to log in with administrator privileges cmd In the implementation of
It's going on solr When querying , Each query criteria object query All need to have a criteria Conditions of the object , But there can only be one . Each query has only one master query object , All of them are filter query objects ( It also has its own criteria object ), Must be added to the main query object
When searching the page for queries , The display of commodity classification is only based on keyword query , Do not consider the subsequent conditions , By default, I display the specifications and brands of the first category , If the classification is passed , According to the classification of biography , The code in the highlighted part is our theme display code , You need to add filter conditions here
solr Remember to submit after the call solrtemplate.commit(); The calling of services should have a clear division of labor , Unified by controller Call the service layer , Each service layer is responsible for its own business , Don't mix with each other
边栏推荐
- Judge whether H5 is in wechat environment or enterprise wechat environment at both ends
- 1.9 - 存储器的分类
- ROS-URDF
- Improve simulation speed during ROS and Px4 joint simulation
- Image processing 7- image enhancement
- Picture.....
- Ls1028 manual
- Four tips in numpy
- 手机开户一般哪个证券公司好?还有,在线开户安全么?
- RT thread Kernel Implementation (III): implementation of idle threads and blocking delay
猜你喜欢
![[fuzzy neural network] mobile robot path planning based on Fuzzy Neural Network](/img/39/c9bf235828b6d50e7931876fa4a918.png)
[fuzzy neural network] mobile robot path planning based on Fuzzy Neural Network

Analysis of startup process of gazebo multi computer simulation

Picture.....

【转】存储器结构、cache、DMA架构分析

InnoDB engine in MySQL

Force buckle ------ replace blank space

不忘初心,能偷懒就偷懒:C#操作Word文件

程序猿入门攻略(十一)——结构体

记录一次腾讯测试开发工程师自动化接口测试实践经验

0 basic job transfer software test, how to achieve a monthly salary of 9.5k+
随机推荐
1.7 - CPU的性能指标
Basic questions (I)
gazebo/set_ model_ State topic driving UAV model through posture
史上最全一句话木马
成品升级程序
RT thread application
Fastapi learning Day2
手机开户一般哪个证券公司好?还有,在线开户安全么?
Rising posture series: fancy debugging information
Idea add database
Idea run SQL file
KEIL - 下载调试出现“TRACE HW not present”
Rhcsa day 3
Why does the verification code not refresh when clicked
Which securities company is good for opening a mobile account? Also, is it safe to open an account online?
1.9 - Classification of memory
Huawei full-scale Daniel shared the 598 page full-color Manual of network protocols for the first time
Traitement d'images 7 - amélioration d'images
Pycharm shortcut key
C # - C # process and convert pixeldata of CT images with fo DICOM