SNIPPET_TITLE_LENGTH
SNIPPET_TITLE_LENGTH
Model used to keep track for analytic and user experience activities that users carry out on a Yioop web site. For analytics things that might tracked are wiki page views, queries, query outcomes. For UX things that the impression model allows is to keep track of recent group a user has visited to provide better bread crumb drop downs, make the manage account landing page list more relevant groups, determine start of whether a media item has been watched, completely watched, etc.
In terms of how things are implemented in the database. The tables ITEM_IMPRESSION and ITEM_IMPRESSION_SUMMARY contain the raw statistics of activities. If differential privacy is in use then ITEM_IMPRESSION_STAT keeps track of fuzzified statistics.
__construct(string $db_name = \seekquarry\yioop\configs\DB_NAME, boolean $connect = true, $web_site = null)
Sets up the database manager that will be used and name of the search engine database
string | $db_name | the name of the database for the search engine |
boolean | $connect | whether to connect to the database by default after making the datasource class |
$web_site |
fileGetContents(string $filename, boolean $force_read = false) : string
Either a wrapper for file_get_contents, or if a WebSite object is being used to serve pages, it reads it in using blocking I/O file_get_contents() and caches it before return its string contents.
Note this function assumes that only the web server is performing I/O with this file. filemtime() can be used to see if a file on disk has been changed and then you can use $force_read = true below to force re- reading the file into the cache
string | $filename | name of file to get contents of |
boolean | $force_read | whether to force the file to be read from presistent storage rather than the cache |
contents of the file given by $filename
filePutContents(string $filename, string $data)
Either a wrapper for file_put_contents, or if a WebSite object is being used to serve pages, writes $data to the persistent file with name $filename. Saves a copy in the RAM cache if there is a copy already there.
string | $filename | name of file to write to persistent storages |
string | $data | string of data to store in file |
formatSinglePageResult(array $page, array $words = null, integer $description_length = self::DEFAULT_DESCRIPTION_LENGTH) : array
Given a page summary, extracts snippets which are related to a set of search words. For each snippet, bold faces the search terms, and then creates a new summary array.
array | $page | a single search result summary |
array | $words | keywords (typically what was searched on) |
integer | $description_length | length of the description |
$page which has been snippified and bold faced
getSnippets(string $text, array $words, string $description_length) : string
Given a string, extracts a snippets of text related to a given set of key words. For a given word a snippet is a window of characters to its left and right that is less than a maximum total number of characters.
There is also a rule that a snippet should avoid ending in the middle of a word
string | $text | haystack to extract snippet from |
array | $words | keywords used to make look in haystack |
string | $description_length | length of the description desired |
a concatenation of the extracted snippets of each word
boldKeywords(string $text, array $words) : string
Given a string, wraps in bold html tags a set of key words it contains.
string | $text | haystack string to look for the key words |
array | $words | an array of words to bold face |
the resulting string after boldfacing has been applied
isSingleLocalhost(array $machine_urls, string $index_timestamp = -1) : boolean
Used to determine if an action involves just one yioop instance on the current local machine or not
array | $machine_urls | urls of yioop instances to which the action applies |
string | $index_timestamp | if timestamp exists checks if the index has declared itself to be a no network index. |
whether it involves a single local yioop instance (true) or not (false)
searchArrayToWhereOrderClauses(array $search_array, array $any_fields = array('status')) : array
Creates the WHERE and ORDER BY clauses for a query of a Yioop table such as USERS, ROLE, GROUP, which have associated search web forms. Searches are case insensitive
array | $search_array | each element of this is a quadruple name of a field, what comparison to perform, a value to check, and an order (ascending/descending) to sort by |
array | $any_fields | these fields if present in search array but with value "-1" will be skipped as part of the where clause but will be used for order by clause |
string for where clause, string for order by clause
getRows(integer $limit, integer $num, \seekquarry\yioop\models\int& $total, array $search_array = array(), array $args = null) : array
Gets a range of rows which match the provided search criteria from $th provided table
integer | $limit | starting row from the potential results to return |
integer | $num | number of rows after start row to return |
\seekquarry\yioop\models\int& | $total | gets set with the total number of rows that can be returned by the given database query |
array | $search_array | each element of this is a quadruple name of a field, what comparison to perform, a value to check, and an order (ascending/descending) to sort by |
array | $args | additional values which may be used to get rows (what these are will typically depend on the subclass implementation) |
selectCallback(mixed $args = null) : string
Controls which columns and the names of those columns from the tables underlying the given model should be return from a getRows call.
This defaults to *, but in general will be overriden in subclasses of Model
mixed | $args | any additional arguments which should be used to determine the columns |
a comma separated list of columns suitable for a SQL query
fromCallback(mixed $args = null) : string
Controls which tables and the names of tables underlie the given model and should be used in a getRows call This defaults to the single table whose name is whatever is before Model in the name of the model. For example, by default on FooModel this method would return "FOO". If a different behavior, this can be overriden in subclasses of Model
mixed | $args | any additional arguments which should be used to determine these tables |
a comma separated list of tables suitable for a SQL query
whereCallback(mixed $args = null) : string
Controls the WHERE clause of the SQL query that underlies the given model and should be used in a getRows call.
This defaults to an empty WHERE clause.
mixed | $args | additional arguments that might be used to construct the WHERE clause. |
a SQL WHERE clause
rowCallback(array $row, mixed $args) : array
Called after as row is retrieved by getRows from the database to perform some manipulation that would be useful for this model.
For example, in CrawlModel, after a row representing a crawl mix has been gotten, this is used to perform an additional query to marshal its components. By default this method just returns this row unchanged.
array | $row | row as retrieved from database query |
mixed | $args | additional arguments that might be used by this callback |
$row after callback manipulation
postQueryCallback(array $rows) : array
Called after getRows has retrieved all the rows that it would retrieve but before they are returned to give one last place where they could be further manipulated. For example, in MachineModel this callback is used to make parallel network calls to get the status of each machine returned by getRows. The default for this method is to leave the rows that would be returned unchanged
array | $rows | that have been calculated so far by getRows |
$rows after this final manipulation
init(integer $user_id, integer $item_id, integer $type_id)
Used to create a new counter related to a particular user for a particular activity in the impression analytics. This entails adding both a log-like record of when the activity happened and creating a new global count for this acitvity.
integer | $user_id | id of user we are adding analytic information for |
integer | $item_id | id of particular item we are adding analytic information of |
integer | $type_id | type of particular item we are adding analytic information of (group, wiki, thread, etc) |
add(integer $user_id, integer $item_id, integer $type_id)
Used to add a count record related to a particular user for a particular activity to the impression analytics. This entails adding both a log-like record of when the activity happened and incrementing a global count of this activity.
integer | $user_id | id of user we are adding analytic information for |
integer | $item_id | id of particular item we are adding analytic information of |
integer | $type_id | type of particular item we are adding analytic information of (group, wiki, thread, etc) |
addQueryImpression(integer $query)
Used to add a count record related to a web search to the impression analytics. This entails adding a record to QUERY_ITEM if it doesn't exist together with an add() call. This is perhaps not the ideal model for this function, but didn't want to create a new model for just this one method.
integer | $query | search query we are adding an impression for |
delete(integer $user_id, integer $item_id, integer $type_id)
Used to delete information related to a particular user from the impression analytics.
integer | $user_id | id of user we are deleting analytic information for |
integer | $item_id | id of particular item we are deleting analytic information of |
integer | $type_id | type of particular item we are deleting analytic information of (group, wiki, thread, etc) |
recent(integer $user_id, integer $type_id, integer $num) : array
Returns num many most recent impression items of the given type for a user
integer | $user_id | id of user we are looking for information about |
integer | $type_id | type of particular item we want information on (group, wiki, thread, etc) |
integer | $num | how many most recent entries we want to get |
of $num many most recent item id's of $type_id of for the given $user_id
getStatistics(integer $type, integer $period, integer $filter = "", integer $group_id = \seekquarry\yioop\configs\PUBLIC_GROUP_ID, integer $user_id = \seekquarry\yioop\configs\PUBLIC_USER_ID, integer $limit, integer $num = 100) : array
Used to return an array of impression statistics for a particular update period for a particular type of impression.
integer | $type | type of impression to return statistic |
integer | $period | an update period to get statistics for in second, for example, 3600 would give statistics for an hour. Only hour, day, month, and year second quantities supported |
integer | $filter | a string to filter the items names of the statistics returns (for example, filter could be used to filter statistics about popular thread names with respect to the number of views statistics ) |
integer | $group_id | group identifier of group want stats for |
integer | $user_id | user identifier of user want stats for |
integer | $limit | first row we want from the result set |
integer | $num | number of rows we want starting from the first row in the result set |
getPeriodHistogramData(integer $type, integer $period, integer $item_id) : array
Calculates total number of views of given item id for given time period
integer | $type | the impression type to get data for |
integer | $period | time period for which to show stats |
integer | $item_id | item identifier of item for which to show stats |
getLastTimestamp(integer $period) : array
Subtracts the timestamp to get actual time period window.
To get statistics for one time period, lower time period's data needs to be extracted. For example, to get last day's stat, result in every one hour needs to be extracted in the last 24 hours
integer | $period | time period |
updatePrivacyViews(integer $item_id, integer $num_views, integer $fuzzy_num_views)
Used to update the fuzzified view counts of a thread item.
integer | $item_id | id of the thread item to update fuzzified counts for |
integer | $num_views | current number of views for item. This value is stored in the TMP_NUM_VIEWS column to remember the last time the FUZZY_NUM_VIEWS column was updated. Only when the TMP_NUM_VIEWS column differs from the NUM_VIEWS COLUMN will this method need to be called. |
integer | $fuzzy_num_views | number of views after epsilon privacy fuzzification applied. |
updateImpressionStat(integer $item_id, integer $item_type, integer $period, integer $num_views, integer $fuzzy_num_views)
Used to update the fuzzy statistics of impression items.
integer | $item_id | id of the item to update the statistics |
integer | $item_type | type of the item |
integer | $period | time period of the item |
integer | $num_views | number of views of the item for specified time period |
integer | $fuzzy_num_views | fuzzified views of the item for specified time period |
getImpressionStat(integer $item_id, integer $item_type, integer $period) : array
Returns the fuzzy statistics of the specified impression item.
If no statistics exists it creates default dummy statistics It is assumed this function is always called at least once before
integer | $item_id | id of the item to return the statistics |
integer | $item_type | type of the item |
integer | $period | time period of the item |
values of $sum and $fuzzy_num_views
initWithDb(integer $user_id, integer $item_id, integer $type_id, object $db)
Used to create a new counter related to a particular user for a particular activity in the impression analytics. This entails adding both a log-like record of when the activity happened and creating a new global count for this activity. This static method version requires having an initialized data source manager and may be appropriate to call in the context of another model.
integer | $user_id | id of user we are adding analytic information for |
integer | $item_id | id of particular item we are adding analytic information of |
integer | $type_id | type of particular item we are adding analytic information of (group, wiki, thread, etc) |
object | $db | a DatasourceManager used to query the Yioop Yioop database |
addWithDb(integer $user_id, integer $item_id, integer $type_id, object $db)
Used to add a count record related to a particular user for a particular activity to the impression analytics. This entails adding both a log-like record of when the activity happened and incrementing a global count of this activity. This static method version requires having an initialized data source manager and may be appropriate to call in the context of another model.
integer | $user_id | id of user we are adding analytic information for |
integer | $item_id | id of particular item we are adding analytic information of |
integer | $type_id | type of particular item we are adding analytic information of (group, wiki, thread, etc) |
object | $db | a DatasourceManager used to query the Yioop Yioop database |
deleteWithDb(integer $user_id, integer $item_id, integer $type_id, object $db)
Used to delete information related to a particular user from the impression analytics. This static method version requires having an initialized data source manager and may be appropriate to call in the context of another model.
integer | $user_id | id of user we are deleting analytic information for |
integer | $item_id | id of particular item we are deleting analytic information of |
integer | $type_id | type of particular item we are deleting analytic information of (group, wiki, thread, etc) |
object | $db | a DatasourceManager used to query the Yioop Yioop database |