FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
339
sites/all/modules/contrib/search/search_api_multi/LICENSE.txt
Normal file
339
sites/all/modules/contrib/search/search_api_multi/LICENSE.txt
Normal file
@@ -0,0 +1,339 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
38
sites/all/modules/contrib/search/search_api_multi/README.txt
Normal file
38
sites/all/modules/contrib/search/search_api_multi/README.txt
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
Multi-index searches
|
||||
--------------------
|
||||
|
||||
This module allows you to create search queries on multiple indexes that lie on
|
||||
the same server. The only thing you'll need is a search service class that
|
||||
supports the "search_api_multi" feature. Currently, only the "Solr search"
|
||||
supports this.
|
||||
|
||||
|
||||
|
||||
Information for users
|
||||
---------------------
|
||||
|
||||
Enable the Search views (search_api_views) module along with this one to make
|
||||
instant use of the multi-index searching facilities. You'll get a new base table
|
||||
in Views for each server supporting the "search_api_multi" feature.
|
||||
You can then add filters, arguments, fields and sorts (although the last one
|
||||
might work rather poorly, depending on the sorted field and the implementation)
|
||||
from all enabled indexes on this server.
|
||||
|
||||
- Issues
|
||||
|
||||
If you find any bugs or shortcomings while using this module, please file an
|
||||
issue in the project's issue queue [1].
|
||||
|
||||
[1] http://drupal.org/project/issues/search_api_multi
|
||||
|
||||
|
||||
|
||||
Information for developers
|
||||
--------------------------
|
||||
|
||||
If you are the developer of a SearchApiServiceInterface implementation and want
|
||||
to support searches on multiple indexes with your service class, too, you'll
|
||||
have to support the "search_api_multi" feature by implementing the
|
||||
SearchApiMultiServiceInterface interface documented in
|
||||
search_api_multi.service.inc.
|
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Hooks provided by the Search API multi-index searches module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @addtogroup hooks
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Lets modules alter a search query before executing it.
|
||||
*
|
||||
* @param SearchApiMultiQueryInterface $query
|
||||
* The executed search query.
|
||||
*/
|
||||
function hook_search_api_multi_query_alter(SearchApiMultiQueryInterface $query) {
|
||||
$query->condition('#', 0, '!=');
|
||||
}
|
||||
|
||||
/**
|
||||
* @} End of "addtogroup hooks".
|
||||
*/
|
@@ -0,0 +1,19 @@
|
||||
|
||||
name = Multi-index searches
|
||||
description = Small extension for the Search API that allows searches across several indexes on the same server.
|
||||
dependencies[] = search_api
|
||||
core = 7.x
|
||||
package = Search
|
||||
|
||||
files[] = search_api_multi.query.inc
|
||||
files[] = search_api_multi.service.inc
|
||||
files[] = views/handler_argument_fulltext.inc
|
||||
files[] = views/handler_filter_fulltext.inc
|
||||
files[] = views/query.inc
|
||||
|
||||
; Information added by drupal.org packaging script on 2012-06-22
|
||||
version = "7.x-1.0-beta3+2-dev"
|
||||
core = "7.x"
|
||||
project = "search_api_multi"
|
||||
datestamp = "1340325572"
|
||||
|
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_views_api().
|
||||
*/
|
||||
function search_api_multi_views_api() {
|
||||
if (module_exists('search_api_views')) {
|
||||
return array(
|
||||
'api' => '3.0-alpha1',
|
||||
'path' => drupal_get_path('module', 'search_api_multi') . '/views',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_search_api_server_enabled().
|
||||
*/
|
||||
function search_api_multi_search_api_server_enabled(array $servers) {
|
||||
if (!module_exists('search_api_views')) {
|
||||
return;
|
||||
}
|
||||
foreach ($servers as $server) {
|
||||
if ($server->supportsFeature('search_api_multi')) {
|
||||
// Make the new server(s) available for views.
|
||||
views_invalidate_cache();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_search_api_server_update().
|
||||
*/
|
||||
function search_api_multi_search_api_server_update(SearchApiServer $server) {
|
||||
if (module_exists('search_api_views') && $server->supportsFeature('search_api_multi') && !$server->enabled && $server->original->enabled) {
|
||||
_search_api_multi_server_unavailable($server);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_search_api_server_delete().
|
||||
*/
|
||||
function search_api_multi_search_api_server_delete(SearchApiServer $server) {
|
||||
if (module_exists('search_api_views') && $server->supportsFeature('search_api_multi')) {
|
||||
_search_api_multi_server_unavailable($server);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for reacting to a disabled or deleted search server.
|
||||
*/
|
||||
function _search_api_multi_server_unavailable(SearchApiServer $server) {
|
||||
$names = array();
|
||||
$table = 'search_api_server_' . $server->machine_name;
|
||||
foreach (views_get_all_views() as $name => $view) {
|
||||
if (empty($view->disabled) && $view->base_table == $table) {
|
||||
$names[] = $name;
|
||||
// @todo: if ($server_deleted) $view->delete()?
|
||||
}
|
||||
}
|
||||
if ($names) {
|
||||
views_invalidate_cache();
|
||||
drupal_set_message(t('The following views were using the server %name: @views. You should disable or delete them.', array('%name' => $server->name, '@views' => implode(', ', $names))), 'warning');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a multi-index search query on a specified search server.
|
||||
*
|
||||
* @param $id
|
||||
* The ID or machine name of the index to execute the search on.
|
||||
* @param array $options
|
||||
* Associative array of options configuring this query. Recognized options
|
||||
* are:
|
||||
* - conjunction: The type of conjunction to use for this query - either
|
||||
* 'AND' or 'OR'. 'AND' by default. This only influences the search keys,
|
||||
* filters will always use AND by default.
|
||||
* - 'parse mode': The mode with which to parse the $keys variable, if it
|
||||
* is set and not already an array. See SearchApiMultiQuery::parseModes() for
|
||||
* recognized parse modes.
|
||||
* - languages: The languages to search for, as an array of language IDs.
|
||||
* If not specified, all languages will be searched. Language-neutral
|
||||
* content (LANGUAGE_NONE) is always searched.
|
||||
* - offset: The position of the first returned search results relative to
|
||||
* the whole result on the server.
|
||||
* - limit: The maximum number of search results to return. -1 means no
|
||||
* limit.
|
||||
* - 'filter class': Can be used to change the SearchApiQueryFilterInterface
|
||||
* implementation to use.
|
||||
* - 'search id': A string that will be used as the identifier when storing
|
||||
* this search in the static cache.
|
||||
* All options are optional.
|
||||
*
|
||||
* @return SearchApiMultiQueryInterface
|
||||
* An object for searching on the specified server.
|
||||
*/
|
||||
function search_api_multi_query($id, array $options = array()) {
|
||||
$server = search_api_server_load($id);
|
||||
if (!$server) {
|
||||
throw new SearchApiException(t('Unknown server with ID @id.', array('@id' => $id)));
|
||||
}
|
||||
if (!$server->supportsFeature('search_api_multi')) {
|
||||
throw new SearchApiException(t("The search server @name doesn't support multi-index searches.", array('@name' => $server->name)));
|
||||
}
|
||||
return $server->queryMultiple($options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Static store for the multi-index searches executed on the current page. Can
|
||||
* either be used to store an executed search, or to retrieve a previously
|
||||
* stored search.
|
||||
*
|
||||
* @param $search_id
|
||||
* For pages displaying multiple searches, an optional ID identifying the
|
||||
* search in questions. When storing a search, this is filled automatically,
|
||||
* unless it is manually set.
|
||||
* @param SearchApiMultiQuery $query
|
||||
* When storing an executed search, the query that was executed. NULL
|
||||
* otherwise.
|
||||
* @param array $results
|
||||
* When storing an executed search, the returned results as specified by
|
||||
* SearchApiMultiQueryInterface::execute(). An empty array, otherwise.
|
||||
*
|
||||
* @return array
|
||||
* If a search with the specified ID was executed, an array containing
|
||||
* ($query, $results) as used in this function's parameters. If $search_id is
|
||||
* NULL, an array of all executed searches will be returned, keyed by ID.
|
||||
*/
|
||||
function search_api_multi_current_search($search_id = NULL, SearchApiMultiQuery $query = NULL, array $results = array()) {
|
||||
$searches = &drupal_static(__FUNCTION__, array());
|
||||
|
||||
if (isset($query)) {
|
||||
if (!isset($search_id)) {
|
||||
$search_id = $query->getOption('search id');
|
||||
}
|
||||
$base = $search_id;
|
||||
$i = 0;
|
||||
while (isset($searches[$search_id])) {
|
||||
$search_id = $base . '-' . ++$i;
|
||||
}
|
||||
$searches[$search_id] = array($query, $results);
|
||||
}
|
||||
|
||||
if (isset($searches[$search_id])) {
|
||||
return $searches[$search_id];
|
||||
}
|
||||
return $searches;
|
||||
}
|
@@ -0,0 +1,863 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Interface representing a search query on multiple Search API indexes on the
|
||||
* same server. The server has to support the "search_api_multi" feature.
|
||||
*
|
||||
* For discerning from which index a certain field should be used (for filtering
|
||||
* or specifying the fulltext fields, fr instance), all field identifiers have
|
||||
* to be prefixed with their index' machine name, seperated by a colon.
|
||||
* For example, to filter on the "author:name" field from the index with the
|
||||
* machine name "default_node_index", use "default_node_index:author:name" as
|
||||
* the identifier.
|
||||
*
|
||||
* Methods not returning something else will return the object itself, so calls
|
||||
* can be chained.
|
||||
*/
|
||||
interface SearchApiMultiQueryInterface {
|
||||
|
||||
/**
|
||||
* Constructor used when creating SearchApiMultiQueryInterface objects.
|
||||
*
|
||||
* @param SearchApiServer $server
|
||||
* The server this search will be executed on.
|
||||
* @param array $options
|
||||
* Associative array of options configuring this query. Recognized options
|
||||
* are:
|
||||
* - conjunction: The type of conjunction to use for this query - either
|
||||
* 'AND' or 'OR'. 'AND' by default. This only influences the search keys,
|
||||
* filters will always use AND by default.
|
||||
* - 'parse mode': The mode with which to parse the $keys variable, if it
|
||||
* is set and not already an array. See SearchApiMultiQuery::parseModes() for
|
||||
* recognized parse modes.
|
||||
* - languages: The languages to search for, as an array of language IDs.
|
||||
* If not specified, all languages will be searched. Language-neutral
|
||||
* content (LANGUAGE_NONE) is always searched.
|
||||
* - offset: The position of the first returned search results relative to
|
||||
* the whole result on the server.
|
||||
* - limit: The maximum number of search results to return. -1 means no
|
||||
* limit.
|
||||
* - 'filter class': Can be used to change the SearchApiQueryFilterInterface
|
||||
* implementation to use.
|
||||
* - 'search id': A string that will be used as the identifier when storing
|
||||
* this search in the static cache.
|
||||
* All options are optional.
|
||||
*
|
||||
* @throws SearchApiException
|
||||
* If a search with these options won't be possible.
|
||||
*/
|
||||
public function __construct(SearchApiServer $server, array $options = array());
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* An associative array of parse modes recognized by objects of this class.
|
||||
* The keys are the parse modes' ids, values are associative arrays
|
||||
* containing the following entries:
|
||||
* - name: The translated name of the parse mode.
|
||||
* - description: (optional) A translated text describing the parse mode.
|
||||
*/
|
||||
public function parseModes();
|
||||
|
||||
/**
|
||||
* Method for creating a filter to use with this query object.
|
||||
*
|
||||
* @param $conjunction
|
||||
* The conjunction to use for the filter - either 'AND' or 'OR'.
|
||||
*
|
||||
* @return SearchApiQueryFilterInterface
|
||||
* A filter object that is set to use the specified conjunction.
|
||||
*/
|
||||
public function createFilter($conjunction = 'AND');
|
||||
|
||||
/**
|
||||
* Sets the keys to search for. If this method is not called on the query
|
||||
* before execution, this will be a filter-only query.
|
||||
*
|
||||
* @param $keys
|
||||
* A string with the unparsed search keys, or NULL to use no search keys.
|
||||
*
|
||||
* @return SearchApiMultiQueryInterface
|
||||
* The called object.
|
||||
*/
|
||||
public function keys($keys = NULL);
|
||||
|
||||
/**
|
||||
* Sets the fields that will be searched for the search keys. If this is not
|
||||
* called, all fulltext fields should be searched.
|
||||
*
|
||||
* @param array $fields
|
||||
* An array containing fulltext fields that should be searched.
|
||||
*
|
||||
* @throws SearchApiException
|
||||
* If one of the fields isn't of type "text".
|
||||
*
|
||||
* @return SearchApiMultiQueryInterface
|
||||
* The called object.
|
||||
*/
|
||||
public function fields(array $fields);
|
||||
|
||||
/**
|
||||
* Adds a subfilter to this query's filter.
|
||||
*
|
||||
* @param SearchApiQueryFilterInterface $filter
|
||||
* A SearchApiQueryFilter object that should be added as a subfilter.
|
||||
*
|
||||
* @return SearchApiMultiQueryInterface
|
||||
* The called object.
|
||||
*/
|
||||
public function filter(SearchApiQueryFilterInterface $filter);
|
||||
|
||||
/**
|
||||
* Add a new ($field $operator $value) condition filter.
|
||||
*
|
||||
* @param $field
|
||||
* The field to filter on. Either a field specification as detailed in the
|
||||
* class comment, or the special field "search_api_multi_index" which means
|
||||
* a filter on the searched indexes.
|
||||
* @param $value
|
||||
* The value the field should have (or be related to by the operator).
|
||||
* @param $operator
|
||||
* The operator to use for checking the constraint. The following operators
|
||||
* are supported for primitive types: "=", "<>", "<", "<=", ">=", ">". They
|
||||
* have the same semantics as the corresponding SQL operators.
|
||||
* If $field is a fulltext field, $operator can only be "=" or "<>", which
|
||||
* are in this case interpreted as "contains" or "doesn't contain",
|
||||
* respectively.
|
||||
* If $value is NULL, $operator also can only be "=" or "<>", meaning the
|
||||
* field must have no or some value, respectively.
|
||||
*
|
||||
* @return SearchApiMultiQueryInterface
|
||||
* The called object.
|
||||
*/
|
||||
public function condition($field, $value, $operator = '=');
|
||||
|
||||
/**
|
||||
* Add a sort directive to this search query. If no sort is manually set, the
|
||||
* results will be sorted descending by relevance.
|
||||
*
|
||||
* How sorts on index-specific fields are handled may differ between service
|
||||
* backends.
|
||||
*
|
||||
* @param $field
|
||||
* The field to sort by. The special field "search_api_relevance" may be
|
||||
* used to sort by relevance.
|
||||
* @param $order
|
||||
* The order to sort items in - either 'ASC' or 'DESC'.
|
||||
*
|
||||
* @throws SearchApiException
|
||||
* If the field is multi-valued or of a fulltext type.
|
||||
*
|
||||
* @return SearchApiMultiQueryInterface
|
||||
* The called object.
|
||||
*/
|
||||
public function sort($field, $order = 'ASC');
|
||||
|
||||
/**
|
||||
* Adds a range of results to return. This will be saved in the query's
|
||||
* options. If called without parameters, this will remove all range
|
||||
* restrictions previously set.
|
||||
*
|
||||
* @param $offset
|
||||
* The zero-based offset of the first result returned.
|
||||
* @param $limit
|
||||
* The number of results to return.
|
||||
*
|
||||
* @return SearchApiMultiQueryInterface
|
||||
* The called object.
|
||||
*/
|
||||
public function range($offset = NULL, $limit = NULL);
|
||||
|
||||
/**
|
||||
* Executes this search query.
|
||||
*
|
||||
* @return array
|
||||
* An associative array containing the search results. The following keys
|
||||
* are standardized:
|
||||
* - 'result count': The overall number of results for this query, without
|
||||
* range restrictions. Might be approximated, for large numbers.
|
||||
* - results: An array of results, ordered as specified. The array keys are
|
||||
* the items' IDs, values are arrays containing the following keys:
|
||||
* - id: The item's ID.
|
||||
* - index_id: The machine name of the index this item was found on.
|
||||
* - score: A float measuring how well the item fits the search.
|
||||
* - entity (optional): If set, the fully loaded result item. This field
|
||||
* should always be used by modules using search results, to avoid
|
||||
* duplicate item loads.
|
||||
* - excerpt (optional): If set, an HTML text containing highlighted
|
||||
* portions of the fulltext that match the query.
|
||||
* - warnings: A numeric array of translated warning messages that may be
|
||||
* displayed to the user.
|
||||
* - ignored: A numeric array of search keys that were ignored for this
|
||||
* search (e.g., because of being too short or stop words).
|
||||
* - performance: An associative array with the time taken (as floats, in
|
||||
* seconds) for specific parts of the search execution:
|
||||
* - complete: The complete runtime of the query.
|
||||
* - hooks: Hook invocations and other client-side preprocessing.
|
||||
* - preprocessing: Preprocessing of the service class.
|
||||
* - execution: The actual query to the search server, in whatever form.
|
||||
* - postprocessing: Preparing the results for returning.
|
||||
* Additional metadata may be returned in other keys. Only 'result count'
|
||||
* and 'result' always have to be set, all other entries are optional.
|
||||
*/
|
||||
public function execute();
|
||||
|
||||
/**
|
||||
* @return SearchApiServer
|
||||
* The search server this query should be executed on.
|
||||
*/
|
||||
public function getServer();
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* An array of SearchApiIndex objects representing all indexes that will be
|
||||
* searched.
|
||||
*/
|
||||
public function getIndexes();
|
||||
|
||||
/**
|
||||
* @return
|
||||
* This object's search keys - either a string or an array specifying a
|
||||
* complex search expression.
|
||||
* An array will contain a '#conjunction' key specifying the conjunction
|
||||
* type, and search strings or nested expression arrays at numeric keys.
|
||||
* Additionally, a '#negation' key might be present, which means – unless it
|
||||
* maps to a FALSE value – that the search keys contained in that array
|
||||
* should be negated, i.e. not be present in returned results.
|
||||
*/
|
||||
public function &getKeys();
|
||||
|
||||
/**
|
||||
* @return
|
||||
* The unprocessed search keys, exactly as passed to this object. Has the
|
||||
* same format as getKeys().
|
||||
*/
|
||||
public function getOriginalKeys();
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* An array containing the fields that should be searched for the search
|
||||
* keys.
|
||||
*/
|
||||
public function &getFields();
|
||||
|
||||
/**
|
||||
* @return SearchApiQueryFilterInterface
|
||||
* This object's associated filter object.
|
||||
*/
|
||||
public function getFilter();
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* An array specifying the sort order for this query. Array keys are the
|
||||
* field names in order of importance, the values are the respective order
|
||||
* in which to sort the results according to the field.
|
||||
*/
|
||||
public function &getSort();
|
||||
|
||||
/**
|
||||
* @param $name string
|
||||
* The name of an option.
|
||||
*
|
||||
* @return mixed
|
||||
* The value of the option with the specified name, if set. NULL otherwise.
|
||||
*/
|
||||
public function getOption($name);
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* The name of an option.
|
||||
* @param mixed $value
|
||||
* The new value of the option.
|
||||
*
|
||||
* @return The option's previous value.
|
||||
*/
|
||||
public function setOption($name, $value);
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* An associative array of query options.
|
||||
*/
|
||||
public function &getOptions();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Standard implementation of SearchApiMultiQueryInterface.
|
||||
*/
|
||||
class SearchApiMultiQuery implements SearchApiMultiQueryInterface {
|
||||
|
||||
/**
|
||||
* The server.
|
||||
*
|
||||
* @var SearchApiServer
|
||||
*/
|
||||
protected $server;
|
||||
|
||||
/**
|
||||
* The searched indexes.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $indexes;
|
||||
|
||||
/**
|
||||
* The search keys. If NULL, this will be a filter-only search.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $keys;
|
||||
|
||||
/**
|
||||
* The unprocessed search keys, as passed to the keys() method.
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
protected $orig_keys;
|
||||
|
||||
/**
|
||||
* The fields that will be searched for the keys.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fields;
|
||||
|
||||
/**
|
||||
* The search filter associated with this query.
|
||||
*
|
||||
* @var SearchApiQueryFilterInterface
|
||||
*/
|
||||
protected $filter;
|
||||
|
||||
/**
|
||||
* The sort associated with this query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $sort;
|
||||
|
||||
/**
|
||||
* Search options configuring this query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $options;
|
||||
|
||||
/**
|
||||
* Count for providing a unique ID.
|
||||
*/
|
||||
protected static $count = 0;
|
||||
|
||||
/**
|
||||
* Constructor for SearchApiMultiQuery objects.
|
||||
*
|
||||
* @param SearchApiIndex $server
|
||||
* The server the query should be executed on.
|
||||
* @param array $options
|
||||
* Associative array of options configuring this query. Recognized options
|
||||
* are:
|
||||
* - conjunction: The type of conjunction to use for this query - either
|
||||
* 'AND' or 'OR'. 'AND' by default. This only influences the search keys,
|
||||
* filters will always use AND by default.
|
||||
* - 'parse mode': The mode with which to parse the $keys variable, if it
|
||||
* is set and not already an array. See SearchApiMultiQuery::parseModes() for
|
||||
* recognized parse modes.
|
||||
* - languages: The languages to search for, as an array of language IDs.
|
||||
* If not specified, all languages will be searched. Language-neutral
|
||||
* content (LANGUAGE_NONE) is always searched.
|
||||
* - offset: The position of the first returned search results relative to
|
||||
* the whole result on the server.
|
||||
* - limit: The maximum number of search results to return. -1 means no
|
||||
* limit.
|
||||
* - 'filter class': Can be used to change the SearchApiQueryFilterInterface
|
||||
* implementation to use.
|
||||
* - 'search id': A string that will be used as the identifier when storing
|
||||
* this search in the Search API's static cache.
|
||||
* All options are optional.
|
||||
*
|
||||
* @throws SearchApiException
|
||||
* If a search with these options won't be possible.
|
||||
*/
|
||||
public function __construct(SearchApiServer $server, array $options = array()) {
|
||||
if (!$server->supportsFeature('search_api_multi')) {
|
||||
throw new SearchApiException(t("The search server @name doesn't support multi-index searches.", array('@name' => $server->name)));
|
||||
}
|
||||
$this->server = $server;
|
||||
$this->indexes = search_api_index_load_multiple(FALSE, array('server' => $server->machine_name, 'enabled' => 1));
|
||||
if (empty($this->indexes)) {
|
||||
throw new SearchApiException(t('There are no enabled indexes on the searched server @name.', array('@name' => $server->name)));
|
||||
}
|
||||
foreach ($this->indexes as $index) {
|
||||
if (empty($index->options['fields'])) {
|
||||
throw new SearchApiException(t("Can't search an index which hasn't got any fields defined."));
|
||||
}
|
||||
if (isset($options['parse mode'])) {
|
||||
$modes = $this->parseModes();
|
||||
if (!isset($modes[$options['parse mode']])) {
|
||||
throw new SearchApiException(t('Unknown parse mode: @mode.', array('@mode' => $options['parse mode'])));
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->options = $options + array(
|
||||
'conjunction' => 'AND',
|
||||
'parse mode' => 'terms',
|
||||
'filter class' => 'SearchApiQueryFilter',
|
||||
'search id' => __CLASS__,
|
||||
);
|
||||
$this->filter = $this->createFilter('AND');
|
||||
$this->sort = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* An associative array of parse modes recognized by objects of this class.
|
||||
* The keys are the parse modes' ids, values are associative arrays
|
||||
* containing the following entries:
|
||||
* - name: The translated name of the parse mode.
|
||||
* - description: (optional) A translated text describing the parse mode.
|
||||
*/
|
||||
public function parseModes() {
|
||||
$modes['direct'] = array(
|
||||
'name' => t('Direct query'),
|
||||
'description' => t("Don't parse the query, just hand it to the search server unaltered. " .
|
||||
"Might fail if the query contains syntax errors in regard to the specific server's query syntax."),
|
||||
);
|
||||
$modes['single'] = array(
|
||||
'name' => t('Single term'),
|
||||
'description' => t('The query is interpreted as a single keyword, maybe containing spaces or special characters.'),
|
||||
);
|
||||
$modes['terms'] = array(
|
||||
'name' => t('Multiple terms'),
|
||||
'description' => t('The query is interpreted as multiple keywords seperated by spaces. ' .
|
||||
'Keywords containing spaces may be "quoted". Quoted keywords must still be seperated by spaces.'),
|
||||
);
|
||||
return $modes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the keys string according to the $mode parameter.
|
||||
*
|
||||
* @return
|
||||
* The parsed keys. Either a string or an array.
|
||||
*/
|
||||
protected function parseKeys($keys, $mode) {
|
||||
if ($keys == NULL || is_array($keys)) {
|
||||
return $keys;
|
||||
}
|
||||
$keys = '' . $keys;
|
||||
switch ($mode) {
|
||||
case 'direct':
|
||||
return $keys;
|
||||
|
||||
case 'single':
|
||||
return array('#conjunction' => $this->options['conjunction'], $keys);
|
||||
|
||||
case 'terms':
|
||||
$ret = explode(' ', $keys);
|
||||
$ret['#conjunction'] = $this->options['conjunction'];
|
||||
$quoted = FALSE;
|
||||
$str = '';
|
||||
foreach ($ret as $k => $v) {
|
||||
if (!$v) {
|
||||
continue;
|
||||
}
|
||||
if ($quoted) {
|
||||
if ($v[drupal_strlen($v)-1] == '"') {
|
||||
$v = substr($v, 0, -1);
|
||||
$str .= ' ' . $v;
|
||||
$ret[$k] = $str;
|
||||
$quoted = FALSE;
|
||||
}
|
||||
else {
|
||||
$str .= ' ' . $v;
|
||||
unset($ret[$k]);
|
||||
}
|
||||
}
|
||||
elseif ($v[0] == '"') {
|
||||
$len = drupal_strlen($v);
|
||||
if ($len > 1 && $v[$len-1] == '"') {
|
||||
$ret[$k] = substr($v, 1, -1);
|
||||
}
|
||||
else {
|
||||
$str = substr($v, 1);
|
||||
$quoted = TRUE;
|
||||
unset($ret[$k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($quoted) {
|
||||
$ret[] = $str;
|
||||
}
|
||||
return array_filter($ret);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for creating a filter to use with this query object.
|
||||
*
|
||||
* @param $conjunction
|
||||
* The conjunction to use for the filter - either 'AND' or 'OR'.
|
||||
*
|
||||
* @return SearchApiQueryFilterInterface
|
||||
* A filter object that is set to use the specified conjunction.
|
||||
*/
|
||||
public function createFilter($conjunction = 'AND') {
|
||||
$filter_class = $this->options['filter class'];
|
||||
return new $filter_class($conjunction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the keys to search for. If this method is not called on the query
|
||||
* before execution, this will be a filter-only query.
|
||||
*
|
||||
* @param $keys
|
||||
* A string with the unparsed search keys, or NULL to use no search keys.
|
||||
*
|
||||
* @return SearchApiMultiQuery
|
||||
* The called object.
|
||||
*/
|
||||
public function keys($keys = NULL) {
|
||||
$this->orig_keys = $keys;
|
||||
if (isset($keys)) {
|
||||
$this->keys = $this->parseKeys($keys, $this->options['parse mode']);
|
||||
}
|
||||
else {
|
||||
$this->keys = NULL;
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
/**
|
||||
* Sets the fields that will be searched for the search keys. If this is not
|
||||
* called, all fulltext fields should be searched.
|
||||
*
|
||||
* @param array $fields
|
||||
* An array containing fulltext fields that should be searched.
|
||||
*
|
||||
* @throws SearchApiException
|
||||
* If one of the fields isn't of type "text".
|
||||
*
|
||||
* @return SearchApiMultiQueryInterface
|
||||
* The called object.
|
||||
*/
|
||||
public function fields(array $fields) {
|
||||
foreach ($fields as $spec) {
|
||||
list($index_id, $field) = explode(':', $spec, 2);
|
||||
if (!isset($this->indexes[$index_id])) {
|
||||
throw new SearchApiException(t("Trying to search on fields of index @index which doesn't lie on server @server.", array('@index' => $index_id, '@server' => $this->server->name)));
|
||||
}
|
||||
if (empty($this->indexes[$index_id]->options['fields'][$field]) || !search_api_is_text_type($this->indexes[$index_id]->options['fields'][$field]['type'])) {
|
||||
throw new SearchApiException(t('Trying to search on field @field which is no indexed fulltext field.', array('@field' => $field)));
|
||||
}
|
||||
}
|
||||
$this->fields = $fields;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a subfilter to this query's filter.
|
||||
*
|
||||
* @param SearchApiQueryFilterInterface $filter
|
||||
* A SearchApiQueryFilter object that should be added as a subfilter.
|
||||
*
|
||||
* @return SearchApiMultiQuery
|
||||
* The called object.
|
||||
*/
|
||||
public function filter(SearchApiQueryFilterInterface $filter) {
|
||||
$this->filter->filter($filter);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new ($field $operator $value) condition filter.
|
||||
*
|
||||
* @param $field
|
||||
* The field to filter on, e.g. 'title'.
|
||||
* @param $value
|
||||
* The value the field should have (or be related to by the operator).
|
||||
* @param $operator
|
||||
* The operator to use for checking the constraint. The following operators
|
||||
* are supported for primitive types: "=", "<>", "<", "<=", ">=", ">". They
|
||||
* have the same semantics as the corresponding SQL operators.
|
||||
* If $field is a fulltext field, $operator can only be "=" or "<>", which
|
||||
* are in this case interpreted as "contains" or "doesn't contain",
|
||||
* respectively.
|
||||
* If $value is NULL, $operator also can only be "=" or "<>", meaning the
|
||||
* field must have no or some value, respectively.
|
||||
*
|
||||
* @return SearchApiMultiQuery
|
||||
* The called object.
|
||||
*/
|
||||
public function condition($field, $value, $operator = '=') {
|
||||
$this->filter->condition($field, $value, $operator);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a sort directive to this search query. If no sort is manually set, the
|
||||
* results will be sorted descending by relevance.
|
||||
*
|
||||
* @param $field
|
||||
* The field to sort by. The special fields 'search_api_relevance' (sort by
|
||||
* relevance) and 'search_api_id' (sort by item id) may be used.
|
||||
* @param $order
|
||||
* The order to sort items in - either 'ASC' or 'DESC'.
|
||||
*
|
||||
* @throws SearchApiException
|
||||
* If the field is multi-valued or of a fulltext type.
|
||||
*
|
||||
* @return SearchApiMultiQuery
|
||||
* The called object.
|
||||
*/
|
||||
public function sort($field, $order = 'ASC') {
|
||||
if ($field != 'search_api_relevance' && $field != 'search_api_id') {
|
||||
list($index_id, $f) = explode(':', $field, 2);
|
||||
if (!isset($this->indexes[$index_id])) {
|
||||
throw new SearchApiException(t("Trying to search on fields of index @index which doesn't lie on server @server.", array('@index' => $index_id, '@server' => $this->server->name)));
|
||||
}
|
||||
$fields = $this->indexes[$index_id]->options['fields'];
|
||||
$fields += array(
|
||||
'search_api_relevance' => array('type' => 'decimal'),
|
||||
'search_api_id' => array('type' => 'integer'),
|
||||
);
|
||||
if (empty($fields[$f])) {
|
||||
throw new SearchApiException(t('Trying to sort on unknown field @field.', array('@field' => $f)));
|
||||
}
|
||||
$type = $fields[$f]['type'];
|
||||
if (search_api_is_list_type($type) || search_api_is_text_type($type)) {
|
||||
throw new SearchApiException(t('Trying to sort on field @field of illegal type @type.', array('@field' => $f, '@type' => $type)));
|
||||
}
|
||||
}
|
||||
$order = strtoupper(trim($order)) == 'DESC' ? 'DESC' : 'ASC';
|
||||
$this->sort[$field] = $order;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a range of results to return. This will be saved in the query's
|
||||
* options. If called without parameters, this will remove all range
|
||||
* restrictions previously set.
|
||||
*
|
||||
* @param $offset
|
||||
* The zero-based offset of the first result returned.
|
||||
* @param $limit
|
||||
* The number of results to return.
|
||||
*
|
||||
* @return SearchApiMultiQueryInterface
|
||||
* The called object.
|
||||
*/
|
||||
public function range($offset = NULL, $limit = NULL) {
|
||||
$this->options['offset'] = $offset;
|
||||
$this->options['limit'] = $limit;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes this search query.
|
||||
*
|
||||
* @return array
|
||||
* An associative array containing the search results. The following keys
|
||||
* are standardized:
|
||||
* - 'result count': The overall number of results for this query, without
|
||||
* range restrictions. Might be approximated, for large numbers.
|
||||
* - results: An array of results, ordered as specified. The array keys are
|
||||
* the items' IDs, values are arrays containing the following keys:
|
||||
* - id: The item's ID.
|
||||
* - index_id: The machine name of the index this item was found on.
|
||||
* - score: A float measuring how well the item fits the search.
|
||||
* - entity (optional): If set, the fully loaded result item. This field
|
||||
* should always be used by modules using search results, to avoid
|
||||
* duplicate item loads.
|
||||
* - excerpt (optional): If set, an HTML text containing highlighted
|
||||
* portions of the fulltext that match the query.
|
||||
* - warnings: A numeric array of translated warning messages that may be
|
||||
* displayed to the user.
|
||||
* - ignored: A numeric array of search keys that were ignored for this
|
||||
* search (e.g., because of being too short or stop words).
|
||||
* - performance: An associative array with the time taken (as floats, in
|
||||
* seconds) for specific parts of the search execution:
|
||||
* - complete: The complete runtime of the query.
|
||||
* - hooks: Hook invocations and other client-side preprocessing.
|
||||
* - preprocessing: Preprocessing of the service class.
|
||||
* - execution: The actual query to the search server, in whatever form.
|
||||
* - postprocessing: Preparing the results for returning.
|
||||
* Additional metadata may be returned in other keys. Only 'result count'
|
||||
* and 'result' always have to be set, all other entries are optional.
|
||||
*/
|
||||
public final function execute() {
|
||||
$start = microtime(TRUE);
|
||||
|
||||
// Add filter for languages.
|
||||
if (isset($this->options['languages'])) {
|
||||
$this->addLanguages($this->options['languages']);
|
||||
}
|
||||
|
||||
// Add fulltext fields, unless set
|
||||
if ($this->fields === NULL) {
|
||||
$this->fields = array();
|
||||
foreach ($this->indexes as $index) {
|
||||
$prefix = $index->machine_name . ':';
|
||||
foreach ($index->getFulltextFields() as $f) {
|
||||
$this->fields[] = $prefix . $f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Call pre-execute hook.
|
||||
$this->preExecute();
|
||||
|
||||
// Let modules alter the query.
|
||||
drupal_alter('search_api_multi_query', $this);
|
||||
|
||||
$pre_search = microtime(TRUE);
|
||||
|
||||
// Execute query.
|
||||
$response = $this->server->searchMultiple($this);
|
||||
|
||||
$post_search = microtime(TRUE);
|
||||
|
||||
// Call post-execute hook.
|
||||
$this->postExecute($response);
|
||||
|
||||
$end = microtime(TRUE);
|
||||
$response['performance']['complete'] = $end - $start;
|
||||
$response['performance']['hooks'] = $response['performance']['complete'] - ($post_search - $pre_search);
|
||||
|
||||
// Store search for later retrieval for facets, etc.
|
||||
search_api_multi_current_search(NULL, $this, $response);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method for adding a language filter.
|
||||
*/
|
||||
protected function addLanguages(array $languages) {
|
||||
if (array_search(LANGUAGE_NONE, $languages) === FALSE) {
|
||||
$languages[] = LANGUAGE_NONE;
|
||||
}
|
||||
|
||||
if (count($languages) == 1) {
|
||||
$this->condition('search_api_language', reset($languages));
|
||||
}
|
||||
else {
|
||||
$filter = $this->createFilter('OR');
|
||||
foreach ($languages as $lang) {
|
||||
$filter->condition('search_api_language', $lang);
|
||||
}
|
||||
$this->filter($filter);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pre-execute hook for modifying search behaviour.
|
||||
*/
|
||||
protected function preExecute() {}
|
||||
|
||||
/**
|
||||
* Post-execute hook for modifying search behaviour.
|
||||
*
|
||||
* @param array $results
|
||||
* The results returned by the server, which may be altered.
|
||||
*/
|
||||
protected function postExecute(array &$results) {}
|
||||
|
||||
/**
|
||||
* @return SearchApiIndex
|
||||
* The search index this query will be executed on.
|
||||
*/
|
||||
public function getServer() {
|
||||
return $this->server;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* An array of SearchApiIndex objects representing all indexes that will be
|
||||
* searched.
|
||||
*/
|
||||
public function getIndexes() {
|
||||
return $this->indexes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* This object's search keys - either a string or an array specifying a
|
||||
* complex search expression.
|
||||
* An array will contain a '#conjunction' key specifying the conjunction
|
||||
* type, and search strings or nested expression arrays at numeric keys.
|
||||
* Additionally, a '#negation' key might be present, which means – unless it
|
||||
* maps to a FALSE value – that the search keys contained in that array
|
||||
* should be negated, i.e. not be present in returned results.
|
||||
*/
|
||||
public function &getKeys() {
|
||||
return $this->keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
* The unprocessed search keys, exactly as passed to this object. Has the
|
||||
* same format as getKeys().
|
||||
*/
|
||||
public function getOriginalKeys() {
|
||||
return $this->orig_keys;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* An array containing the fields that should be searched for the search
|
||||
* keys.
|
||||
*/
|
||||
public function &getFields() {
|
||||
return $this->fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return SearchApiQueryFilterInterface
|
||||
* This object's associated filter object.
|
||||
*/
|
||||
public function getFilter() {
|
||||
return $this->filter;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* An array specifying the sort order for this query. Array keys are the
|
||||
* field names in order of importance, the values are the respective order
|
||||
* in which to sort the results according to the field.
|
||||
*/
|
||||
public function &getSort() {
|
||||
return $this->sort;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name string
|
||||
* The name of an option.
|
||||
*
|
||||
* @return mixed
|
||||
* The option with the specified name, if set, or NULL otherwise.
|
||||
*/
|
||||
public function getOption($name) {
|
||||
return isset($this->options[$name]) ? $this->options[$name] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* The name of an option.
|
||||
* @param mixed $value
|
||||
* The new value of the option.
|
||||
*
|
||||
* @return The option's previous value.
|
||||
*/
|
||||
public function setOption($name, $value) {
|
||||
$old = $this->getOption($name);
|
||||
$this->options[$name] = $value;
|
||||
return $old;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* An associative array of query options.
|
||||
*/
|
||||
public function &getOptions() {
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Interface defining the additional methods a service has to implement in order
|
||||
* to support the "search_api_multi" feature.
|
||||
*
|
||||
* The interface shouldn't be implemented directly (i.e., with a proper
|
||||
* "implements" statement) since this would introduce a needless dependency.
|
||||
*/
|
||||
interface SearchApiMultiServiceInterface extends SearchApiServiceInterface {
|
||||
|
||||
//
|
||||
// Additional methods
|
||||
//
|
||||
|
||||
/**
|
||||
* Create a query object for searching on this server.
|
||||
*
|
||||
* @param $options
|
||||
* Associative array of options configuring this query. See
|
||||
* SearchApiMultiQueryInterface::__construct().
|
||||
*
|
||||
* @throws SearchApiException
|
||||
* If the server is currently disabled.
|
||||
*
|
||||
* @return SearchApiMultiQueryInterface
|
||||
* An object for searching this server.
|
||||
*/
|
||||
public function queryMultiple(array $options = array());
|
||||
|
||||
/**
|
||||
* Executes a search on the server represented by this object.
|
||||
*
|
||||
* @param SearchApiMultiQueryInterface $query
|
||||
* The search query to execute.
|
||||
*
|
||||
* @throws SearchApiException
|
||||
* If an error prevented the search from completing.
|
||||
*
|
||||
* @return array
|
||||
* An associative array containing the search results, as required by
|
||||
* SearchApiMultiQueryInterface::execute().
|
||||
*/
|
||||
public function searchMultiple(SearchApiMultiQueryInterface $query);
|
||||
|
||||
//
|
||||
// Changed documentation / post-conditions
|
||||
//
|
||||
|
||||
/**
|
||||
* Determines whether this service class implementation supports a given
|
||||
* feature. Features are optional extensions to Search API functionality and
|
||||
* usually defined and used by third-party modules.
|
||||
* Currently, the only feature specified directly in the search_api project is
|
||||
* "search_api_facets", defined by the module of the same name.
|
||||
*
|
||||
* @param string $feature
|
||||
* The name of the optional feature.
|
||||
*
|
||||
* @return boolean
|
||||
* TRUE if this service knows and supports the specified feature. FALSE
|
||||
* otherwise.
|
||||
* Must return TRUE if $feature is "search_api_multi".
|
||||
*/
|
||||
public function supportsFeature($feature);
|
||||
|
||||
/**
|
||||
* Add a new index to this server.
|
||||
*
|
||||
* If the index was already added to the server, the object should treat this
|
||||
* as if removeIndex() and then addIndex() were called.
|
||||
*
|
||||
* The implementation of this method should call views_invalidate_cache(), if
|
||||
* the search_api_views and search_api_multi modules are enabled.
|
||||
*
|
||||
* @param SearchApiIndex $index
|
||||
* The index to add.
|
||||
*/
|
||||
public function addIndex(SearchApiIndex $index);
|
||||
|
||||
/**
|
||||
* Notify the server that the indexed field settings for the index have
|
||||
* changed.
|
||||
* If any user action is necessary as a result of this, the method should
|
||||
* use drupal_set_message() to notify the user.
|
||||
*
|
||||
* The implementation of this method should call views_invalidate_cache(), if
|
||||
* the search_api_views and search_api_multi modules are enabled.
|
||||
*
|
||||
* @param SearchApiIndex $index
|
||||
* The updated index.
|
||||
*
|
||||
* @return
|
||||
* TRUE, if this change affected the server in any way that forces it to
|
||||
* re-index the content. FALSE otherwise.
|
||||
*/
|
||||
public function fieldsUpdated(SearchApiIndex $index);
|
||||
|
||||
/**
|
||||
* Remove an index from this server.
|
||||
*
|
||||
* This might mean that the index has been deleted, or reassigned to a
|
||||
* different server. If you need to distinguish between these cases, inspect
|
||||
* $index->server.
|
||||
*
|
||||
* If the index wasn't added to the server, the method call should be ignored.
|
||||
*
|
||||
* The implementation of this method should call views_invalidate_cache(), if
|
||||
* the search_api_views and search_api_multi modules are enabled.
|
||||
*
|
||||
* @param $index
|
||||
* Either an object representing the index to remove, or its machine name
|
||||
* (if the index was completely deleted).
|
||||
*/
|
||||
public function removeIndex($index);
|
||||
|
||||
}
|
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Views argument handler class for handling fulltext fields.
|
||||
*/
|
||||
class SearchApiMultiHandlerArgumentFulltext extends SearchApiViewsHandlerArgumentFulltext {
|
||||
|
||||
/**
|
||||
* Extend the options form a bit.
|
||||
*/
|
||||
public function options_form(array &$form, array &$form_state) {
|
||||
parent::options_form($form, $form_state);
|
||||
|
||||
$fields = array();
|
||||
$server_id = substr($this->table, 18);
|
||||
$indexes = search_api_index_load_multiple(FALSE, array('enabled' => TRUE, 'server' => $server_id));
|
||||
foreach ($indexes as $index) {
|
||||
if (!empty($index->options['fields'])) {
|
||||
$prefix = $index->machine_name . ':';
|
||||
$prefix_name = $index->name . ' » ';
|
||||
$f = $index->options['fields'];
|
||||
foreach ($index->getFulltextFields() as $name) {
|
||||
$fields[$prefix . $name] = $prefix_name . $f[$name]['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!empty($fields)) {
|
||||
$form['fields'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Searched fields'),
|
||||
'#description' => t('Select the fields that will be searched. If no fields are selected, all available fulltext fields will be searched.'),
|
||||
'#options' => $fields,
|
||||
'#size' => min(4, count($fields)),
|
||||
'#multiple' => TRUE,
|
||||
'#default_value' => $this->options['fields'],
|
||||
);
|
||||
}
|
||||
else {
|
||||
$form['fields'] = array(
|
||||
'#type' => 'value',
|
||||
'#value' => array(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Views filter handler class for handling fulltext fields.
|
||||
*/
|
||||
class SearchApiMultiHandlerFilterFulltext extends SearchApiViewsHandlerFilterFulltext {
|
||||
|
||||
/**
|
||||
* Helper method to get an option list of all available fulltext fields.
|
||||
*/
|
||||
protected function getFulltextFields() {
|
||||
$fields = array();
|
||||
$server_id = substr($this->table, 18);
|
||||
$indexes = search_api_index_load_multiple(FALSE, array('enabled' => TRUE, 'server' => $server_id));
|
||||
foreach ($indexes as $index) {
|
||||
if (!empty($index->options['fields'])) {
|
||||
$prefix = $index->machine_name . ':';
|
||||
$prefix_name = $index->name . ' » ';
|
||||
$f = $index->options['fields'];
|
||||
foreach ($index->getFulltextFields() as $name) {
|
||||
$fields[$prefix . $name] = $prefix_name . $f[$name]['name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return $fields;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Views query class using a Search API index as the data source.
|
||||
*/
|
||||
class SearchApiMultiViewsQuery extends SearchApiViewsQuery {
|
||||
|
||||
/**
|
||||
* The server this view accesses.
|
||||
*
|
||||
* @var SearchApiServer
|
||||
*/
|
||||
protected $server;
|
||||
|
||||
/**
|
||||
* Create the basic query object and fill with default values.
|
||||
*/
|
||||
public function init($base_table, $base_field, $options) {
|
||||
try {
|
||||
parent::init($base_table, $base_field, $options);
|
||||
if (substr($base_table, 0, 18) == 'search_api_server_') {
|
||||
$id = substr($base_table, 18);
|
||||
$this->server = search_api_server_load($id);
|
||||
$this->query = $this->server->queryMultiple(array(
|
||||
'parse mode' => 'terms',
|
||||
));
|
||||
}
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$this->errors[] = $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for adding results to a view in the format expected by the view.
|
||||
*/
|
||||
protected function addResults(array $results, $view) {
|
||||
$index_types = array();
|
||||
$view_result = array();
|
||||
$items = array();
|
||||
$ids = array();
|
||||
// First we extract the involved indexes, and which entities need to be
|
||||
// loaded for each entity type.
|
||||
foreach ($results as $result) {
|
||||
$id = $result['id'];
|
||||
$index_id = $result['index_id'];
|
||||
if (!isset($index_types[$index_id])) {
|
||||
$index_types[$index_id] = search_api_index_load($index_id)->item_type;
|
||||
}
|
||||
// Maybe the service class or a postprocessor already set the entities.
|
||||
if (!empty($result['entity'])) {
|
||||
$items[$index_types[$index_id]][$id] = $result['entity'];
|
||||
}
|
||||
else {
|
||||
$ids[$index_types[$index_id]][$id] = $id;
|
||||
}
|
||||
}
|
||||
|
||||
// Then extract the needed fields for each involved entity type.
|
||||
$type_fields = array();
|
||||
foreach ($this->fields as $field => $true) {
|
||||
if (strpos($field, ':') !== FALSE) {
|
||||
list($index_id, $field) = explode(':', $field, 2);
|
||||
if (isset($index_types[$index_id])) {
|
||||
$type_fields[$index_types[$index_id]][$field] = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Extract the field values for entities that were already loaded.
|
||||
foreach ($items as $type => $objs) {
|
||||
foreach ($objs as $id => $item) {
|
||||
try {
|
||||
$key = $type . '-' . $id;
|
||||
$wrapper = search_api_get_datasource_controller($type)->getMetadataWrapper($item);
|
||||
$view_result[$key] = (object) $this->extractFields($wrapper, $type_fields[$type]);
|
||||
$view_result[$key]->entity = $item;
|
||||
unset($objs[$id]);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// If the values of some items couldn't be extracted, try it again with
|
||||
// freshly loaded ones.
|
||||
if ($objs) {
|
||||
$ids[$type] = array_merge($ids[$type], array_keys($objs));
|
||||
}
|
||||
}
|
||||
|
||||
// Load remaining items and extract their field values.
|
||||
foreach ($ids as $type => $item_ids) {
|
||||
if (empty($type_fields[$type])) {
|
||||
continue;
|
||||
}
|
||||
$datasource = search_api_get_datasource_controller($type);
|
||||
$items = $datasource->loadItems($item_ids);
|
||||
foreach ($items as $id => $item) {
|
||||
try {
|
||||
$key = $type . '-' . $id;
|
||||
$wrapper = $datasource->getMetadataWrapper($item);
|
||||
$view_result[$key] = (object) $this->extractFields($wrapper, $type_fields[$type]);
|
||||
$view_result[$key]->entity = $item;
|
||||
}
|
||||
catch (Exception $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Finally, add the extracted values in the correct order to $view->result.
|
||||
foreach ($results as $result) {
|
||||
$key = $index_types[$result['index_id']] . '-' . $result['id'];
|
||||
if (isset($view_result[$key])) {
|
||||
$prefix = $result['index_id'] . ':';
|
||||
$view->result[$key] = new stdClass();
|
||||
foreach ($view_result[$key] as $k => $v) {
|
||||
if ($k != 'entity') {
|
||||
$k = $prefix . $k;
|
||||
}
|
||||
$view->result[$key]->$k = $v;
|
||||
}
|
||||
$view->result[$key]->search_api_relevance = $result['score'];
|
||||
$view->result[$key]->search_api_multi_index = $result['index_id'];
|
||||
foreach ($this->fields as $field => $true) {
|
||||
if (!isset($view->result[$key]->$field)) {
|
||||
$view->result[$key]->$field = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Query interface methods (proxy to $this->query)
|
||||
//
|
||||
|
||||
public function getServer() {
|
||||
return $this->server;
|
||||
}
|
||||
|
||||
public function getIndexes() {
|
||||
if (!$this->errors) {
|
||||
return $this->query->getIndexes();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Implements hook_views_data().
|
||||
*/
|
||||
// This is largely copied from search_api_views_views_data(), including the
|
||||
// "This is largely copied from _search_api_admin_get_fields()." comment.
|
||||
function search_api_multi_views_data() {
|
||||
$data = array();
|
||||
$servers = array();
|
||||
foreach (search_api_index_load_multiple(FALSE) as $index) {
|
||||
if (!($server = $index->server()) || !$server->supportsFeature('search_api_multi')) {
|
||||
continue;
|
||||
}
|
||||
$servers[$server->machine_name][$index->machine_name] = $index->name;
|
||||
// We need the complete indexed data.
|
||||
$array = array();
|
||||
$index->dataAlter($array);
|
||||
|
||||
// Base data
|
||||
$key = 'search_api_server_' . $server->machine_name;
|
||||
$table = &$data[$key];
|
||||
$table['table']['base'] = array(
|
||||
'field' => 'search_api_id',
|
||||
'index' => $server->machine_name,
|
||||
'title' => $server->name,
|
||||
'help' => t('Use search indexes on the %name search server for filtering and retrieving data.', array('%name' => $server->name)),
|
||||
'query class' => 'search_api_multi_query',
|
||||
);
|
||||
|
||||
// Add all available fields
|
||||
// This is largely copied from _search_api_admin_get_fields().
|
||||
$max_depth = variable_get('search_api_multi_max_fields_depth', 2);
|
||||
$orig_wrapper = $index->entityWrapper(NULL, FALSE);
|
||||
$fields = empty($index->options['fields']) ? array() : $index->options['fields'];
|
||||
|
||||
// A wrapper for a specific field name prefix, e.g. 'user:' mapped to the user wrapper
|
||||
$wrappers = array('' => $orig_wrapper);
|
||||
// Display names for the prefixes
|
||||
$prefix_names = array('' => '');
|
||||
// The list nesting level for entities with a certain prefix
|
||||
$nesting_levels = array('' => 0);
|
||||
|
||||
$types = search_api_field_types();
|
||||
$types['options'] = t('Options');
|
||||
while ($wrappers) {
|
||||
foreach ($wrappers as $prefix => $wrapper) {
|
||||
$prefix_name = $prefix_names[$prefix];
|
||||
$depth = substr_count($prefix, ':');
|
||||
// Deal with lists.
|
||||
$nesting_level = $nesting_levels[$prefix];
|
||||
$type_prefix = str_repeat('list<', $nesting_level);
|
||||
$type_suffix = str_repeat('>', $nesting_level);
|
||||
if ($nesting_level) {
|
||||
$info = $wrapper->info();
|
||||
// The real nesting level of the wrapper, not the accumulated one.
|
||||
$level = search_api_list_nesting_level($info['type']);
|
||||
for ($i = 0; $i < $level; ++$i) {
|
||||
$wrapper = $wrapper[0];
|
||||
}
|
||||
}
|
||||
// Now look at all properties.
|
||||
foreach ($wrapper as $property => $value) {
|
||||
$info = $value->info();
|
||||
$type = $type_prefix . $info['type'] . $type_suffix;
|
||||
$inner_type = search_api_extract_inner_type($info['type']);
|
||||
if ($inner_type == 'token') {
|
||||
$inner_type = 'string';
|
||||
$type = search_api_nest_type('string', $type);
|
||||
}
|
||||
$key = $index->machine_name . ':' . $prefix . $property;
|
||||
if (isset($types[$inner_type])) {
|
||||
if ($value->optionsList()) {
|
||||
$inner_type = 'options';
|
||||
$type = search_api_nest_type('options', $type);
|
||||
}
|
||||
// Add field handler.
|
||||
$table[$key]['group'] = $prefix_name ? $index->name . ' » ' . $prefix_name : $index->name;
|
||||
$table[$key]['title'] = $info['label'];
|
||||
$table[$key]['help'] = empty($info['description']) ? t('(No information available)') : $info['description'];
|
||||
$table[$key]['type'] = $type;
|
||||
$table[$key]['field']['handler'] = _search_api_views_field_handler($type, $inner_type);
|
||||
if ($inner_type == 'options') {
|
||||
$table[$key]['field']['options'] = $value->optionsList();
|
||||
}
|
||||
|
||||
// If field is indexed, also add additional handlers.
|
||||
if (!empty($fields[$prefix . $property])) {
|
||||
// Discern between original and indexed type
|
||||
$table[$key]['field']['type'] = $table[$key]['type'];
|
||||
$table[$key]['type'] = $fields[$prefix . $property]['type'];
|
||||
$table[$key] += _search_api_views_add_handlers($fields[$prefix . $property], $value);
|
||||
if (!empty($table[$key]['sort'])) {
|
||||
$table[$key]['field']['click sortable'] = TRUE;
|
||||
}
|
||||
}
|
||||
unset($fields[$prefix . $property]);
|
||||
}
|
||||
elseif ($depth < $max_depth) {
|
||||
// Visit this entity/struct in a later iteration.
|
||||
$key = $prefix . $property . ':';
|
||||
$wrappers[$key] = $value;
|
||||
$prefix_names[$key] = $prefix_name ? $prefix_name . ' » ' . $info['label'] : $info['label'];
|
||||
$nesting_levels[$key] = search_api_list_nesting_level($type);
|
||||
}
|
||||
}
|
||||
unset($wrappers[$prefix]);
|
||||
}
|
||||
}
|
||||
|
||||
// Add handlers for all indexed fields which weren't processed yet.
|
||||
foreach ($fields as $key => $field) {
|
||||
$tmp = $orig_wrapper;
|
||||
$group = '';
|
||||
$name = $index->name;
|
||||
$parts = explode(':', $key);
|
||||
foreach ($parts as $i => $part) {
|
||||
if (!isset($tmp->$part)) {
|
||||
continue 2;
|
||||
}
|
||||
$tmp = $tmp->$part;
|
||||
$info = $tmp->info();
|
||||
$group = ($group ? $group . ' » ' . $name : ($name ? $name : ''));
|
||||
$name = $info['label'];
|
||||
if ($i < count($parts) - 1) {
|
||||
// Unwrap lists.
|
||||
$level = search_api_list_nesting_level($info['type']);
|
||||
for ($j = 0; $j < $level; ++$j) {
|
||||
$tmp = $tmp[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
$key = $index->machine_name . ':' . $key;
|
||||
if ($group) {
|
||||
$table[$key]['group'] = $group;
|
||||
}
|
||||
$table[$key]['title'] = $name;
|
||||
$table[$key]['help'] = empty($info['description']) ? t('(No information available)') : $info['description'];
|
||||
$table[$key]['type'] = $field['type'];
|
||||
$table[$key] += _search_api_views_add_handlers($field, $tmp);
|
||||
}
|
||||
|
||||
// Special handlers
|
||||
$table['search_api_relevance']['group'] = t('Search');
|
||||
$table['search_api_relevance']['title'] = t('Relevance');
|
||||
$table['search_api_relevance']['help'] = t('The relevance of this search result with respect to the query.');
|
||||
$table['search_api_relevance']['type'] = 'decimal';
|
||||
$table['search_api_relevance']['field']['handler'] = _search_api_views_field_handler('decimal', 'decimal');
|
||||
$table['search_api_relevance']['field']['click sortable'] = TRUE;
|
||||
$table['search_api_relevance']['sort']['handler'] = 'SearchApiViewsHandlerSort';
|
||||
|
||||
$table['search_api_multi_fulltext']['group'] = t('Search');
|
||||
$table['search_api_multi_fulltext']['title'] = t('Fulltext search');
|
||||
$table['search_api_multi_fulltext']['help'] = t('Search several or all fulltext fields at once.');
|
||||
$table['search_api_multi_fulltext']['type'] = 'text';
|
||||
$table['search_api_multi_fulltext']['filter']['handler'] = 'SearchApiMultiHandlerFilterFulltext';
|
||||
$table['search_api_multi_fulltext']['argument']['handler'] = 'SearchApiMultiHandlerArgumentFulltext';
|
||||
}
|
||||
|
||||
foreach ($servers as $server_id => $indexes) {
|
||||
$key = 'search_api_server_' . $server_id;
|
||||
$table = &$data[$key];
|
||||
$table['search_api_multi_index']['group'] = t('Search');
|
||||
$table['search_api_multi_index']['title'] = t('Index');
|
||||
$table['search_api_multi_index']['help'] = t('The search indexes that will be searched.');
|
||||
$table['search_api_multi_index']['type'] = 'options';
|
||||
$table['search_api_multi_index']['field']['handler'] = _search_api_views_field_handler('options', 'options');
|
||||
$table['search_api_multi_index']['field']['options'] = $indexes;
|
||||
$table['search_api_multi_index']['argument']['handler'] = 'SearchApiViewsHandlerArgument';
|
||||
$table['search_api_multi_index']['filter']['handler'] = 'SearchApiViewsHandlerFilterOptions';
|
||||
$table['search_api_multi_index']['filter']['options'] = $indexes;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_views_plugins().
|
||||
*/
|
||||
function search_api_multi_views_plugins() {
|
||||
return array(
|
||||
'query' => array(
|
||||
'search_api_multi_query' => array(
|
||||
'title' => t('Search API Query'),
|
||||
'help' => t('Query will be generated and run using the Search API.'),
|
||||
'handler' => 'SearchApiMultiViewsQuery'
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
Reference in New Issue
Block a user