CWIS Developer Documentation
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

 SearchEngine ($ItemTableName, $ItemIdFieldName)
 Object constructor. More...
 
 AddField ($FieldName, $FieldType, $Weight, $UsedInKeywordSearch)
 Add field to include in searching. More...
 
 FieldType ($FieldName)
 Get type of specified field (text/numeric/date/daterange). More...
 
 FieldWeight ($FieldName)
 Get search weight for specified field. More...
 
 FieldInKeywordSearch ($FieldName)
 Get whether specified field is included in keyword searches. More...
 
 DebugLevel ($NewValue)
 Set debug output level. More...
 
 Search ($SearchString, $StartingResult=0, $NumberOfResults=10, $SortByField=NULL, $SortDescending=TRUE)
 Perform keyword search. 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...
 
 GroupedSearch ($SearchGroups, $StartingResult=0, $NumberOfResults=10, $SortByField=NULL, $SortDescending=TRUE)
 Perform search with logical groups of fielded searches. More...
 
 AddResultFilterFunction ($FunctionName)
 Add function that will be called to filter search results. More...
 
 DefaultSearchLogic ($NewSetting=NULL)
 Get/set default search logic (LOGIC_AND or LOGIC_OR). More...
 
 SearchTermsRequiredByDefault ($NewSetting=TRUE)
 Set default search logic. More...
 
 NumberOfResults ()
 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 ($SearchStrings)
 Get total of weights for all fields involved in search, useful for assessing scale of scores in search results. More...
 
 UpdateForItem ($ItemId)
 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 ($FieldName)
 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...
 

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 STEM_ID_OFFSET = 1000000
 
const SEARCHLOGIC_AND = 1
 
const SEARCHLOGIC_OR = 2
 

Protected Member Functions

 SearchFieldForPhrases ($FieldName, $Phrase)
 
 FilterOnSuppliedFunctions ($Scores)
 
 GetFieldContent ($ItemId, $FieldName)
 
 DMsg ($Level, $Msg)
 

Protected Attributes

 $DB
 
 $DebugLevel
 
 $ItemTableName
 
 $ItemIdFieldName
 
 $NumberOfResultsAvailable
 
 $LastSearchTime
 
 $FilterFuncs
 
 $DefaultSearchLogic = self::LOGIC_AND
 
 $StemmingEnabled = TRUE
 
 $SynonymsEnabled = TRUE
 

Detailed Description

Core metadata archive search engine class.

Definition at line 13 of file SearchEngine.php.

Member Function Documentation

SearchEngine::AddField (   $FieldName,
  $FieldType,
  $Weight,
  $UsedInKeywordSearch 
)

Add field to include in searching.

Parameters
string$FieldNameName of field.
int$FieldTypeType of field (FIELDTYPE_ constant value).
int$WeightNumeric search weight for field.
bool$UsedInKeywordSearchIf TRUE, field is included in keyword searches.

Definition at line 59 of file SearchEngine.php.

Referenced by SPTSearchEngine\SPTSearchEngine().

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 348 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 572 of file SearchEngine.php.

Referenced by LoadSynonymsFromFile(), and SetAllSynonyms().

Here is the caller graph for this function:

SearchEngine::DebugLevel (   $NewValue)

Set debug output level.

Values above zero trigger diagnostic output.

Parameters
int$NewValueNew debugging level.

Definition at line 97 of file SearchEngine.php.

Referenced by SearchEngine(), and SPTSearchEngine\SearchFieldForPhrases().

Here is the caller graph for this function:

SearchEngine::DefaultSearchLogic (   $NewSetting = NULL)

Get/set default search logic (LOGIC_AND or LOGIC_OR).

Parameters
enum$NewSettingNew search logic setting. (OPTIONAL)
Returns
enum Current search logic setting.

Definition at line 359 of file SearchEngine.php.

References $DefaultSearchLogic.

Referenced by GroupedSearch(), SPTSearchEngine\SearchFieldsForComparisonMatches(), and SearchTermsRequiredByDefault().

Here is the caller graph for this function:

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

Definition at line 2099 of file SearchEngine.php.

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

Here is the caller graph for this function:

SearchEngine::DropField (   $FieldName)

Drop all data pertaining to field from search database.

Parameters
string$FieldNameName of field to drop.

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

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.

Definition at line 198 of file SearchEngine.php.

References DMsg().

SearchEngine::FieldedSearchWeightScale (   $SearchStrings)

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

Parameters
array$SearchStringsArray of arrays of search strings, with field names for index.
Returns
int Total of weights.

Definition at line 412 of file SearchEngine.php.

SearchEngine::FieldInKeywordSearch (   $FieldName)

Get whether specified field is included in keyword searches.

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

Definition at line 90 of file SearchEngine.php.

SearchEngine::FieldType (   $FieldName)

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

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

Definition at line 74 of file SearchEngine.php.

SearchEngine::FieldWeight (   $FieldName)

Get search weight for specified field.

Parameters
string$FieldNameName of field.
Returns
int Search weight.

Definition at line 82 of file SearchEngine.php.

SearchEngine::FilterOnSuppliedFunctions (   $Scores)
protected

Definition at line 1771 of file SearchEngine.php.

SearchEngine::GetAllSynonyms ( )

Get all synonyms.

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

Definition at line 702 of file SearchEngine.php.

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

Definition at line 2056 of file SearchEngine.php.

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 664 of file SearchEngine.php.

SearchEngine::GroupedSearch (   $SearchGroups,
  $StartingResult = 0,
  $NumberOfResults = 10,
  $SortByField = NULL,
  $SortDescending = TRUE 
)

Perform search with logical groups of fielded searches.

Parameters
array$SearchGroups
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.

Definition at line 240 of file SearchEngine.php.

References $DefaultSearchLogic, DefaultSearchLogic(), and DMsg().

SearchEngine::ItemCount ( )

Get total number of items indexed by search engine.

Returns
int Count of items.

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

References AddSynonyms().

SearchEngine::NumberOfResults ( )

Get number of results found by most recent search.

Returns
int Result count.

Definition at line 382 of file SearchEngine.php.

References $NumberOfResultsAvailable.

SearchEngine::RemoveAllSynonyms ( )

Remove all synonyms.

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

SearchEngine::Search (   $SearchString,
  $StartingResult = 0,
  $NumberOfResults = 10,
  $SortByField = NULL,
  $SortDescending = TRUE 
)

Perform keyword search.

Parameters
string$SearchStringKeyword string to search for.
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.

Definition at line 120 of file SearchEngine.php.

References DMsg().

SearchEngine::SearchEngine (   $ItemTableName,
  $ItemIdFieldName 
)

Object constructor.

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

Definition at line 38 of file SearchEngine.php.

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

Referenced by SPTSearchEngine\SPTSearchEngine().

Here is the caller graph for this function:

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

Definition at line 1544 of file SearchEngine.php.

SearchEngine::SearchTermCount ( )

Get total number of search terms indexed by search engine.

Returns
int Count of terms.

Definition at line 549 of file SearchEngine.php.

SearchEngine::SearchTerms ( )

Get normalized list of search terms.

Returns
array Array of search terms.

Definition at line 391 of file SearchEngine.php.

SearchEngine::SearchTermsRequiredByDefault (   $NewSetting = TRUE)

Set default search logic.

Parameters
bool$NewSettingIf TRUE then default logic is LOGIC_AND, otherwise default logic is LOGIC_OR.

Definition at line 373 of file SearchEngine.php.

References DefaultSearchLogic().

SearchEngine::SearchTime ( )

Get time that last search took, in seconds.

Returns
float Time in seconds, with microseconds.

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

References AddSynonyms(), and RemoveAllSynonyms().

SearchEngine::UpdateForItem (   $ItemId)

Update search database for the specified item.

Parameters
int$ItemIdID of item.

Definition at line 450 of file SearchEngine.php.

References GetFieldContent().

Referenced by UpdateForItems(), and SPTSearchEngine\UpdateForResource().

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 499 of file SearchEngine.php.

References UpdateForItem().

Member Data Documentation

SearchEngine::$DB
protected

Definition at line 857 of file SearchEngine.php.

Referenced by SPTSearchEngine\GetResultFacets().

SearchEngine::$DebugLevel
protected

Definition at line 858 of file SearchEngine.php.

SearchEngine::$DefaultSearchLogic = self::LOGIC_AND
protected

Definition at line 864 of file SearchEngine.php.

Referenced by DefaultSearchLogic(), and GroupedSearch().

SearchEngine::$FilterFuncs
protected

Definition at line 863 of file SearchEngine.php.

SearchEngine::$ItemIdFieldName
protected

Definition at line 860 of file SearchEngine.php.

Referenced by SearchEngine().

SearchEngine::$ItemTableName
protected

Definition at line 859 of file SearchEngine.php.

Referenced by SearchEngine().

SearchEngine::$LastSearchTime
protected

Definition at line 862 of file SearchEngine.php.

Referenced by SearchTime().

SearchEngine::$NumberOfResultsAvailable
protected

Definition at line 861 of file SearchEngine.php.

Referenced by NumberOfResults().

SearchEngine::$StemmingEnabled = TRUE
protected

Definition at line 865 of file SearchEngine.php.

SearchEngine::$SynonymsEnabled = TRUE
protected

Definition at line 866 of file SearchEngine.php.

const SearchEngine::FIELDTYPE_DATE = 3

Definition at line 24 of file SearchEngine.php.

const SearchEngine::FIELDTYPE_DATERANGE = 4

Definition at line 25 of file SearchEngine.php.

const SearchEngine::FIELDTYPE_NUMERIC = 2

Definition at line 23 of file SearchEngine.php.

const SearchEngine::FIELDTYPE_TEXT = 1

Definition at line 22 of file SearchEngine.php.

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

Definition at line 2110 of file SearchEngine.php.

const SearchEngine::SEARCHLOGIC_OR = 2

Definition at line 2111 of file SearchEngine.php.

const SearchEngine::STEM_ID_OFFSET = 1000000

Definition at line 877 of file SearchEngine.php.

const SearchEngine::WORD_EXCLUDED = 2

Definition at line 29 of file SearchEngine.php.

const SearchEngine::WORD_PRESENT = 1

Definition at line 28 of file SearchEngine.php.

const SearchEngine::WORD_REQUIRED = 4

Definition at line 30 of file SearchEngine.php.


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