[opencms-dev] Hide individual files from search results
Christoph Schönfeld
cschoenfeld at sylphen.com
Tue Dec 5 15:44:13 CET 2006
Hi Olli,
It is also possible to search for properties than just the category.
OpenCms stores the values of several standard properties in the search
index as part of the Lucene document for each resource. From the code in
A_CmsVfsDocument.newInstance() I can tell that those are the following:
- content (the file content)
- title
- keywords
- description
- meta (which consists of title, keyword and description)
- path
- document type (just identifies resources as being VFS documents)
- priority (affects the lucene search boost the maximal priority value
results in a boost of 2, the lowest will boost by 0.5)
(added attributes are:
- creation timestamp
- lastmodified timestamp)
I have studied the source code of CmsSearchIndex.search(). It extracts
restrictions on the lucene fields from the method parameter of type
CmsSearchParameters.
CmsSearchIndex.search() uses the Lucene class QueryParser to create a
query for each field restriction found in the CmsSearchParameter
instance. The queries are built from the CmsSearchParameter property
"query".
The query of the CmsSearchParameter is used in two different modes. If
the CmsSearchParameter does not contain field restrictions the
CmsSearchParameter.query is used a single time for the whole Lucene
query. The second mode (if there are field restrictions) parses the
query for each field in order to add a Lucene query for this field.
The query syntax accepted by QueryParser is defined in the Lucene API
documentation:
http://lucene.apache.org/java/docs/api/org/apache/lucene/queryParser/QueryParser.html.
More details and good examples are here:
http://lucene.apache.org/java/docs/queryparsersyntax.html
Set the Title of your file or any other of the indexed properties
mentioned above to "nosearch" and add the following to the
CmsSearchParameter.query: " NOT nosearch". You might need to enclose the
nosearch in quotes. I am not sure.
I have attached a test case which shows the exclusion behaviour in line
103. A strange thing is that it fails when any of the constants defined
at the top contain uppercase letters. I have not found out why.
Best regards,
Christoph
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LuceneIndexTest.java
Type: text/x-java
Size: 3628 bytes
Desc: not available
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20061205/6ee98cbc/attachment.java>
More information about the opencms-dev
mailing list