jitenderrawal / laravel-solarium
用于使用 Solarium 的 Laravel 框架包
Requires
- php: >=5.3.0
- illuminate/support: 4.*
- solarium/solarium: ~3.2
This package is not auto-updated.
Last update: 2024-09-20 19:35:12 UTC
README
用于使用 Solarium 的 Laravel 框架包
功能
- 观察应用程序的模型以进行插入、更新和删除,并在 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 服务器,如果配置正确,应该可以在
获取 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
编辑配置文件。