搜索词>>iphone 耗时0.0010
  • iphone se2 运行内存多大

    最近苹果发布了一款新机 Iphone SE 二代最近苹果发布了一款新机 Iphone SE 二代。之前一直在猜测内存可能是3G.。通过一些软件,我们可以查询到确实如下:​​机器太新,很多检测APP还没上数据(或者说这款APP大多数数据靠手动录入的,假检查软件)
  • 屏蔽恶意蜘蛛_屏蔽垃圾蜘蛛_Nginx方式

    1.新增nginx屏蔽配置文件​文件暂时为/etc/nginx/conf.d/deny_ua.config说明:文件名deny_ua.config,后缀为.config非.conf,原因是.conf在conf.d目录下默认配置会扫描所有.c1.新增nginx屏蔽配置文件​文件暂时为/etc/nginx/conf.d/deny_ua.config说明:文件名deny_ua.config,后缀为.config非.conf,原因是.conf在conf.d目录下默认配置会扫描所有.conf文件。如果我们只希望某个站配置,则这里就不能用.conf2.deny_ua.config文件内容:  #forbidden UA if ($http_user_agent ~ "Bytespider|^$" ) {     return 403; }以上为禁用UA为空或者UA包含Bytespider的访问;如果需要屏蔽其他者修改"Bytespider|^$"  这一部分,例如屏蔽百度"BaiduSpider|Bytespider|^$" 3.在nginx对应的server片段引入配置 xxx.con.conf server{ .....其他省略.... include conf.d/deny_ua.config .....其他省略.... }  4.重启nginx nginx -s reload5.测试curl -A "Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.1547.1694 Mobile Safari/537.36; Bytespider" http://www.leftso.com <html> <head><title>403 Forbidden</title></head> <body bgcolor="white"> <center><h1>403 Forbidden</h1></center> <hr><center>nginx/1.10.2</center> </body> </html>  
  • Hibernate Search 入门配置及简单实用

    Hibernate Search 入门配置及简单实用,在本文中,我们将讨论Hibernate Search的基础知识,如何配置它,并且我们将实现一些简单的查询。<h2 style="margin-left:0px; margin-right:0px; text-align:start"><strong>1.概述</strong></h2> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">在本文中,我们将讨论Hibernate Search的基础知识,如何配置它,并且我们将实现一些简单的查询。</span></span></span><br />  </p> <h2 style="margin-left:0px; margin-right:0px; text-align:start"><strong>2. Hibernate搜索的基础知识</strong></h2> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">有些时候我们必须实现全文搜索功能,使用我们已经熟悉的工具总是优点。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">如果我们已经将Hibernate和JPA用于ORM,那么我们距离Hibernate Search只有一步之遥。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff"><strong>Hibernate Search集成了Apache Lucene,这是一种用Java编写的高性能和可扩展的全文搜索引擎库</strong>。这将Lucene的强大功能与Hibernate和JPA的简单性相结合。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">简而言之,我们只需要向我们的域类添加一些额外的注释,并且<strong>该工具将处理数据库/索引同步等问题。</strong></span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">Hibernate Search还提供了Elasticsearch集成; 然而,由于它仍处于实验阶段,我们将在这里重点介绍Lucene。</span></span></span></p> <h2 style="margin-left:0px; margin-right:0px; text-align:start"><strong>3.配置</strong></h2> <h3 style="margin-left:0px; margin-right:0px; text-align:start"><strong>3.1。Maven的依赖</strong></h3> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">我们首先需要将必要的依赖添加到我们的<em>pom.xml中</em>:</span></span></span></p> <pre> <code class="language-xml"><dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-search-orm</artifactId> <version>5.8.2.Final</version> </dependency></code></pre> <p style="margin-left:0px; margin-right:0px; text-align:start">为了简单起见,我们将使用H2作为我们的数据库:</p> <pre> <code class="language-xml"><dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <version>1.4.196</version> </dependency></code></pre> <h3 style="margin-left:0px; margin-right:0px; text-align:start"><strong>3.2。配置</strong></h3> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff"><strong>我们还必须指定Lucene应该存储索引的位置。</strong></span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">这可以通过属性  <em>hibernate.search.default.directory_provider完成</em>。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">我们将选择<em>文件系统</em>,这对我们的用例来说是最直接的选择。<a href="https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#search-configuration-directory" rel="external nofollow" style="box-sizing:border-box; color:#63b175; text-decoration:none" target="_blank">官方文档</a>中列出了更多选项  。 对于群集应用程序来说,<em>文件系统主</em> / <em>文件系统 - 从属</em>和  <em>无限大</em>是值得注意的,其中索引必须在节点之间同步。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">我们还必须定义索引将存储在其中的默认基本目录:</span></span></span></p> <pre> <code class="language-html">hibernate.search.default.directory_provider = filesystem hibernate.search.default.indexBase = /data/index/default</code></pre> <h2 style="margin-left:0px; margin-right:0px; text-align:start"><strong>4.模型类</strong></h2> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">配置完成后,我们现在准备指定我们的模型。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff"><strong>在JPA注解<em>@Entity</em>和<em>@Table</em>之上,我们必须添加  <em>@Indexed</em>注释。</strong>它告诉Hibernate Search实体<em>产品</em>将被索引。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff"><strong>之后,我们必须通过添加<em>@Field</em>注释来将所需的属性定义为可搜索的</strong>:</span></span></span></p> <pre> <code class="language-java">@Entity @Indexed @Table(name = "product") public class Product { @Id private int id; @Field(termVector = TermVector.YES) private String productName; @Field(termVector = TermVector.YES) private String description; @Field private int memory; // getters, setters, and constructors }</code></pre> <p style="margin-left:0px; margin-right:0px; text-align:start">该<em>termVector = TermVector.YES</em>  属性将需要“更多类似这样的”查询后。<br />  </p> <h2 style="margin-left:0px; margin-right:0px; text-align:start"><strong>5.构建Lucene索引</strong></h2> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">在开始实际查询之前,<strong>我们必须首先触发Lucene建立索引</strong>:</span></span></span></p> <pre> <code class="language-java">FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager); fullTextEntityManager.createIndexer().startAndWait();</code></pre> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff"><strong>在初始构建之后,Hibernate Search会负责保持索引是最新的</strong>。I. e。我们可以像往常一样通过<em>EntityManager</em>创建,操作和删除实体。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">注意:<strong>我们必须确保实体完全致力于数据库,然后才能被Lucene发现并编入索引</strong>(顺便说一下,这也是为什么我们的<a href="https://github.com/eugenp/tutorials/tree/master/persistence-modules/spring-hibernate-5" rel="external nofollow" style="box-sizing:border-box; color:#63b175; text-decoration:none" target="_blank">示例代码测试用例中</a>的初始测试数据导入来自专用的JUnit测试用例,用<em>@Commit</em>注解)。</span></span></span></p> <h2 style="margin-left:0px; margin-right:0px; text-align:start"><strong>6.构建和执行查询</strong></h2> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">现在,我们准备创建我们的第一个查询。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">在下一节中,<strong>我们将展示准备和执行查询的一般工作流程。</strong></span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">之后,我们将为最重要的查询类型创建一些示例查询。</span></span></span></p> <h3 style="margin-left:0px; margin-right:0px; text-align:start"><strong>6.1。用于创建和执行查询的一般工作流程</strong></h3> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff"><strong>一般来说准备和执行查询由四个步骤组成</strong>:</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">在第1步中,我们必须得到一个JPA <em>FullTextEntityManager,</em>并从中获得一个<em>QueryBuilder</em>:</span></span></span></p> <pre> <code class="language-java">FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(entityManager); QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory() .buildQueryBuilder() .forEntity(Product.class) .get(); 在第2步中,我们将通过Hibernate查</code></pre> 在第2步中,我们将通过Hibernate查询DSL创建一个Lucene查询: <pre> <code class="language-java">org.apache.lucene.search.Query query = queryBuilder .keyword() .onField("productName") .matching("iphone") .createQuery();</code></pre> <p style="margin-left:0px; margin-right:0px; text-align:start">在第3步中,我们将Lucene查询包装到一个Hibernate查询中:</p> <pre> <code class="language-java">org.hibernate.search.jpa.FullTextQuery jpaQuery = fullTextEntityManager.createFullTextQuery(query, Product.class);</code></pre> <p style="margin-left:0px; margin-right:0px; text-align:start">最后,在第4步中,我们将执行查询:</p> <pre> <code class="language-java">List<Product> results = jpaQuery.getResultList();</code></pre> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff"><em>注意</em>:默认情况下,Lucene按照相关性排序结果。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">步骤1,3和4对于所有查询类型都是相同的。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">在下文中,我们将重点关注第2步,即如何创建不同类型的查询。</span></span></span></p> <h3 style="margin-left:0px; margin-right:0px; text-align:start"><strong>6.2。关键字查询</strong></h3> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">最基本的用例是<strong>搜索一个特定的单词</strong>。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">这就是我们在前一节中已经做过的事情:</span></span></span></p> <pre> <code class="language-java">Query keywordQuery = queryBuilder .keyword() .onField("productName") .matching("iphone") .createQuery();</code></pre> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">在这里,<em>keyword()</em>指定我们正在寻找一个特定的单词,<em>onField()</em>告诉Lucene在哪里寻找和<em>匹配()</em>寻找什么。</span></span></span></p> <h3 style="margin-left:0px; margin-right:0px; text-align:start"><strong>6.3。模糊查询</strong></h3> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">模糊查询的工作方式与关键字查询相似,不同之处在于<strong>我们可以定义“模糊性”的限制</strong>,超过此<strong>限制</strong>,Lucene将接受这两个词作为匹配。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">通过<em>withEditDistanceUpTo()</em>,<strong>我们可以定义一个术语可能与另一个术语相差多少</strong>。它可以设置为0,1和2,默认值是2(<em>注意</em>:这个限制来自Lucene的实现)。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">通过  <em>withPrefixLength()</em>,我们可以定义前缀的长度,模糊性应该忽略它:</span></span></span></p> <pre> <code class="language-java">Query fuzzyQuery = queryBuilder .keyword() .fuzzy() .withEditDistanceUpTo(2) .withPrefixLength(0) .onField("productName") .matching("iPhaen") .createQuery();</code></pre> <h3 style="margin-left:0px; margin-right:0px; text-align:start"><strong>6.4。通配符查询</strong></h3> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">Hibernate Search还使我们能够执行通配符查询,即查询某个单词的一部分未知。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">为此,我们可以对单个字符使用“ <em>?”</em>,对任何字符序列使用“ <em>*”</em>:</span></span></span></p> <pre> <code>Query wildcardQuery = queryBuilder .keyword() .wildcard() .onField("productName") .matching("Z*") .createQuery();</code></pre> <h3 style="margin-left:0px; margin-right:0px; text-align:start"><strong>6.5。短语查询</strong></h3> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">如果我们想要搜索多个单词,我们可以使用短语查询。如果需要,我们可以使用<em>phrase()</em>和<em>withSlop()</em>来查找<strong>确切的或近似的句子</strong>。斜率因子定义了句子中允许的其他单词的数量:</span></span></span></p> <pre> <code class="language-java">Query phraseQuery = queryBuilder .phrase() .withSlop(1) .onField("description") .sentence("with wireless charging") .createQuery();</code></pre>   <h3 style="margin-left:0px; margin-right:0px; text-align:start"><strong>6.6。简单查询字符串查询</strong></h3> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">使用先前的查询类型,我们必须明确指定查询类型。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">如果我们想给用户更多的权力,我们可以使用简单的查询字符串查询:<strong>由此,他可以在运行时定义自己的查询</strong>。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">支持以下查询类型:</span></span></span></p> <ul style="list-style-type:disc"> <li>布尔型(使用“+”,或使用“|”,不使用“ - ”)</li> <li>前缀(前缀*)</li> <li>短语(“某个短语”)</li> <li>优先顺序(使用括号)</li> <li>模糊(fuzy〜2)</li> <li>短语查询附近的运算符(“某个短语”〜3)</li> </ul> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">以下示例将结合模糊,短语和布尔查询:</span></span></span></p> <pre> <code class="language-java">Query simpleQueryStringQuery = queryBuilder .simpleQueryString() .onFields("productName", "description") .matching("Aple~2 + \"iPhone X\" + (256 | 128)") .createQuery();</code></pre> <h3 style="margin-left:0px; margin-right:0px; text-align:start"><strong>6.7。范围查询</strong></h3> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff"><strong>范围查询搜索</strong> <strong>给定边界之间</strong><strong>的</strong><strong>值</strong>。这可以应用于数字,日期,时间戳和字符串:</span></span></span></p> <pre> <code class="language-java">Query rangeQuery = queryBuilder .range() .onField("memory") .from(64).to(256) .createQuery();</code></pre> <h3 style="margin-left:0px; margin-right:0px; text-align:start"><strong>6.8。更像此查询</strong></h3> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">我们最后的查询类型是“ <em>更像这个</em> ” - 查询。为此,我们提供了一个实体,<strong>Hibernate Search返回一个具有相似实体的列表</strong>,每个<strong>实体</strong>都具有相似性分数。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">如前所述,在这种情况下,我们的模型类中的  <em>TermVector = TermVector.YES</em>属性是必需的:它告诉Lucene在索引期间存储每个术语的频率。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">基于此,相似性将在查询执行时计算:</span></span></span></p> <pre> <code class="language-java">Query moreLikeThisQuery = queryBuilder .moreLikeThis() .comparingField("productName").boostedTo(10f) .andField("description").boostedTo(1f) .toEntity(entity) .createQuery(); List<Object[]> results = (List<Object[]>) fullTextEntityManager .createFullTextQuery(moreLikeThisQuery, Product.class) .setProjection(ProjectionConstants.THIS, ProjectionConstants.SCORE) .getResultList();</code></pre> <h3 style="margin-left:0px; margin-right:0px; text-align:start"><strong>6.9。搜索多个字段</strong></h3> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">到目前为止,我们只使用<em>onField()</em>创建了查询一个属性的查询。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">根据用例,<strong>我们还可以搜索两个或更多属性</strong>:</span></span></span></p> <pre> <code class="language-java">Query luceneQuery = queryBuilder .keyword() .onFields("productName", "description") .matching(text) .createQuery();</code></pre> 此外,<strong>我们可以指定要分别搜索的每个属性</strong>,例如,如果我们要为一个属性定义增强: <pre> <code class="language-java">Query moreLikeThisQuery = queryBuilder .moreLikeThis() .comparingField("productName").boostedTo(10f) .andField("description").boostedTo(1f) .toEntity(entity) .createQuery();</code></pre>   <h3 style="margin-left:0px; margin-right:0px; text-align:start"><strong>6.10。结合查询</strong></h3> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">最后,Hibernate Search还支持使用各种策略来组合查询:</span></span></span></p> <ul style="list-style-type:disc"> <li><em>应该:</em>查询应该包含子查询的匹配元素</li> <li><em>必须:</em>查询必须包含子查询的匹配元素</li> <li><em>MUST NOT</em>:查询不得包含子查询的匹配元素</li> </ul> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">聚合<strong>类似于布尔逻辑的<em>AND,OR</em>和<em>NOT</em></strong><em>。</em>但是,名称不同,强调它们对相关性也有影响。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">例如,两个查询之间的<em>SHOULD</em>类似于布尔<em>OR:</em>如果其中一个查询有匹配,则返回该匹配。</span></span></span></p> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">但是,如果两个查询匹配,则与只有一个查询匹配的情况相比,匹配的关联性会更高:</span></span></span></p> <pre> <code class="language-java">Query combinedQuery = queryBuilder .bool() .must(queryBuilder.keyword() .onField("productName").matching("apple") .createQuery()) .must(queryBuilder.range() .onField("memory").from(64).to(256) .createQuery()) .should(queryBuilder.phrase() .onField("description").sentence("face id") .createQuery()) .must(queryBuilder.keyword() .onField("productName").matching("samsung") .createQuery()) .not() .createQuery();</code></pre> <h2 style="margin-left:0px; margin-right:0px; text-align:start"><strong>7.总结</strong></h2> <p style="margin-left:0px; margin-right:0px; text-align:start"><span style="color:#535353"><span style="font-family:raleway"><span style="background-color:#ffffff">在本文中,我们讨论了Hibernate Search的基础知识,并展示了如何实现最重要的查询类型。更高级的功能可以在<a href="https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/" rel="external nofollow" style="box-sizing:border-box; color:#63b175; text-decoration:none" target="_blank">官方文档中</a>找到 。</span></span></span></p>