CWIS Developer Documentation
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
SearchEngine Class Reference

Core metadata archive search engine class. More...

Inheritance diagram for SearchEngine:
Inheritance graph
[legend]

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, $StartingResult=0, $NumberOfResults=PHP_INT_MAX, $SortByField=NULL, $SortDescending=TRUE)
 Perform search with specified parameters. More...
 
 FieldedSearch ($SearchStrings, $StartingResult=0, $NumberOfResults=10, $SortByField=NULL, $SortDescending=TRUE)
 Perform search across multiple fields, with different values or comparisons specified for each field. 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
 
 $StemmingEnabled = TRUE
 
 $SynonymsEnabled = TRUE
 

Detailed Description

Core metadata archive search engine class.

Definition at line 13 of file SearchEngine.php.

Constructor & Destructor Documentation

SearchEngine::__construct (   $ItemTableName,
  $ItemIdFieldName,
  $ItemTypeFieldName 
)

Object constructor.

Parameters
string$ItemTableNameName of database table containing items.
string$ItemIdFieldNameName of column in item database table containing item IDs.
string$ItemTypeFieldNameName of column in item database table containing item types.

Definition at line 41 of file SearchEngine.php.

References $ItemIdFieldName, $ItemTableName, $ItemTypeFieldName, and DebugLevel().

Member Function Documentation

SearchEngine::AddField (   $FieldId,
  $FieldType,
  $ItemTypes,
  $Weight,
  $UsedInKeywordSearch 
)

Add field to include in searching.

Parameters
int$FieldIdID of field.
int$FieldTypeType of field (FIELDTYPE_ constant value).
mixed$ItemTypesItem type or array of item types to which the field applies.
int$WeightNumeric search weight for field.
bool$UsedInKeywordSearchIf TRUE, field is included in keyword searches.

Definition at line 66 of file SearchEngine.php.

Referenced by SPTSearchEngine\__construct().

Here is the caller graph for this function:

SearchEngine::AddResultFilterFunction (   $FunctionName)

Add function that will be called to filter search results.

Parameters
callable$FunctionNameFunction to be called.

Definition at line 243 of file SearchEngine.php.

SearchEngine::AddSynonyms (   $Word,
  $Synonyms 
)

Add synonyms.

Parameters
string$WordWord for which synonyms should apply.
array$SynonymsArray of synonyms.
Returns
int Count of new synonyms added. (May be less than the number passed in, if some synonyms were already defined.)

Definition at line 439 of file SearchEngine.php.

Referenced by LoadSynonymsFromFile(), and SetAllSynonyms().

Here is the caller graph for this function:

static SearchEngine::BuildMultiTypeResults (   $Results)
static

Expand a one-dimensional array(ItemId => ItemScore) into a two-dimensional array(ItemType => array(ItemId => ItemScore)).

Parameters
arrayOne-dimensional array(ItemId => ItemScore).
Returns
Two-dimensional array(ItemType => array(ItemId => ItemScore)).

Definition at line 745 of file SearchEngine.php.

References $DB.

SearchEngine::DebugLevel (   $NewValue)

Set debug output level.

Values above zero trigger diagnostic output.

Parameters
int$NewValueNew debugging level.

Definition at line 112 of file SearchEngine.php.

Referenced by __construct(), DMsg(), FilterOnSuppliedFunctions(), and SPTSearchEngine\SearchFieldForPhrases().

Here is the caller graph for this function:

SearchEngine::DMsg (   $Level,
  $Msg 
)
protected

Print debug message if level set high enough.

Parameters
int$LevelLevel of message.
string$MsgMessage to print.

Definition at line 2301 of file SearchEngine.php.

References DebugLevel().

Referenced by FieldedSearch(), FilterOnSuppliedFunctions(), GetFieldContent(), Search(), SPTSearchEngine\SearchFieldForPhrases(), SearchFieldForPhrases(), and SPTSearchEngine\SearchFieldsForComparisonMatches().

Here is the caller graph for this function:

SearchEngine::DropField (   $FieldId)

Drop all data pertaining to field from search database.

Parameters
int$FieldIdID of field to drop.

Definition at line 406 of file SearchEngine.php.

SearchEngine::DropItem (   $ItemId)

Drop all data pertaining to item from search database.

Parameters
int$ItemIdID of item to drop from database.

Definition at line 395 of file SearchEngine.php.

SearchEngine::FieldedSearch (   $SearchStrings,
  $StartingResult = 0,
  $NumberOfResults = 10,
  $SortByField = NULL,
  $SortDescending = TRUE 
)

Perform search across multiple fields, with different values or comparisons specified for each field.

This method is DEPRECATED – please use SearchEngine::Search() with a SearchParameterSet object instead.

Parameters
array$SearchStringsArray of search strings, with field names for index.
int$StartingResultStarting index into results. (OPTIONAL, defaults to 0)
int$NumberOfResultsNumber of results to return. (OPTIONAL, defaults to 10)
string$SortByFieldName of field to sort results by. (OPTIONAL, defaults to relevance score)
bool$SortDescendingIf TRUE, results will be sorted in descending order, otherwise results will be sorted in ascending order. (OPTIONAL, defaults to TRUE)
Returns
array Array of search result scores, with the IDs of items found by search as the index.
See also
SearchEngine::Search()

Definition at line 204 of file SearchEngine.php.

References DMsg().

SearchEngine::FieldedSearchWeightScale (   $SearchParams)

Get total of weights for all fields involved in search, useful for assessing scale of scores in search results.

Parameters
object$SearchParamsSearch parameters (SearchParameterSet).
Returns
int Total of weights.

Definition at line 286 of file SearchEngine.php.

SearchEngine::FieldInKeywordSearch (   $FieldId)

Get whether specified field is included in keyword searches.

Parameters
int$FieldIdID of field.
Returns
bool TRUE if field is included in keyword search, otherwise FALSE.

Definition at line 103 of file SearchEngine.php.

SearchEngine::FieldType (   $FieldId)

Get type of specified field (text/numeric/date/daterange).

Parameters
int$FieldIdID of field.
Returns
int Field type (FIELDTYPE_ constant).

Definition at line 83 of file SearchEngine.php.

SearchEngine::FieldWeight (   $FieldId)

Get search weight for specified field.

Parameters
int$FieldIdID of field.
Returns
int Search weight.

Definition at line 93 of file SearchEngine.php.

SearchEngine::FilterOnSuppliedFunctions (   $Scores)
protected

Filter search scores through any supplied functions.

Parameters
array$ScoresCurrent set of search scores.
Returns
array An possibly pared-down set of search scores.

Definition at line 1653 of file SearchEngine.php.

References DebugLevel(), and DMsg().

Referenced by SearchFieldForPhrases().

Here is the caller graph for this function:

static SearchEngine::FlattenMultiTypeResults (   $Results)
static

Flatten a two-dimensional array keyed by ItemType with results for each type as the outer values into array(ItemId => ItemScore).

Parameters
arrayTwo-dimensional array(ItemType => array(ItemId => ItemScore)).
Returns
array One-dimensional array(ItemId => ItemScore)

Definition at line 728 of file SearchEngine.php.

SearchEngine::GetAllSynonyms ( )

Get all synonyms.

Returns
array Array of arrays of synonyms, with words for index.

Definition at line 569 of file SearchEngine.php.

SearchEngine::GetFieldContent (   $ItemId,
  $FieldId 
)
protected

Retrieve content for specified field for specified item.

Parameters
int$ItemIdID of item.
int$FieldIdID of field.

Definition at line 1968 of file SearchEngine.php.

References DMsg().

Referenced by UpdateForItem().

Here is the caller graph for this function:

SearchEngine::GetSynonyms (   $Word)

Get synonyms for word.

Parameters
string$WordWord for which synonyms should apply.
Returns
array Array of synonyms.

Definition at line 531 of file SearchEngine.php.

SearchEngine::ItemCount ( )

Get total number of items indexed by search engine.

Returns
int Count of items.

Definition at line 426 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.

Parameters
string$FileNameName of file containing synonyms (with path if needed).
Returns
Number of new synonyms added.

Definition at line 684 of file SearchEngine.php.

References AddSynonyms().

SearchEngine::NumberOfResults (   $ItemType = NULL)

Get number of results found by most recent search.

Parameters
int$ItemTypeType of item. (OPTIONAL, defaults to total for all items)
Returns
int Result count.

Definition at line 255 of file SearchEngine.php.

SearchEngine::RemoveAllSynonyms ( )

Remove all synonyms.

Definition at line 521 of file SearchEngine.php.

Referenced by SetAllSynonyms().

Here is the caller graph for this function:

SearchEngine::RemoveSynonyms (   $Word,
  $Synonyms = NULL 
)

Remove synonym(s).

Parameters
string$WordWord for which synonyms should apply.
array$SynonymsArray of synonyms to remove. If not specified, all synonyms for word will be removed. (OPTIONAL)

Definition at line 479 of file SearchEngine.php.

SearchEngine::Search (   $SearchParams,
  $StartingResult = 0,
  $NumberOfResults = PHP_INT_MAX,
  $SortByField = NULL,
  $SortDescending = TRUE 
)

Perform search with specified parameters.

Parameters
mixed$SearchParamsSearch parameters as SearchParameterSet object or keyword search string.
int$StartingResultStarting index into results. (OPTIONAL, defaults to 0)
int$NumberOfResultsNumber of results to return. (OPTIONAL, defaults to PHP_INT_MAX)
string$SortByFieldID of field or array of IDs of fields (indexed by item type) to sort results by. (OPTIONAL, defaults to NULL, which indicates to sort by relevance score)
mixed$SortDescendingIf TRUE, sort in descending order, otherwise sort in ascending order. May also be array of boolean values, with item types for the index. (OPTIONAL, defaults to TRUE)
Returns
array Array of arrays of search result scores, with the item type for the first index and the IDs of items found by search as the second index.

Definition at line 138 of file SearchEngine.php.

References DMsg().

Referenced by SPTSearchEngine\GroupedSearch().

Here is the caller graph for this function:

SearchEngine::SearchFieldForPhrases (   $FieldId,
  $Phrase 
)
protected

Search for phrase in specified field.

Parameters
string$FieldIdID of field to search.
string$PhrasePhrase to search for.

Definition at line 1332 of file SearchEngine.php.

References $DB, DMsg(), and FilterOnSuppliedFunctions().

SearchEngine::SearchTermCount ( )

Get total number of search terms indexed by search engine.

Returns
int Count of terms.

Definition at line 416 of file SearchEngine.php.

SearchEngine::SearchTerms ( )

Get normalized list of search terms.

Returns
array Array of search terms.

Definition at line 266 of file SearchEngine.php.

SearchEngine::SearchTime ( )

Get time that last search took, in seconds.

Returns
float Time in seconds, with microseconds.

Definition at line 275 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.

Parameters
array$SynonymListArray of arrays of synonyms, with words for index.

Definition at line 663 of file SearchEngine.php.

References AddSynonyms(), and RemoveAllSynonyms().

SearchEngine::UpdateForItem (   $ItemId,
  $ItemType 
)

Update search database for the specified item.

Parameters
int$ItemIdID of item.
int$ItemTypeNumerical type of item.

Definition at line 318 of file SearchEngine.php.

References GetFieldContent().

Referenced by UpdateForItems().

Here is the caller graph for this function:

SearchEngine::UpdateForItems (   $StartingItemId,
  $NumberOfItems 
)

Update search database for the specified range of items.

Parameters
int$StartingItemIdID of item to start with.
int$NumberOfItemsMaximum number of items to update.
Returns
int ID of last item updated.

Definition at line 370 of file SearchEngine.php.

References UpdateForItem().

Member Data Documentation

SearchEngine::$DB
protected
SearchEngine::$DebugLevel
protected

Definition at line 764 of file SearchEngine.php.

SearchEngine::$FilterFuncs
protected

Definition at line 765 of file SearchEngine.php.

SearchEngine::$ItemIdFieldName
protected

Definition at line 766 of file SearchEngine.php.

Referenced by __construct().

SearchEngine::$ItemTableName
protected

Definition at line 767 of file SearchEngine.php.

Referenced by __construct().

SearchEngine::$ItemTypeFieldName
protected

Definition at line 768 of file SearchEngine.php.

Referenced by __construct().

SearchEngine::$LastSearchTime
protected

Definition at line 769 of file SearchEngine.php.

Referenced by SearchTime().

SearchEngine::$NumberOfResultsAvailable
protected

Definition at line 770 of file SearchEngine.php.

SearchEngine::$StemmingEnabled = TRUE
protected

Definition at line 771 of file SearchEngine.php.

SearchEngine::$SynonymsEnabled = TRUE
protected

Definition at line 772 of file SearchEngine.php.

const SearchEngine::COMPARISON_OPERATOR_PATTERN = '/^([><=^$@]+|!=)([^><=^$@])/'

Definition at line 2316 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 783 of file SearchEngine.php.

const SearchEngine::LOGIC_AND = 1
const SearchEngine::LOGIC_OR = 2
const SearchEngine::SEARCHLOGIC_AND = 1

Definition at line 2312 of file SearchEngine.php.

const SearchEngine::SEARCHLOGIC_OR = 2

Definition at line 2313 of file SearchEngine.php.

const SearchEngine::STEM_ID_OFFSET = 1000000

Definition at line 784 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().


The documentation for this class was generated from the following file: