1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Manage indexing of Nit model for Nitdoc QuickSearch.
18 import static
::static_html
21 # Generate the index for then Nitdoc QuickSearch field.
23 # Create a JSON object containing links to:
28 # All entities are grouped by name to make the research easier.
30 # TODO Merge with model_index
33 # Build the nitdoc quick search index
34 fun create_index_file
(file
: String) do
35 var table
= new QuickSearchTable(self)
36 var tpl
= new Template
37 tpl
.add
"var nitdocQuickSearchRawList="
40 tpl
.write_to_file
(file
)
44 # The result map for QuickSearch.
45 private class QuickSearchTable
46 super HashMap[String, Array[QuickSearchResult]]
52 var filter
= doc
.filter
54 index_mentities model
.collect_mpackages
(filter
)
55 index_mentities model
.collect_mmodules
(filter
)
56 index_mentities model
.collect_mclasses
(filter
)
57 index_mentities model
.collect_mproperties
(filter
)
60 fun index_mentities
(mentities
: Collection[MEntity]) do
61 for mentity
in mentities
do index_mentity mentity
64 fun index_mentity
(mentity
: MEntity) do
65 var key
= mentity
.name
66 if not has_key
(key
) then
67 self[key
] = new Array[QuickSearchResult]
69 self[key
].add
new QuickSearchResult(mentity
.full_name
, mentity
.html_url
)
73 # A QuickSearch result.
74 private class QuickSearchResult
77 # The text of the link.
80 # The destination of the link.