CWIS Developer Documentation
|
Core metadata archive search engine class. More...
Public Member Functions | |
__construct ($ItemTableName, $ItemIdFieldName, $ItemTypeFieldName) | |
Object constructor. More... | |
AddField ($FieldId, $FieldType, $ItemTypes, $Weight, $UsedInKeywordSearch) | |
Add field to include in searching. More... | |
FieldType ($FieldId) | |
Get type of specified field (text/numeric/date/daterange). More... | |
FieldWeight ($FieldId) | |
Get search weight for specified field. More... | |
FieldInKeywordSearch ($FieldId) | |
Get whether specified field is included in keyword searches. More... | |
DebugLevel ($NewValue) | |
Set debug output level. More... | |
Search ($SearchParams) | |
Perform search with specified parameters, returning results in a flat array indexed by item ID. More... | |
SearchAll ($SearchParams) | |
Perform search with specified parameters, returning results separated by item type. More... | |
AddResultFilterFunction ($FunctionName) | |
Add function that will be called to filter search results. More... | |
NumberOfResults ($ItemType=NULL) | |
Get number of results found by most recent search. More... | |
SearchTerms () | |
Get normalized list of search terms. More... | |
SearchTime () | |
Get time that last search took, in seconds. More... | |
FieldedSearchWeightScale ($SearchParams) | |
Get total of weights for all fields involved in search, useful for assessing scale of scores in search results. More... | |
UpdateForItem ($ItemId, $ItemType) | |
Update search database for the specified item. More... | |
UpdateForItems ($StartingItemId, $NumberOfItems) | |
Update search database for the specified range of items. More... | |
DropItem ($ItemId) | |
Drop all data pertaining to item from search database. More... | |
DropField ($FieldId) | |
Drop all data pertaining to field from search database. More... | |
SearchTermCount () | |
Get total number of search terms indexed by search engine. More... | |
ItemCount () | |
Get total number of items indexed by search engine. More... | |
AddSynonyms ($Word, $Synonyms) | |
Add synonyms. More... | |
RemoveSynonyms ($Word, $Synonyms=NULL) | |
Remove synonym(s). More... | |
RemoveAllSynonyms () | |
Remove all synonyms. More... | |
GetSynonyms ($Word) | |
Get synonyms for word. More... | |
GetAllSynonyms () | |
Get all synonyms. More... | |
SetAllSynonyms ($SynonymList) | |
Set all synonyms. More... | |
LoadSynonymsFromFile ($FileName) | |
Load synonyms from a file. More... | |
Static Public Member Functions | |
static | FlattenMultiTypeResults ($Results) |
Flatten a two-dimensional array keyed by ItemType with results for each type as the outer values into array(ItemId => ItemScore). More... | |
static | BuildMultiTypeResults ($Results) |
Expand a one-dimensional array(ItemId => ItemScore) into a two-dimensional array(ItemType => array(ItemId => ItemScore)). More... | |
Public Attributes | |
const | LOGIC_AND = 1 |
const | LOGIC_OR = 2 |
const | FIELDTYPE_TEXT = 1 |
const | FIELDTYPE_NUMERIC = 2 |
const | FIELDTYPE_DATE = 3 |
const | FIELDTYPE_DATERANGE = 4 |
const | WORD_PRESENT = 1 |
const | WORD_EXCLUDED = 2 |
const | WORD_REQUIRED = 4 |
const | KEYWORD_FIELD_ID = -100 |
const | STEM_ID_OFFSET = 1000000 |
const | SEARCHLOGIC_AND = 1 |
const | SEARCHLOGIC_OR = 2 |
const | COMPARISON_OPERATOR_PATTERN = '/^([><=^$@]+|!=)([^><=^$@])/' |
Protected Member Functions | |
SearchFieldForPhrases ($FieldId, $Phrase) | |
Search for phrase in specified field. More... | |
FilterOnSuppliedFunctions ($Scores) | |
Filter search scores through any supplied functions. More... | |
GetFieldContent ($ItemId, $FieldId) | |
Retrieve content for specified field for specified item. More... | |
DMsg ($Level, $Msg) | |
Print debug message if level set high enough. More... | |
Protected Attributes | |
$DB | |
$DebugLevel | |
$FilterFuncs | |
$ItemIdFieldName | |
$ItemTableName | |
$ItemTypeFieldName | |
$LastSearchTime | |
$NumberOfResultsAvailable | |
$NumberOfResultsPerItemType | |
$StemmingEnabled = TRUE | |
$SynonymsEnabled = TRUE | |
Core metadata archive search engine class.
Definition at line 13 of file SearchEngine.php.
SearchEngine::__construct | ( | $ItemTableName, | |
$ItemIdFieldName, | |||
$ItemTypeFieldName | |||
) |
Object constructor.
string | $ItemTableName | Name of database table containing items. |
string | $ItemIdFieldName | Name of column in item database table containing item IDs. |
string | $ItemTypeFieldName | Name of column in item database table containing item types. |
Definition at line 41 of file SearchEngine.php.
References $ItemIdFieldName, $ItemTableName, $ItemTypeFieldName, and DebugLevel().
SearchEngine::AddField | ( | $FieldId, | |
$FieldType, | |||
$ItemTypes, | |||
$Weight, | |||
$UsedInKeywordSearch | |||
) |
Add field to include in searching.
int | $FieldId | ID of field. |
int | $FieldType | Type of field (FIELDTYPE_ constant value). |
mixed | $ItemTypes | Item type or array of item types to which the field applies. |
int | $Weight | Numeric search weight for field. |
bool | $UsedInKeywordSearch | If TRUE, field is included in keyword searches. |
Definition at line 66 of file SearchEngine.php.
Referenced by SPTSearchEngine\__construct().
SearchEngine::AddResultFilterFunction | ( | $FunctionName | ) |
Add function that will be called to filter search results.
callable | $FunctionName | Function to be called. |
Definition at line 193 of file SearchEngine.php.
SearchEngine::AddSynonyms | ( | $Word, | |
$Synonyms | |||
) |
Add synonyms.
string | $Word | Word for which synonyms should apply. |
array | $Synonyms | Array of synonyms. |
Definition at line 389 of file SearchEngine.php.
Referenced by LoadSynonymsFromFile(), and SetAllSynonyms().
|
static |
Expand a one-dimensional array(ItemId => ItemScore) into a two-dimensional array(ItemType => array(ItemId => ItemScore)).
array | $Results | One-dimensional array(ItemId => ItemScore). |
Definition at line 696 of file SearchEngine.php.
References $DB.
SearchEngine::DebugLevel | ( | $NewValue | ) |
Set debug output level.
Values above zero trigger diagnostic output.
int | $NewValue | New debugging level. |
Definition at line 112 of file SearchEngine.php.
Referenced by __construct(), DMsg(), FilterOnSuppliedFunctions(), and SPTSearchEngine\SearchFieldForPhrases().
|
protected |
Print debug message if level set high enough.
int | $Level | Level of message. |
string | $Msg | Message to print. |
Definition at line 2237 of file SearchEngine.php.
References DebugLevel().
Referenced by FilterOnSuppliedFunctions(), GetFieldContent(), SearchAll(), SPTSearchEngine\SearchFieldForPhrases(), SearchFieldForPhrases(), and SPTSearchEngine\SearchFieldsForComparisonMatches().
SearchEngine::DropField | ( | $FieldId | ) |
Drop all data pertaining to field from search database.
int | $FieldId | ID of field to drop. |
Definition at line 356 of file SearchEngine.php.
SearchEngine::DropItem | ( | $ItemId | ) |
Drop all data pertaining to item from search database.
int | $ItemId | ID of item to drop from database. |
Definition at line 345 of file SearchEngine.php.
SearchEngine::FieldedSearchWeightScale | ( | $SearchParams | ) |
Get total of weights for all fields involved in search, useful for assessing scale of scores in search results.
object | $SearchParams | Search parameters (SearchParameterSet). |
Definition at line 236 of file SearchEngine.php.
SearchEngine::FieldInKeywordSearch | ( | $FieldId | ) |
Get whether specified field is included in keyword searches.
int | $FieldId | ID of field. |
Definition at line 103 of file SearchEngine.php.
SearchEngine::FieldType | ( | $FieldId | ) |
Get type of specified field (text/numeric/date/daterange).
int | $FieldId | ID of field. |
Definition at line 83 of file SearchEngine.php.
SearchEngine::FieldWeight | ( | $FieldId | ) |
Get search weight for specified field.
int | $FieldId | ID of field. |
Definition at line 93 of file SearchEngine.php.
|
protected |
Filter search scores through any supplied functions.
array | $Scores | Current set of search scores. |
Definition at line 1588 of file SearchEngine.php.
References DebugLevel(), and DMsg().
Referenced by SearchFieldForPhrases().
|
static |
Flatten a two-dimensional array keyed by ItemType with results for each type as the outer values into array(ItemId => ItemScore).
array | $Results | Two-dimensional array(ItemType => array(ItemId => ItemScore)). |
Definition at line 678 of file SearchEngine.php.
SearchEngine::GetAllSynonyms | ( | ) |
Get all synonyms.
Definition at line 519 of file SearchEngine.php.
|
protected |
Retrieve content for specified field for specified item.
int | $ItemId | ID of item. |
int | $FieldId | ID of field. |
Definition at line 1903 of file SearchEngine.php.
References DMsg().
Referenced by UpdateForItem().
SearchEngine::GetSynonyms | ( | $Word | ) |
Get synonyms for word.
string | $Word | Word for which synonyms should apply. |
Definition at line 481 of file SearchEngine.php.
SearchEngine::ItemCount | ( | ) |
Get total number of items indexed by search engine.
Definition at line 376 of file SearchEngine.php.
SearchEngine::LoadSynonymsFromFile | ( | $FileName | ) |
Load synonyms from a file.
Each line of file should contain one word at the beginning of the line, followed by one or more synonyms separated by spaces or commas. Blank lines or lines beginning with "#" (i.e. comments) will be ignored.
string | $FileName | Name of file containing synonyms (with path if needed). |
Definition at line 634 of file SearchEngine.php.
References AddSynonyms().
SearchEngine::NumberOfResults | ( | $ItemType = NULL | ) |
Get number of results found by most recent search.
int | $ItemType | Type of item. (OPTIONAL, defaults to total for all items) |
Definition at line 205 of file SearchEngine.php.
SearchEngine::RemoveAllSynonyms | ( | ) |
Remove all synonyms.
Definition at line 471 of file SearchEngine.php.
Referenced by SetAllSynonyms().
SearchEngine::RemoveSynonyms | ( | $Word, | |
$Synonyms = NULL |
|||
) |
Remove synonym(s).
string | $Word | Word for which synonyms should apply. |
array | $Synonyms | Array of synonyms to remove. If not specified, all synonyms for word will be removed. (OPTIONAL) |
Definition at line 429 of file SearchEngine.php.
SearchEngine::Search | ( | $SearchParams | ) |
Perform search with specified parameters, returning results in a flat array indexed by item ID.
If multiple types of items are present in the results, they will first be sorted by item type, and then within item type will be sorted by whatever sorting parameters were specified.
mixed | $SearchParams | Search parameters as SearchParameterSet object or keyword search string. |
Definition at line 130 of file SearchEngine.php.
References SearchAll().
Referenced by SPTSearchEngine\GroupedSearch().
SearchEngine::SearchAll | ( | $SearchParams | ) |
Perform search with specified parameters, returning results separated by item type.
mixed | $SearchParams | Search parameters as SearchParameterSet object or keyword search string. |
Definition at line 144 of file SearchEngine.php.
References DMsg().
Referenced by Search().
|
protected |
Search for phrase in specified field.
string | $FieldId | ID of field to search. |
string | $Phrase | Phrase to search for. |
Definition at line 1284 of file SearchEngine.php.
References $DB, DMsg(), and FilterOnSuppliedFunctions().
SearchEngine::SearchTermCount | ( | ) |
Get total number of search terms indexed by search engine.
Definition at line 366 of file SearchEngine.php.
SearchEngine::SearchTerms | ( | ) |
Get normalized list of search terms.
Definition at line 216 of file SearchEngine.php.
SearchEngine::SearchTime | ( | ) |
Get time that last search took, in seconds.
Definition at line 225 of file SearchEngine.php.
References $LastSearchTime.
SearchEngine::SetAllSynonyms | ( | $SynonymList | ) |
Set all synonyms.
This removes any existing synonyms and replaces them with the synonyms passed in.
array | $SynonymList | Array of arrays of synonyms, with words for index. |
Definition at line 613 of file SearchEngine.php.
References AddSynonyms(), and RemoveAllSynonyms().
SearchEngine::UpdateForItem | ( | $ItemId, | |
$ItemType | |||
) |
Update search database for the specified item.
int | $ItemId | ID of item. |
int | $ItemType | Numerical type of item. |
Definition at line 268 of file SearchEngine.php.
References GetFieldContent().
Referenced by UpdateForItems().
SearchEngine::UpdateForItems | ( | $StartingItemId, | |
$NumberOfItems | |||
) |
Update search database for the specified range of items.
int | $StartingItemId | ID of item to start with. |
int | $NumberOfItems | Maximum number of items to update. |
Definition at line 320 of file SearchEngine.php.
References UpdateForItem().
|
protected |
Definition at line 714 of file SearchEngine.php.
Referenced by BuildMultiTypeResults(), SPTSearchEngine\FilterTextDisplay(), SPTSearchEngine\GetResultFacets(), and SearchFieldForPhrases().
|
protected |
Definition at line 715 of file SearchEngine.php.
|
protected |
Definition at line 716 of file SearchEngine.php.
|
protected |
Definition at line 717 of file SearchEngine.php.
Referenced by __construct().
|
protected |
Definition at line 718 of file SearchEngine.php.
Referenced by __construct().
|
protected |
Definition at line 719 of file SearchEngine.php.
Referenced by __construct().
|
protected |
Definition at line 720 of file SearchEngine.php.
Referenced by SearchTime().
|
protected |
Definition at line 721 of file SearchEngine.php.
|
protected |
Definition at line 722 of file SearchEngine.php.
|
protected |
Definition at line 723 of file SearchEngine.php.
|
protected |
Definition at line 724 of file SearchEngine.php.
const SearchEngine::COMPARISON_OPERATOR_PATTERN = '/^([><=^$@]+|!=)([^><=^$@])/' |
Definition at line 2252 of file SearchEngine.php.
const SearchEngine::FIELDTYPE_DATE = 3 |
Definition at line 25 of file SearchEngine.php.
const SearchEngine::FIELDTYPE_DATERANGE = 4 |
Definition at line 26 of file SearchEngine.php.
const SearchEngine::FIELDTYPE_NUMERIC = 2 |
Definition at line 24 of file SearchEngine.php.
const SearchEngine::FIELDTYPE_TEXT = 1 |
Definition at line 23 of file SearchEngine.php.
const SearchEngine::KEYWORD_FIELD_ID = -100 |
Definition at line 735 of file SearchEngine.php.
const SearchEngine::LOGIC_AND = 1 |
const SearchEngine::LOGIC_OR = 2 |
Definition at line 20 of file SearchEngine.php.
Referenced by SearchParameterSet\Logic(), MetadataField\SearchGroupLogic(), and SavedSearch\TranslateUrlParametersToSearchGroups().
const SearchEngine::SEARCHLOGIC_AND = 1 |
Definition at line 2248 of file SearchEngine.php.
const SearchEngine::SEARCHLOGIC_OR = 2 |
Definition at line 2249 of file SearchEngine.php.
const SearchEngine::STEM_ID_OFFSET = 1000000 |
Definition at line 736 of file SearchEngine.php.
const SearchEngine::WORD_EXCLUDED = 2 |
Definition at line 30 of file SearchEngine.php.
Referenced by SearchEngine_Test\testParseSearchStringForWords().
const SearchEngine::WORD_PRESENT = 1 |
Definition at line 29 of file SearchEngine.php.
Referenced by SearchEngine_Test\testParseSearchStringForWords().
const SearchEngine::WORD_REQUIRED = 4 |
Definition at line 31 of file SearchEngine.php.
Referenced by SearchEngine_Test\testParseSearchStringForWords().