Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
mahara
mahara
Commits
7e16a697
Commit
7e16a697
authored
Feb 19, 2007
by
Martyn Smith
Committed by
Martyn Smith
Feb 19, 2007
Browse files
Finished self search, result linking doesn't work properly yet.
parent
19d9deaf
Changes
4
Hide whitespace changes
Inline
Side-by-side
htdocs/search/solr/lib.php
View file @
7e16a697
...
...
@@ -187,17 +187,24 @@ END;
*
*/
public
static
function
self_search
(
$query_string
,
$limit
,
$offset
,
$type
=
'all'
)
{
global
$USER
;
if
(
$type
!=
'artefact'
&&
$type
!=
'view'
)
{
$type
=
'artefact OR view'
;
}
$results
=
self
::
send_query
(
$query_string
,
$limit
,
$offset
,
array
(
'type'
=>
$type
));
$results
=
self
::
send_query
(
$query_string
,
$limit
,
$offset
,
array
(
'type'
=>
$type
,
'owner'
=>
$USER
->
get
(
'id'
)),
'*'
,
true
);
if
(
is_array
(
$results
[
'data'
]))
{
foreach
(
$results
[
'data'
]
as
&
$result
)
{
$new_result
=
array
();
foreach
(
$result
as
$key
=>
&
$value
)
{
if
(
$key
==
'id'
||
$key
==
'title'
||
$key
==
'description'
||
$key
==
'
type
'
)
{
if
(
$key
==
'id'
||
$key
==
'title'
||
$key
==
'type'
||
$key
==
'description'
||
$key
==
'
summary'
||
$key
==
'tags
'
)
{
$new_result
[
$key
]
=
$value
;
}
else
if
(
$key
==
'ref_artefacttype'
)
{
$new_result
[
'artefacttype'
]
=
$value
;
}
}
$result
=
$new_result
;
}
...
...
@@ -231,7 +238,7 @@ END;
'ref_artefacttype'
=>
$artefact
[
'artefacttype'
],
'type'
=>
'artefact'
,
'title'
=>
$artefact
[
'title'
],
'description'
=>
$artefact
[
'description'
],
'description'
=>
strip_tags
(
$artefact
[
'description'
]
)
,
'tags'
=>
join
(
', '
,
get_column
(
'artefact_tag'
,
'tag'
,
'artefact'
,
$artefact
[
'id'
])),
'ctime'
=>
$artefact
[
'ctime'
],
'mtime'
=>
$artefact
[
'mtime'
],
...
...
@@ -377,7 +384,7 @@ END;
}
}
private
static
function
send_query
(
$query
,
$limit
,
$offset
,
$constraints
=
array
(),
$fields
=
'*'
)
{
private
static
function
send_query
(
$query
,
$limit
,
$offset
,
$constraints
=
array
(),
$fields
=
'*'
,
$highlight
=
false
)
{
$q
=
array
();
foreach
(
$constraints
as
$key
=>
$value
)
{
...
...
@@ -402,8 +409,15 @@ END;
'fl'
=>
$fields
,
'start'
=>
$offset
,
'rows'
=>
$limit
,
//'indent' => 1,
);
if
(
$highlight
)
{
$data
[
'hl'
]
=
'true'
;
$data
[
'hl.fl'
]
=
'title,description,tags'
;
$data
[
'hl.snippets'
]
=
'3'
;
}
$url
=
get_config_plugin
(
'search'
,
'solr'
,
'solrurl'
)
.
'select'
;
if
(
!
$client
->
submit
(
$url
,
$data
))
{
...
...
@@ -429,6 +443,28 @@ END;
return
$result
;
}
$summary_info
=
array
();
if
(
$highlight
)
{
$hlroot
=
$dom
->
getElementsByTagName
(
'lst'
);
foreach
(
$hlroot
as
$node
)
{
if
(
$node
->
getAttribute
(
'name'
)
==
'highlighting'
)
{
$hlroot
=
$node
;
break
;
}
}
foreach
(
$hlroot
->
childNodes
as
$node
)
{
if
(
$node
->
nodeType
!=
XML_ELEMENT_NODE
||
$node
->
nodeName
!=
'lst'
)
{
continue
;
}
$idtype
=
$node
->
getAttribute
(
'name'
);
$summary_info
[
$idtype
]
=
''
;
foreach
(
$node
->
getElementsByTagName
(
'str'
)
as
$text
)
{
$summary_info
[
$idtype
]
.
=
$text
->
textContent
;
}
}
}
$root
=
$dom
->
getElementsByTagName
(
'result'
);
// get root node
$root
=
$root
->
item
(
0
);
...
...
@@ -442,7 +478,7 @@ END;
// loop over results
foreach
(
$root
->
childNodes
as
$node
)
{
if
(
$node
->
nodeType
!=
XML_ELEMENT_NODE
||
$node
->
nodeName
!=
'doc'
)
{
log_debug
(
'bad node
'
);
log_debug
(
'bad node
: '
.
$node
->
nodeName
);
continue
;
}
$result
=
array
();
...
...
@@ -459,6 +495,14 @@ END;
$result
[
$field
->
getAttribute
(
'name'
)]
=
$value
->
wholeText
;
}
if
(
isset
(
$summary_info
[
$result
[
'idtype'
]]))
{
$result
[
'summary'
]
=
$summary_info
[
$result
[
'idtype'
]];
}
if
(
empty
(
$result
[
'summary'
]))
{
$result
[
'summary'
]
=
$result
[
'description'
];
}
$results
[
'data'
][]
=
$result
;
}
...
...
htdocs/selfsearch.php
View file @
7e16a697
...
...
@@ -44,15 +44,31 @@ results.statevars.push('query');
results.statevars.push('type');
results.emptycontent = {$enc_noresults};
results.rowfunction = function (r, n, d) {
logDebug(r, n, d);
return TR(null, TD(null, r.title));
var titleElement = H3(null, A({'href': config.wwwroot + 'view/view.php?artefactid=' + r.id}, r.title));
var descriptionElement = P(null);
descriptionElement.innerHTML = r.summary;
return TR(null, TD(null,
titleElement,
descriptionElement
));
};
function dosearch(e) {
results.query = $('search_query').value;
results.offset = 0;
results.doupdate();
}
EOF;
if
(
!
empty
(
$query
))
{
$javascript
.
=
'results.query = '
.
json_encode
(
$query
)
.
";
\n
"
;
$javascript
.
=
"results.updateOnLoad();
\n
"
;
}
else
{
$javascript
.
=
'results.query = \'\';'
;
}
$smarty
=
smarty
(
array
(
'tablerenderer'
));
$smarty
->
assign
(
'query'
,
$query
);
...
...
htdocs/theme/default/templates/header.tpl
View file @
7e16a697
...
...
@@ -2,6 +2,7 @@
<html>
<head>
<title>
{
$PAGETITLE
|
escape
}
</title>
<script
type=
"text/javascript"
src=
"
{
$WWWROOT
}
js/firebug/firebug.js"
></script>
<script
type=
"text/javascript"
>
var
config
=
{
literal
}{{/
literal
}
'theme'
:
{
$THEMELIST
}
,
...
...
htdocs/theme/default/templates/selfsearch.tpl
View file @
7e16a697
...
...
@@ -3,10 +3,12 @@
{
include
file
=
"columnfullstart.tpl"
}
<div
class=
"searchform"
>
<h2>
{
str
tag
=
"search"
}
</h2>
<label>
Query:
<input
type=
"text"
name=
"search_query"
id=
"search_query"
value=
"
{
$query
|
escape
}
"
>
</label>
<button
type=
"button"
onclick=
"doSearch();"
>
{
str
tag
=
"go"
}
</button>
<form
method=
"post"
onsubmit=
"dosearch(); return false;"
>
<label>
Query:
<input
type=
"text"
name=
"query"
id=
"search_query"
value=
"
{
$query
|
escape
}
"
>
</label>
<button
type=
"submit"
class=
"button"
>
{
str
tag
=
"go"
}
</button>
</form>
</div>
<div
id=
"selfsearchresults"
>
<h3>
{
str
tag
=
"results"
}
</h3>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment