网站开发容易找工作吗,精品课程网站开发,自助下单网站咋做,wordpress 5.2solr字段类型 类说明BinaryField二进制数据BoolField布尔值#xff0c;其中’t’/’T’/’1’都是trueCollationFiled支持Unicode排序CurrencyField支持货币和汇率DateRangeFiled支持索引date rangeExternamFiledFiledpull磁盘上的文件EnumField支持定义枚举值ICUCollationFie…solr字段类型 类说明BinaryField二进制数据BoolField布尔值其中’t’/’T’/’1’都是trueCollationFiled支持Unicode排序CurrencyField支持货币和汇率DateRangeFiled支持索引date rangeExternamFiledFiledpull磁盘上的文件EnumField支持定义枚举值ICUCollationField支持Unicode排序LatLonType支持经度、纬度坐标PointType支持任意的n维向量可以用于检索CAD图数据PreAnalyzedField用于支持序列化数据RandomSortField结果随机排序SpatialRecursivePrefixTreeFieldType支持经纬度字符串或WKT格式StrField字符串不分词并且小于32kTextField文本字段,既分词又索引TrieDateField日期类型字段TrieDoubleField双精度类型字段TrieField使用时必须指定”type”属性integer,long,double,dateTrieFloatField单精度类型字段TrieIntField整数字段TrieLongField长整形字段UUIDFieldUniversally Unique Identifier通用唯一识别码Date fields fieldType nametdate classsolr.TrieDateField omitNormstrue
precisionStep6 positionIncrementGap0/ 当你要用到日期的范围查询时最好用这样的数据类型而且在提交文档时日期的格式有特别要求日期里有T,Z字符比如有个timestamp字段设置为tdate类型了那么提交时应该 add
doc
...
field nametimestamp2012-05-22T09:30:22Z/field
...
/doc
/add 不需要查询精确到分秒级别时 field nametimestamp2016-05-22T09:30:22Z/HOUR/field 域类型的定义说明(fieldType) 一个solr自带的域类型 打开自己配置的SolrCore的collection1\conf\schema.xml !-- FieldType子结点包括name,class,positionIncrementGap等一些参数name是这个FieldType的名称class是Solr提供的包solr.TextFieldsolr.TextField 允许用户通过分析器来定制索引和查询分析器包括一个分词器tokenizer和多个过滤器filterpositionIncrementGap可选属性定义在同一个文档中此类型数据的空白间隔避免短语匹配错误此值相当于Lucene的短语查询设置slop值根据经验设置为100。在FieldType定义的时候最重要的就是定义这个类型的数据在建立索引和进行查询的时候要使用的分析器analyzer,包括分词和过滤索引分析器中使用solr.StandardTokenizerFactory标准分词器solr.StopFilterFactory停用词过滤器solr.LowerCaseFilterFactory小写过滤器。
搜索分析器中使用solr.StandardTokenizerFactory标准分词器solr.StopFilterFactory停用词过滤器这里还用到了solr.SynonymFilterFactory同义词过滤器。--fieldType nametext_general classsolr.TextField positionIncrementGap100!--索引分析器 --analyzer typeindextokenizer classsolr.StandardTokenizerFactory/filter classsolr.StopFilterFactory ignoreCasetrue wordsstopwords.txt /!-- in this example, we will only use synonyms at query timefilter classsolr.SynonymFilterFactory synonymsindex_synonyms.txt ignoreCasetrue expandfalse/--filter classsolr.LowerCaseFilterFactory//analyzer!--搜索分析器 --analyzer typequerytokenizer classsolr.StandardTokenizerFactory/filter classsolr.StopFilterFactory ignoreCasetrue wordsstopwords.txt /filter classsolr.SynonymFilterFactory synonymssynonyms.txt ignoreCasetrue expandtrue/filter classsolr.LowerCaseFilterFactory//analyzer/fieldType 自定义Field(域) 打开自己配置的SolrCore的collection1\conf\schema.xml 添加以下内容,就可以使用这个域了 !-- 自定义field
filed定义包括,
name 域对象
type为之前定义过的各种FieldType,
indexed是否被索引,
stored是否被储存
multiValued是否存储多个值等属性
multiValued该Field如果要存储多个值时设置为truesolr允许一个Field存储多个值比如存储一个用户的好id多个商品的图片多个大图和小图
required 必须存在,一般用在主键id
--
field namemyname typetext_general indexedtrue storedtrue multiValuedtrue requiredtrue / copy域 运用领域: name:nikeT恤 描述:一件运动T恤 当需要只搜索一次两个域的任意内容时, 就能把两个东西都搜索出来的时候 就把多个域放到一个拷贝域里面 copyField sourcecat desttext/copyField sourcename desttext/copyField sourcemanu desttext/copyField sourcetitle desttext/ 查询 过滤条件查询 product_price:[1 TO 10]过滤查询价格从1到10的商品
也可以使用“*”表示无限例如
20以上product_price:[20 TO *]
20以下product_price:[* TO 20] 降序升序查询 product_price desc
product_price asc 更新/修改 {id:change.me,title:change.me} 删除 根据id删除 delete
idchange.me/id
/delete
commit/ ### 条件删除 delete
queryid:change.me/query
/delete
commit/ 多值字段 必须先定义 multiValuedtrue 的类型的域才可以插入多值 {id:change.me,title:6666,777,888} 定义中文分词器 1 把IKAnalyzer2012FF_u1.jar拷贝到\webapps\solr\WEB-INF\lib下 2 把ik分词器的3个配置文件拷贝到webapps\solr\WEB-INF\classes下 3 在schema.xml中添加自定义分词器 !-- IKAnalyzer 中文分词器--fieldType nametext_ik classsolr.TextFieldanalyzer classorg.wltea.analyzer.lucene.IKAnalyzer//fieldType!--把IK中文分词器添加到一个域--field nametitle_ik typetext_ik indexedtrue storedtrue /field namecontent_ik typetext_ik indexedtrue storedfalse multiValuedtrue/ 导入 批量导入SQL的数据 1.在自定义的solrcore\collection1\lib下面添加dataimport插件依赖的jar和sql的驱动jar 2.根据数据库字段,字段类型等,在中定义字段在solr中存在的形态,比如是否索引,是否分词等 !--product字段的声明--
!-- 根据实际情况来确定是否需要被索引,是否被储存,和选择不同的类型(type)来确定分词--field nameproduct_name typetext_ik indexedtrue storedtrue/field nameproduct_price typefloat indexedtrue storedtrue/field nameproduct_description typetext_ik indexedtrue storedfalse /field nameproduct_picture typestring indexedfalse storedtrue /field nameproduct_catalog_name typestring indexedtrue storedtrue /field nameproduct_keywords typetext_ik indexedtrue storedfalse multiValuedtrue/copyField sourceproduct_name destproduct_keywords/copyField sourceproduct_description destproduct_keywords/3.在collection1\conf\下的solrconfig.xml文件添加一个requestHandler requestHandler name/dataimport
classorg.apache.solr.handler.dataimport.DataImportHandlerlst namedefaultsstr nameconfigdata-config.xml/str/lst/requestHandler 4.创建一个data-config.xml保存到collection1\conf\目录下 ?xml version1.0 encodingUTF-8 ?
dataConfig
dataSource typeJdbcDataSource drivercom.mysql.jdbc.Driver urljdbc:mysql://localhost:3306/solr userroot passwordroot/
document entity nameproduct querySELECT pid,name,catalog_name,price,description,picture FROM products field columnpid nameid/ field columnname nameproduct_name/ field columncatalog_name nameproduct_catalog_name/ field columnprice nameproduct_price/ field columndescription nameproduct_description/ field columnpicture nameproduct_picture/ /entity
/document
/dataConfig 5.重启Tomcat,进入solr主页 ,选中SolrCore,就是collection1,查看DataImport点击Execute执行导入,导入后可在query里面查看 solr实例(solrcore)截图和solr服务器截图 一个solrhome可以包含多个solecore就是多个collection1 solrj solrj是java客户端访问solr服务的工具,可以在java代码中实现搜索 参考自己写的一个demo: 转载于:https://www.cnblogs.com/AngeLeyes/p/7337931.html