예제 #1
0
    /**
     * Build a Lucene Query.
     * 
     * @param  array   $data      - The data (normally $_POST), needs specific array keys
     * @param  boolean $anonymous - whether we build query for anonymous user access or not
     * @return string             - the returned query string
     */
    public static function buildQuery($data, $anonymous = true) {
        if (isset($data['search_terms']) && !empty($data['search_terms']) &&
                isset($data['course_id']) && !empty($data['course_id'])) {
            $terms = explode(' ', Indexer::filterQuery($data['search_terms']));
            $queryStr = '(';
            foreach ($terms as $term) {
                $queryStr .= 'title:' . $term . '* ';
                $queryStr .= 'content:' . $term . '* ';
                $queryStr .= 'filename:' . $term . '* ';
                $queryStr .= 'comment:' . $term . '* ';
                $queryStr .= 'creator:' . $term . '* ';
                $queryStr .= 'subject:' . $term . '* ';
                $queryStr .= 'author:' . $term . '* ';
            }
            $queryStr .= ') AND courseid:' . $data['course_id'] . ' AND doctype:doc AND visible:1';
            if ($anonymous) {
                $queryStr .= ' AND public:1';
            }
            return $queryStr;
        }

        return null;
    }
예제 #2
0
    /**
     * Build a Lucene Query.
     * 
     * @param  array   $data      - The data (normally $_POST), needs specific array keys
     * @param  boolean $anonymous - whether we build query for anonymous user access or not
     * @return string             - the returned query string
     */
    public static function buildQuery($data, $anonymous = true) {
        if (isset($data['search_terms']) && !empty($data['search_terms']) &&
                isset($data['course_id']) && !empty($data['course_id'])) {
            $terms = explode(' ', Indexer::filterQuery($data['search_terms']));
            $queryStr = '(';
            foreach ($terms as $term) {
                $queryStr .= 'title:' . $term . '* ';
            }
            $queryStr .= ') AND courseid:' . $data['course_id'] . ' AND doctype:ftopic';
            return $queryStr;
        }

        return null;
    }
예제 #3
0
 /**
  * Append to the Lucene Query according to data input.
  * 
  * @param  array   $data     - The data (normally coming from $_POST)
  * @param  string  $key      - $data[key]
  * @param  string  $queryKey - Lucene Document field key
  * @param  string  $queryStr - The Lucene Query string
  * @param  boolean $needsOR  - special flag for appending OR
  * @return array             - returns the Lucene Query string and the flag for appending OR in an array
  */
 private static function appendQuery($data, $key, $queryKey, $queryStr, $needsOR) {
     if (isset($data[$key]) && !empty($data[$key])) {
         $terms = explode(' ', Indexer::filterQuery($data[$key]));
         foreach ($terms as $term) {
             $queryStr .= ($needsOR) ? 'OR ' : '';
             $queryStr .= $queryKey . ':' . $term . '* ';
             $needsOR = true;
         }
     }
     return array($queryStr, $needsOR);
 }