aboutsummaryrefslogtreecommitdiff
path: root/app/Models/Context.php
diff options
context:
space:
mode:
authorGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-02-17 13:05:55 +0100
committerGravatar Marien Fressinaud <dev@marienfressinaud.fr> 2015-02-17 13:05:55 +0100
commitc0aba0a371f408ada8dec3e5c8f7fb177ceac3f8 (patch)
tree0dfbe485d5f05e79cffa5ef83b6323e4c0b5dfa9 /app/Models/Context.php
parent4bb8548eccf22b40c25352fe27c66f1f8039ebcd (diff)
parent964e67d4a4914008b0f7bc941d77215b2038012c (diff)
Merge pull request #792 from aledeg/extract-search-from-context
Extract search from context
Diffstat (limited to 'app/Models/Context.php')
-rw-r--r--app/Models/Context.php148
1 files changed, 0 insertions, 148 deletions
diff --git a/app/Models/Context.php b/app/Models/Context.php
index 645639907..f00bb1e97 100644
--- a/app/Models/Context.php
+++ b/app/Models/Context.php
@@ -302,152 +302,4 @@ class FreshRSS_Context {
return false;
}
- /**
- * Parse search string to extract the different keywords.
- *
- * @return array
- */
- public function parseSearch() {
- $search = self::$search;
- $intitle = $this->parseIntitleSearch($search);
- $author = $this->parseAuthorSearch($intitle['string']);
- $inurl = $this->parseInurlSearch($author['string']);
- $pubdate = $this->parsePubdateSearch($inurl['string']);
- $date = $this->parseDateSearch($pubdate['string']);
-
- $remaining = array();
- $remaining_search = trim($date['string']);
- if (strcmp($remaining_search, '') != 0) {
- $remaining['search'] = $remaining_search;
- }
-
- return array_merge($intitle['search'], $author['search'], $inurl['search'], $date['search'], $pubdate['search'], $remaining);
- }
-
- /**
- * Parse the search string to find intitle keyword and the search related
- * to it.
- * The search is the first word following the keyword.
- * It returns an array containing the matched string and the search.
- *
- * @param string $search
- * @return array
- */
- private function parseIntitleSearch($search) {
- if (preg_match('/intitle:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $search, $matches)) {
- return array(
- 'string' => str_replace($matches[0], '', $search),
- 'search' => array('intitle' => $matches['search']),
- );
- }
- if (preg_match('/intitle:(?P<search>\w*)/', $search, $matches)) {
- return array(
- 'string' => str_replace($matches[0], '', $search),
- 'search' => array('intitle' => $matches['search']),
- );
- }
- return array(
- 'string' => $search,
- 'search' => array(),
- );
- }
-
- /**
- * Parse the search string to find author keyword and the search related
- * to it.
- * The search is the first word following the keyword except when using
- * a delimiter. Supported delimiters are single quote (') and double
- * quotes (").
- * It returns an array containing the matched string and the search.
- *
- * @param string $search
- * @return array
- */
- private function parseAuthorSearch($search) {
- if (preg_match('/author:(?P<delim>[\'"])(?P<search>.*)(?P=delim)/U', $search, $matches)) {
- return array(
- 'string' => str_replace($matches[0], '', $search),
- 'search' => array('author' => $matches['search']),
- );
- }
- if (preg_match('/author:(?P<search>\w*)/', $search, $matches)) {
- return array(
- 'string' => str_replace($matches[0], '', $search),
- 'search' => array('author' => $matches['search']),
- );
- }
- return array(
- 'string' => $search,
- 'search' => array(),
- );
- }
-
- /**
- * Parse the search string to find inurl keyword and the search related
- * to it.
- * The search is the first word following the keyword except.
- * It returns an array containing the matched string and the search.
- *
- * @param string $search
- * @return array
- */
- private function parseInurlSearch($search) {
- if (preg_match('/inurl:(?P<search>[^\s]*)/', $search, $matches)) {
- return array(
- 'string' => str_replace($matches[0], '', $search),
- 'search' => array('inurl' => $matches['search']),
- );
- }
- return array(
- 'string' => $search,
- 'search' => array(),
- );
- }
-
- /**
- * Parse the search string to find date keyword and the search related
- * to it.
- * The search is the first word following the keyword.
- * It returns an array containing the matched string and the search.
- *
- * @param string $search
- * @return array
- */
- private function parseDateSearch($search) {
- if (preg_match('/date:(?P<search>[^\s]*)/', $search, $matches)) {
- list($min_date, $max_date) = parseDateInterval($matches['search']);
- return array(
- 'string' => str_replace($matches[0], '', $search),
- 'search' => array('min_date' => $min_date, 'max_date' => $max_date),
- );
- }
- return array(
- 'string' => $search,
- 'search' => array(),
- );
- }
-
- /**
- * Parse the search string to find pubdate keyword and the search related
- * to it.
- * The search is the first word following the keyword.
- * It returns an array containing the matched string and the search.
- *
- * @param string $search
- * @return array
- */
- private function parsePubdateSearch($search) {
- if (preg_match('/pubdate:(?P<search>[^\s]*)/', $search, $matches)) {
- list($min_date, $max_date) = parseDateInterval($matches['search']);
- return array(
- 'string' => str_replace($matches[0], '', $search),
- 'search' => array('min_pubdate' => $min_date, 'max_pubdate' => $max_date),
- );
- }
- return array(
- 'string' => $search,
- 'search' => array(),
- );
- }
-
}