linnhtun/laravel-5-solarium

Laravel 框架的 Solarium 包。只需将 illuminate/support 依赖项更改为 5.*,即可使其在 Laravel 5.* 上运行,并已移除分页功能

v0.1.6 2016-08-04 10:48 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:31:15 UTC


README

我对这个包没有任何贡献,原始包由 "Zenek Palmer" 开发,原始仓库可以在这里找到。我只是将 illuminate/support 依赖项从版本 4.* 更改为 5.*,以便在我的项目中使用。我没有时间正式请求许可,而且我急需它。如果这给任何人带来不便,请谅解。

Laravel-Solarium

Laravel 框架的 Solarium 包

功能

  • 监视您的应用程序模型以进行插入、更新和删除,并将数据存储在 Solr 索引中
  • 支持多个 Solr 核心可以,使您可以将不同的模型保存到不同的核心,或者将相同的模型保存到多个核心。如果您应用程序中有多处搜索功能,例如产品搜索功能和通用网站搜索,这将非常有用。
  • 包含用于查询网站搜索核心的路由(可配置 URI)和控制器。
  • 包含示例网站搜索结果视图,如果您需要,您可以使用它,但您可能只想使用部分视图...
  • 网站搜索表单的部分视图,您可以在布局页眉中包含它
  • 网站搜索结果的部分视图,您可以从您自定义的搜索结果视图中包含它

安装

设置 Solr

下载最新版本的 solr: http://lucene.apache.org/solr/

解包: tar xvzf solr-4.*.*.tgz

复制示例目录并将其重命名为 "site-search",在这种情况下

然后将 collection1 目录重命名为您想要的索引名称。

在这种情况下,索引将称为 search。

如果您需要多个索引,则复制并重命名 site-search 文件夹。

然后更新 solr.xml 文件,以告诉 Solr 服务器您有多少个索引以及它们的名称。

例如

<?xml version="1.0" encoding="UTF-8" ?>

<solr persistent="false">

  <cores adminPath="/admin/cores" host="${host:}" hostPort="${jetty.port:8983}" hostContext="${hostContext:solr}">
    <core name="search" instanceDir="search" />
    <!-- only include this is you have created the second index folder -->
    <core name="index2" instanceDir="index2" />
  </cores>

  <shardHandlerFactory name="shardHandlerFactory"
    class="HttpShardHandlerFactory">
    <int name="socketTimeout">${socketTimeout:0}</int>
    <int name="connTimeout">${connTimeout:0}</int>
  </shardHandlerFactory>

</solr>

现在,对于每个创建的索引文件夹,您需要更新索引配置文件夹中的 schema.xml 和 solrconfig.xml 文件。

示例 schema.xml 文件

<?xml version="1.0" ?>
<schema name="search" version="1.1">
  <types>
    <fieldType name="string"  class="solr.StrField"  sortMissingLast="true" omitNorms="true" />
    <fieldType name="long"    class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
  </types>

  <fields>
    <field name="id"              type="string"  indexed="true"  stored="true"  multiValued="false" required="true"/>
    <field name="model_id"        type="string"  indexed="true"  stored="true"  multiValued="false" />
    <field name="model_name"      type="string"  indexed="true"  stored="true"  multiValued="false" />
    <field name="title"           type="string"  indexed="true"  stored="true"  multiValued="false" />
    <field name="content"         type="string"  indexed="true"  stored="true"  multiValued="false" />
    <field name="search_content"  type="string"  indexed="true"  stored="true"  multiValued="false" />
    <field name="published_date"  type="string"  indexed="true"  stored="true"  multiValued="false" />
    <field name="archive_date"    type="string"  indexed="true"  stored="true"  multiValued="false" />
    <field name="status"          type="string"  indexed="true"  stored="true"  multiValued="false" />
    <field name="url"             type="string"  indexed="true"  stored="true"  multiValued="false" />
    <field name="_version_"       type="long"    indexed="true"  stored="true"/>
  </fields>

  <!-- field to use to determine and enforce document uniqueness. -->
  <uniqueKey>id</uniqueKey>

  <!-- field for the QueryParser to use when an explicit fieldname is absent -->
  <defaultSearchField>title</defaultSearchField>

  <!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
  <solrQueryParser defaultOperator="OR"/>
</schema>

示例 solrconfig.xml

这最好通过复制提供的示例目录中的匹配文件夹来创建。

<?xml version="1.0" encoding="UTF-8" ?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
 contributor license agreements.  See the NOTICE file distributed with
 this work for additional information regarding copyright ownership.
 The ASF licenses this file to You under the Apache License, Version 2.0
 (the "License"); you may not use this file except in compliance with
 the License.  You may obtain a copy of the License at

     https://apache.ac.cn/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->

<!--
 This is a stripped down config file used for a simple example...
 It is *not* a good example to work from.
-->
<config>
  <luceneMatchVersion>4.5</luceneMatchVersion>
  <!--  The DirectoryFactory to use for indexes.
        solr.StandardDirectoryFactory, the default, is filesystem based.
        solr.RAMDirectoryFactory is memory based, not persistent, and doesn't work with replication. -->
  <directoryFactory name="DirectoryFactory" class="${solr.directoryFactory:solr.StandardDirectoryFactory}"/>

  <dataDir>${solr.search.data.dir:}</dataDir>

  <!-- To enable dynamic schema REST APIs, use the following for <schemaFactory>:

       <schemaFactory class="ManagedIndexSchemaFactory">
         <bool name="mutable">true</bool>
         <str name="managedSchemaResourceName">managed-schema</str>
       </schemaFactory>

       When ManagedIndexSchemaFactory is specified, Solr will load the schema from
       he resource named in 'managedSchemaResourceName', rather than from schema.xml.
       Note that the managed schema resource CANNOT be named schema.xml.  If the managed
       schema does not exist, Solr will create it after reading schema.xml, then rename
       'schema.xml' to 'schema.xml.bak'.

       Do NOT hand edit the managed schema - external modifications will be ignored and
       overwritten as a result of schema modification REST API calls.

       When ManagedIndexSchemaFactory is specified with mutable = true, schema
       modification REST API calls will be allowed; otherwise, error responses will be
       sent back for these requests.
  -->
  <schemaFactory class="ClassicIndexSchemaFactory"/>

  <updateHandler class="solr.DirectUpdateHandler2">
    <updateLog>
      <str name="dir">${solr.search.data.dir:}</str>
    </updateLog>
  </updateHandler>

  <!-- realtime get handler, guaranteed to return the latest stored fields
    of any document, without the need to commit or open a new searcher. The current
    implementation relies on the updateLog feature being enabled. -->
  <requestHandler name="/get" class="solr.RealTimeGetHandler">
    <lst name="defaults">
      <str name="omitHeader">true</str>
    </lst>
  </requestHandler>

  <requestHandler name="/replication" class="solr.ReplicationHandler" startup="lazy" />

  <requestDispatcher handleSelect="true" >
    <requestParsers enableRemoteStreaming="false" multipartUploadLimitInKB="2048" formdataUploadLimitInKB="2048" />
  </requestDispatcher>

  <requestHandler name="standard" class="solr.StandardRequestHandler" default="true" />
  <requestHandler name="/analysis/field" startup="lazy" class="solr.FieldAnalysisRequestHandler" />
  <requestHandler name="/update" class="solr.UpdateRequestHandler"  />
  <requestHandler name="/admin/" class="org.apache.solr.handler.admin.AdminHandlers" />

  <requestHandler name="/admin/ping" class="solr.PingRequestHandler">
    <lst name="invariants">
      <str name="q">solrpingquery</str>
    </lst>
    <lst name="defaults">
      <str name="echoParams">all</str>
    </lst>
  </requestHandler>

  <!-- config for the admin interface -->
  <admin>
    <defaultQuery>solr</defaultQuery>
  </admin>

</config>

您还需要更新索引文件夹中的 core.properties 文件。

内容非常简单,例如

name=search

然后,在索引目录中运行 sudo java -jar start.jar

这将启动 Solr 服务器,如果配置正确,应该可在

https://:8983/solr/#/search

获取 laravel-solarium 包

如果您使用 composer,请将以下内容添加到您的 composer.json 文件中

"require": {
  "fbf/laravel-solarium": "dev-master"
},

然后执行 composer update

app/config/app.php 中添加 ServiceProvider

'Fbf\LaravelSolarium\LaravelSolariumServiceProvider'

发布配置文件

php artisan config:publish fbf/laravel-solarium

编辑配置文件。