Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
intranet-search-pg
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
project-open
intranet-search-pg
Commits
9de625a4
Commit
9de625a4
authored
Dec 29, 2023
by
Frank Bergmann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enabled search with wildcards etc
parent
6a348e24
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
156 additions
and
134 deletions
+156
-134
search.tcl
www/search.tcl
+156
-134
No files found.
www/search.tcl
View file @
9de625a4
...
@@ -103,7 +103,7 @@ regsub -all {["']} $q {} q
...
@@ -103,7 +103,7 @@ regsub -all {["']} $q {} q
# Remove accents and other special characters from
# Remove accents and other special characters from
# search query. Also remove "
@
", "
-
" and "
.
" and
# search query. Also remove "
@
", "
-
" and "
.
" and
# convert them to spaces
# convert them to spaces
set q
[
db_exec_plsql normalize
"select norm_text(:q)"
]
#
set q
[
db_exec_plsql normalize
"select norm_text(:q)"
]
set query
$q
set query
$q
#set q
[
join
$q
" & "
]
#set q
[
join
$q
" & "
]
...
@@ -152,9 +152,19 @@ set error_message "
...
@@ -152,9 +152,19 @@ set error_message "
<H2>
[
lang::message::lookup
""
intranet-search-pg.Bad_Query
"Bad Query"
]
</h2>
<H2>
[
lang::message::lookup
""
intranet-search-pg.Bad_Query
"Bad Query"
]
</h2>
[
lang::message::lookup
""
intranet-search-pg.Bad_Query_Msg
"
[
lang::message::lookup
""
intranet-search-pg.Bad_Query_Msg
"
The &
\#
93;po&
\#
91; search engine is capable of processing complex queries
The &
\#
93;po&
\#
91; search engine is capable of processing complex queries
with more then one word
.
<br>
with more then one word
and using wildcards.
<br>
However, you need to instruct the search engine how to search:
However, you need to instruct the search engine how to search:
<p>
<h3>Wildcards</h3>
<ul>
<li>Keyword<b>:*</b>:<br>
A keyword followed by a colon and an asterisk (<b>:*</b>) will find any string starting with keyword.
<br>
<li><b>:*</b>Keyword:<br>
A keyword preceeded by a colon and an asterisk (<b>:*</b>) will find any string ending with keyword.
<br>
</ul>
<h3>Conjunctions</h3>
<ul>
<ul>
<li>Keyword1 <b>&</b> Keyword2:<br>
<li>Keyword1 <b>&</b> Keyword2:<br>
Searches for objects that contain both keywords.<br>
Searches for objects that contain both keywords.<br>
...
@@ -446,6 +456,8 @@ set forum_perm_sql ""
...
@@ -446,6 +456,8 @@ set forum_perm_sql ""
# -----------------------------------------------------------
# -----------------------------------------------------------
# Build a suitable select for object types
# Build a suitable select for object types
# -----------------------------------------------------------
# -----------------------------------------------------------
...
@@ -578,84 +590,87 @@ set sql "
...
@@ -578,84 +590,87 @@ set sql "
limit :limit
limit :limit
"
"
set count 0
set count 0
db_foreach full_text_query
$sql
{
incr count
if {
[
catch
{
db_foreach full_text_query
$sql
{
# Localize the object type
incr count
regsub -all { }
$object
_type_pretty_name {_} object_type_pretty_name_sub
regsub -all { }
$biz
_object_type_pretty_name {_} biz_object_type_pretty_name_sub
set object_type_pretty_name
[
lang::message::lookup
""
intranet-core.$object_type_pretty_name_sub
$object
_type_pretty_name
]
set biz_object_type_pretty_name
[
lang::message::lookup
""
intranet-core.$biz_object_type_pretty_name_sub
$biz
_object_type_pretty_name
]
# Localize the object type
regsub -all
{
}
$object
_type_pretty_name
{
_
}
object_type_pretty_name_sub
regsub -all
{
}
$biz
_object_type_pretty_name
{
_
}
biz_object_type_pretty_name_sub
set object_type_pretty_name
[
lang::message::lookup
""
intranet-core.$object_type_pretty_name_sub
$object
_type_pretty_name
]
set biz_object_type_pretty_name
[
lang::message::lookup
""
intranet-core.$biz_object_type_pretty_name_sub
$biz
_object_type_pretty_name
]
# Skip further permissions checking if we reach the
# maximum number of records. However, keep on counting
# until "
limit
" in order to get an idea of the total
# number of results
if {
$count
>
$results
_per_page} {
continue
}
set name_link
$name
# Skip further permissions checking if we reach the
if {"" !=
$object
_url} {
# maximum number of records. However, keep on counting
set name_link "
<a href=
\"
$object
_url$object_id
\"
>$name</a>
\n
"
# until
"limit"
in order to get an idea of the total
}
# number of results
if
{
$count
>
$results
_per_page
}
{
set text
[
im_tsvector_to_headline
$full
_text_index
]
continue
set headline
[
db_string headline
"select ts_headline(:text, :q::tsquery)"
-default
""
]
# Final permission test: Make sure no object slips through security
# even if it's kind of slow to do this iteratively...
switch
$object
_type {
im_project {
im_project_permissions
$current
_user_id
$object
_id view read write admin
if {!
$read
} { continue }
}
}
user {
im_user_permissions
$current
_user_id
$object
_id view read write admin
set name_link
$name
if {!
$read
} { continue }
if
{
""
!=
$object
_url
}
{
set name_link
"<a href=
\"
$object
_url
$object
_id
\"
>
$name
</a>
\n
"
}
}
im_fs_file {
# The file is readable if it's business object is readable
set text
[
im_tsvector_to_headline
$full
_text_index
]
# AND if the folder is readable
set headline
[
db_string headline
"select ts_headline(:text, :q::tsquery)"
-default
""
]
# Very ugly: The biz_object_id is not checked for "
user
"
# Final permission test: Make sure no object slips through security
# because it is very slow... So check it here now.
# even if it's kind of slow to do this iteratively...
if {"
user
" ==
$biz
_object_type} {
switch
$object
_type
{
im_user_permissions
$current
_user_id
$biz
_object_id view read write admin
im_project
{
im_project_permissions
$current
_user_id
$object
_id view read write admin
if
{
!$read
}
{
continue
}
}
user
{
im_user_permissions
$current
_user_id
$object
_id view read write admin
if
{
!$read
}
{
continue
}
if
{
!$read
}
{
continue
}
}
}
im_fs_file
{
# The file is readable if it's business object is readable
# AND if the folder is readable
# Very ugly: The biz_object_id is not checked for
"user"
# because it is very slow... So check it here now.
if
{
"user"
==
$biz
_object_type
}
{
im_user_permissions
$current
_user_id
$biz
_object_id view read write admin
if
{
!$read
}
{
continue
}
}
# Determine the permissions for the file
# Determine the permissions for the file
set file_permission_p 0
set file_permission_p 0
db_0or1row forum_perm "
db_0or1row forum_perm
"
select f.filename,
select f.filename,
'1' as file_permission_p
'1' as file_permission_p
from im_fs_files f
from im_fs_files f
where f.file_id = :object_id
where f.file_id = :object_id
"
"
if {!
$file
_permission_p} { continue }
if
{
!$file_permission_p
}
{
continue
}
set name_link "
<a href=
\"
$object
_url$biz_object_id&view_name=files
\"
>$biz_object_name</a>:
$filename
\n
"
set name_link
"<a href=
\"
$object
_url
$biz
_object_id&view_name=files
\"
>
$biz
_object_name</a>:
$filename
\n
"
}
im_forum_topic {
# The topic is readable if it's business object is readable
# AND if the user belongs to the right "
sphere
"
# Very ugly: The biz_object_id is not checked for "
user
"
# because it is very slow... So check it here now.
if {"
user
" ==
$biz
_object_type} {
im_user_permissions
$current
_user_id
$biz
_object_id view read write admin
if {!
$read
} { continue }
}
}
im_forum_topic
{
# The topic is readable if it's business object is readable
# AND if the user belongs to the right
"sphere"
# Very ugly: The biz_object_id is not checked for
"user"
# because it is very slow... So check it here now.
if
{
"user"
==
$biz
_object_type
}
{
im_user_permissions
$current
_user_id
$biz
_object_id view read write admin
if
{
!$read
}
{
continue
}
}
# Determine if the current user belongs to the admins of
# Determine if the current user belongs to the admins of
# the "
business object
". This is necessary, because there
# the
"business object"
. This is necessary, because there
# is the forum permission "
PM Only
" which gives rights only"
# is the forum permission
"PM Only"
which gives rights only
"
# to the
(
project
)
managers of the of the container biz object
# to the (project) managers of the of the container biz object
set object_admin_sql
"
set object_admin_sql "
(
select count
(
*
)
(
select count
(
*
)
from acs_rels r,
from acs_rels r,
im_biz_object_members m
im_biz_object_members m
...
@@ -664,11 +679,11 @@ db_foreach full_text_query $sql {
...
@@ -664,11 +679,11 @@ db_foreach full_text_query $sql {
and r.rel_id = m.rel_id
and r.rel_id = m.rel_id
and m.object_role_id in
(
1301, 1302, 1303, 1309
)
and m.object_role_id in
(
1301, 1302, 1303, 1309
)
)
::integer
\n
"
)
::integer
\n
"
if
{
$user
_is_admin_p
}
{
set object_admin_sql
"1::integer
\n
"
}
if {
$user
_is_admin_p} { set object_admin_sql "
1::integer
\n
" }
# Determine the permissions for the forum item
# Determine the permissions for the forum item
set forum_permission_p 0
set forum_permission_p 0
db_0or1row forum_perm
"
db_0or1row forum_perm "
select t.subject,
select t.subject,
im_forum_permission
(
im_forum_permission
(
:current_user_id::integer,
:current_user_id::integer,
...
@@ -684,44 +699,44 @@ db_foreach full_text_query $sql {
...
@@ -684,44 +699,44 @@ db_foreach full_text_query $sql {
from im_forum_topics t
from im_forum_topics t
where t.topic_id = :object_id
where t.topic_id = :object_id
"
"
if
{
!$forum_permission_p
}
{
continue
}
if {!
$forum
_permission_p} { continue }
# set name_link "<a href=\"$url$object_id\">$biz_object_name: $subject</a>\n"
# set name_link "
<a href=
\"
$url$object
_id
\"
>$biz_object_name:
$subject
</a>
\n
"
set name_link
"<a href=
\"
$object
_url
$object
_id
\"
>
$biz
_object_name:
$subject
</a>
\n
"
set name_link "
<a href=
\"
$object
_url$object_id
\"
>$biz_object_name:
$subject
</a>
\n
"
}
}
content_item
{
content_item {
db_1row content_item_detail
"
db_1row content_item_detail "
select name, content_type
select name, content_type
from cr_items
from cr_items
where item_id = :object_id
where item_id = :object_id
"
"
regsub -all
{
}
$content
_type
{
_
}
content_type_sub
regsub -all { }
$content
_type {_} content_type_sub
regsub -all
{
:
}
$content
_type_sub
{}
content_type_sub
regsub -all {:}
$content
_type_sub {} content_type_sub
set object_type_pretty_name
[
lang::message::lookup
""
intranet-core.ContentItem_$content_type_sub
$content
_type
]
set object_type_pretty_name
[
lang::message::lookup
""
intranet-core.ContentItem_$content_type_sub
$content
_type
]
switch
$content
_type
{
switch
$content
_type {
"content_revision"
{
"
content_revision
" {
# Wiki
# Wiki
set read_p
[
permission::permission_p
\
set read_p
[
permission::permission_p
\
-object_id
$object
_id
\
-object_id
$object
_id
\
-party_id
$current
_user_id
\
-party_id
$current
_user_id
\
-privilege
"read"
]
-privilege
"read"
]
if
{
!$read_p
}
{
continue
}
if {!
$read
_p} { continue }
set name_link
"<a href=
\"
/wiki/
$name
\"
>wiki:
$name
</a>
\n
"
set name_link "
<a href=
\"
/wiki/$name
\"
>wiki:
$name
</a>
\n
"
}
}
"workflow_case_log_entry"
{
"
workflow_case_log_entry
" {
# Bug-Tracker
# Bug-Tracker
set bug_number
[
db_string bug_from_cr_item
"
set bug_number
[
db_string bug_from_cr_item
"
select bug_number from bt_bugs,cr_items where item_id=:object_id and cr_items.parent_id=bug_id
select bug_number from bt_bugs,cr_items where item_id=:object_id and cr_items.parent_id=bug_id
"
]
"
]
if
{
!$bug_number
}
{
continue
}
if {!
$bug
_number} { continue }
set name_link
"<a href=
\"
/bug-tracker/bug?bug_number=
$bug
_number
\"
>bug:
$bug
_number
$name
</a>"
set name_link "
<a href=
\"
/bug-tracker/bug?bug_number=$bug_number
\"
>bug:
$bug
_number
$name
</a>
"
}
}
"::xowiki::Page"
{
"
::xowiki::Page
" {
set page_name
""
set page_name ""
set package_mount
""
set package_mount ""
db_0or1row page_info
"
db_0or1row page_info "
select s.name as package_mount,
select s.name as package_mount,
i.name as page_name
i.name as page_name
from cr_items i,
from cr_items i,
...
@@ -734,26 +749,26 @@ db_foreach full_text_query $sql {
...
@@ -734,26 +749,26 @@ db_foreach full_text_query $sql {
i.item_id = d.item_id and
i.item_id = d.item_id and
i.live_revision = d.revision_id
i.live_revision = d.revision_id
"
"
set name_link
"<a href=
\"
/
$package
_mount/
$page
_name
\"
>
$page
_name</a>"
set name_link "
<a href=
\"
/$package_mount/$page_name
\"
>$page_name</a>
"
}
}
"::xowiki::FormPage"
{
"
::xowiki::FormPage
" {
# Skip FormPage contents
# Skip FormPage contents
continue
continue
}
}
default
{
default {
set name_link
[
lang::message::lookup
""
intranet-search-pg.Unknown_CI_Type
"unknown content_item type: %content_type%"
]
set name_link
[
lang::message::lookup
""
intranet-search-pg.Unknown_CI_Type
"unknown content_item type: %content_type%"
]
}
}
}
}
}
}
}
}
# Render the object.
# Render the object.
# With some objects we want to show more information...
# With some objects we want to show more information...
switch
$object
_type
{
switch
$object
_type
{
im_project - im_ticket - im_timesheet_task
{
im_project - im_ticket - im_timesheet_task
{
set parent_name
""
set parent_name
""
set parent_id
""
set parent_id
""
db_0or1row parent_info
"
db_0or1row parent_info
"
select parents.project_name as parent_name,
select parents.project_name as parent_name,
parents.project_id as parent_id
parents.project_id as parent_id
from im_projects parents,
from im_projects parents,
...
@@ -761,10 +776,10 @@ db_foreach full_text_query $sql {
...
@@ -761,10 +776,10 @@ db_foreach full_text_query $sql {
where parents.project_id = children.parent_id and
where parents.project_id = children.parent_id and
children.project_id = :object_id
children.project_id = :object_id
"
"
set parent_html
"<font>
[
lang::message::lookup
""
intranet-search-pg.Parent
"Parent"
]
:
set parent_html
"<font>
[
lang::message::lookup
""
intranet-search-pg.Parent
"Parent"
]
:
<a href=
\"
[
export_vars -base
"/intranet/projects/view"
{{
project_id
$parent
_id
}}]
\"
>
$parent
_name</a></font><br>
\n
"
<a href=
\"
[
export_vars -base
"/intranet/projects/view"
{{
project_id
$parent
_id
}}]
\"
>
$parent
_name</a></font><br>
\n
"
if
{
""
==
$parent
_name
}
{
set parent_html
""
}
if
{
""
==
$parent
_name
}
{
set parent_html
""
}
append result_html
"
append result_html
"
<tr>
<tr>
<td>
<td>
<font>
$object
_type_pretty_name:
$name
_link</font><br>
<font>
$object
_type_pretty_name:
$name
_link</font><br>
...
@@ -774,11 +789,11 @@ db_foreach full_text_query $sql {
...
@@ -774,11 +789,11 @@ db_foreach full_text_query $sql {
</td>
</td>
</tr>
</tr>
"
"
}
}
im_forum_topic
{
im_forum_topic
{
set parent_name
""
set parent_name
""
set parent_id
""
set parent_id
""
db_0or1row parent_info
"
db_0or1row parent_info
"
select acs_object__name(ft.object_id) as parent_name,
select acs_object__name(ft.object_id) as parent_name,
ft.object_id as parent_id,
ft.object_id as parent_id,
( select min(url) from im_biz_object_urls
( select min(url) from im_biz_object_urls
...
@@ -791,9 +806,9 @@ db_foreach full_text_query $sql {
...
@@ -791,9 +806,9 @@ db_foreach full_text_query $sql {
from im_forum_topics ft
from im_forum_topics ft
where topic_id = :object_id
where topic_id = :object_id
"
"
set parent_html
"<font>
[
lang::message::lookup
""
intranet-search-pg.Parent
"Parent"
]
: <a href=
\"
$parent
_url
$parent
_id
\"
>
$parent
_name</a></font><br>
\n
"
set parent_html
"<font>
[
lang::message::lookup
""
intranet-search-pg.Parent
"Parent"
]
: <a href=
\"
$parent
_url
$parent
_id
\"
>
$parent
_name</a></font><br>
\n
"
if
{
""
==
$parent
_name
}
{
set parent_html
""
}
if
{
""
==
$parent
_name
}
{
set parent_html
""
}
append result_html
"
append result_html
"
<tr>
<tr>
<td>
<td>
<font>
$object
_type_pretty_name:
$name
_link</font><br>
<font>
$object
_type_pretty_name:
$name
_link</font><br>
...
@@ -803,10 +818,10 @@ db_foreach full_text_query $sql {
...
@@ -803,10 +818,10 @@ db_foreach full_text_query $sql {
</td>
</td>
</tr>
</tr>
"
"
}
}
im_invoice
{
im_invoice
{
set l10n_key
"intranet-cost.
[
im_cost_type_short_name
$object
_sub_type_id
]
"
set l10n_key
"intranet-cost.
[
im_cost_type_short_name
$object
_sub_type_id
]
"
append result_html
"
append result_html
"
<tr>
<tr>
<td>
<td>
<font>
[
lang::message::lookup
""
intranet-cost.FinancialDocument
"Financial Document"
]
:
<font>
[
lang::message::lookup
""
intranet-cost.FinancialDocument
"Financial Document"
]
:
...
@@ -816,15 +831,15 @@ db_foreach full_text_query $sql {
...
@@ -816,15 +831,15 @@ db_foreach full_text_query $sql {
</td>
</td>
</tr>
</tr>
"
"
}
default
{
set parent_html
""
if
{
""
ne
$biz
_object_id &&
""
ne
$biz
_object_url &&
$biz
_object_id ne
$object
_id
}
{
set biz_object_name_link
"<a href='
$biz
_object_url
$biz
_object_id'>
$biz
_object_name</a>"
set parent_html
"
[
lang::message::lookup
""
intranet-search-pg.Parent
"Parent"
]
:
$biz
_object_type_pretty_name:
$biz
_object_name_link<br>"
}
}
append result_html
"
default
{
set parent_html
""
if
{
""
ne
$biz
_object_id &&
""
ne
$biz
_object_url &&
$biz
_object_id ne
$object
_id
}
{
set biz_object_name_link
"<a href='
$biz
_object_url
$biz
_object_id'>
$biz
_object_name</a>"
set parent_html
"
[
lang::message::lookup
""
intranet-search-pg.Parent
"Parent"
]
:
$biz
_object_type_pretty_name:
$biz
_object_name_link<br>"
}
append result_html
"
<tr>
<tr>
<td>
<td>
$object
_type_pretty_name:
$name
_link<br>
$object
_type_pretty_name:
$name
_link<br>
...
@@ -834,8 +849,15 @@ db_foreach full_text_query $sql {
...
@@ -834,8 +849,15 @@ db_foreach full_text_query $sql {
</td>
</td>
</tr>
</tr>
"
"
}
}
}
}
}
}
errmsg]
}
{
# Explain the user how to improve the search...
ad_return_complaint 1
$error
_message
ad_script_abort
}
}
...
...
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