Detailed introduction to the Second Development of nutch1.2 (3) [Image and text] -- the second development of nutch1.2 (about interface modification)

Source: Internet
Author: User
Tags i18n

The author (the watcher ms) has read a lot of Chinese documents in the process of setting up and developing the nutch, but the content is not detailed and there are errors. Therefore, he recorded the personal practice process and corrected someArticleErrors: a detailed process shows a simple secondary development process, lowering the threshold for beginners. But it cannot be guaranteed that there are no errors at all. If you find any problems, you may want to correct them.

Directory:

1. detailed introduction to the Second Development of nutch1.2 (1) [Image and text] ------ setting up the cygwin environment on the Windows platform

2. detailed introduction to the Second Development of nutch1.2 (2) [Image and text] ------ setting up nutch1.2 on the Windows platform

3. detailed introduction to the Second Development of nutch1.2 (3) [Image and text] ------ Secondary Development of nutch1.2 (about interface modification)

4. detailed introduction to the Second Development of nutch1.2 (4) [Image and text] ------ Secondary Development of nutch1.2 (about Chinese Word Segmentation)

This article is from the "watcher ms" blog and will not be reposted!

I. Development Environment Introduction (taking my personal account as an example ):

Personal development end: Windows Server 2003 + cygwin + eclipse3.2

2. steps:

The original home page and results of nutch are also very ugly, so it is also very important to modify these two pages in the secondary development.

<1>. Modify the homepage

It is the original home page of nutch. Apart from the ugly page, you will find that there are many things you don't want. Below

Now we can modify the homepage.

(1) first, find the newly deployed nutch homepage (index. jsp) in Tomcat and view itsSource code.

<% @ Page
Session = "false"
Import = "Java. Io .*"
Import = "Java. util .*"
%> <%
String Language =
Resourcebundle. getbundle ("org. nutch. jsp. Search", request. getlocale ())
. Getlocale (). getlanguage ();
String requesturi = httputils. getrequesturl (request). tostring ();
String base = requesturi. substring (0, requesturi. lastindexof ('/'));
Response. sendredirect (Language + "/");
%>

After analysis, we found that the home page is just a single parameter transfer and jump, and it does not require so many languages for secondary development.

Therefore:

Step 1: Delete all language packs (including en, and ZH) in the root directory and delete index. jsp.

The second step is to create a new homepage, and I am index.html (this homepage can be designed by a uidesigner, which is a simple static page). The only special one is the place where the form is submitted, such as myCode:

<Form action = "./search. jsp" method = "get">
<Input type = "hidden" name = "page1" value = "1">
<Input type = "text" name = "query" class = "searchinputbot" id = "keyword" AutoComplete = "off" disableautocomplete maxlength = "100"/>
<Input type = "Submit" value = "Power search" class = "searchbutton"/>
</Form>

To put it bluntly, it means passing parameters and redirecting.

Is the modified homepage (some related information is erased in the figure, because my secondary development is not complete yet)

 

 

<2> modify the search result page

Like the modification on the home page, you should first design a static page, and then delete the original code at the corresponding position in the source code of search. jsp, and add your code. Because this page is written by yourself, some references provided by the original nutch can be avoided, such as <JSP: Include page = "include/style.html"/>, you should be familiar with page design in this area.

Is my modified page

 

 

<3>. Modify the display by PAGE

The most important modification on the results page is to display the pages on several pages, because the pages provided by nutch are neither beautiful nor satisfying the user experience. Therefore, we focus on modifying the page display function.

Find the paging code in the original code:

<%

If (hits. totalisexact () & End | (! Hits. totalisexact () & (hits. getlength ()> Start + hitsperpage ))){
%>
<Form name = "Next" Action = ".../search. jsp" method = "get">
<Input type = "hidden" name = "query" value = "<% = htmlquerystring %>">
<Input type = "hidden" name = "Lang" value = "<% = querylang %>">
<Input type = "hidden" name = "start" value = "<% = end %>">
<Input type = "hidden" name = "hitsperpage" value = "<% = hitsperpage %>">
<Input type = "hidden" name = "hitspersite" value = "<% = hitspersite %>">
<Input type = "hidden" name = "clustering" value = "<% = clustering %>">
<Input type = "Submit" value = "<i18n: Message key =" Next "/>">
<% IF (sort! = NULL) {%>
<Input type = "hidden" name = "sort" value = "<% = sort %>">
<Input type = "hidden" name = "reverse" value = "<% = reverse %>">
<% }%>
</Form>
<%
}

If ((! Hits. totalisexact () & (hits. getlength () <= start + hitsperpage ))){
%>
<Form name = "showallhits" Action = ".../search. jsp" method = "get">
<Input type = "hidden" name = "query" value = "<% = htmlquerystring %>">
<Input type = "hidden" name = "Lang" value = "<% = querylang %>">
<Input type = "hidden" name = "hitsperpage" value = "<% = hitsperpage %>">
<Input type = "hidden" name = "hitspersite" value = "0">
<Input type = "hidden" name = "clustering" value = "<% = clustering %>">
<Input type = "Submit" value = "<i18n: Message key =" showallhits "/>">
<% IF (sort! = NULL) {%>
<Input type = "hidden" name = "sort" value = "<% = sort %>">
<Input type = "hidden" name = "reverse" value = "<% = reverse %>">
<% }%>
</Form>
<%
}
%>

Modify it:

Note that the two <div> label styles in the following code are self-written and use CSS to control their styles.

<Div id = "pager">
<Div class = "PG">
<%
If (Start> = hitsperpage)
{
%>
<A class = "flag_pg" href = "/search. jsp? Query = <% = htmlquerystring %> & page1 = <% = page1-1 %> & lang = <% = querylang %> & START = <% = start-hitsperpage %> & hitsperpage = <% = hitsperpage %> & hitspersite = <% = hitspersite %> & clustering = <% = clustering %> "> </a>
<% }%>
<%
// Display page number button
Int startnum = 1;
String current_select = "";
Int select =-1;
// The front page number on the page. I set (yes) a total of 10 pages. When the page is 6th pages
// If the result is greater than or equal to 11 pages, 11 buttons are displayed each time. The current button is in the middle, that is, 6th buttons.
If (INT) (start/hitsperpage)> = 5)
Startnum = (INT) (start/hitsperpage)-4;
For (INT I = hitsperpage * (startnum-1), j = 0; I <= hits. gettotal () & J <= 10 ;)
{
If (hits. gettotal () % 10 = 0 & I = hits. gettotal () break; // processing when the search result is an integer
If (page1 = (I/hitsperpage + 1 ))
{
%>
<SPAN class = "current"> <% = page1 %> </span>
<%
}
Else
{
%>
<A class = "flag_pg" href = "/search. jsp? Query = <% = htmlquerystring %> & page1 = <% = I/hitsperpage + 1%> & lang = <% = querylang %> & START = <% = I %> & hitsperpage = <% = hitsperpage %> & hitspersite = <% = hitspersite %> & clustering = <% = clustering %> "><%= I/hitsperpage + 1%> </a>
<%
}
I = I + 10;
J ++;
}
%>
<%
If (hits. totalisexact () & End | (! Hits. totalisexact () & (hits. getlength ()> Start + hitsperpage ))){
%>
<A class = "flag_pg" href = "/search. jsp? Query = <% = htmlquerystring %> & page1 = <% = page1 + 1%> & lang = <% = querylang %> & START = <% = end %> & hitsperpage = <% = hitsperpage %> & hitspersite = <% = hitspersite %> & clustering = <% = clustering %> ">>></A>
<% }%>
</Div>

In addition, you need to add the following code in the variable declaration section of the search. JSP Source Code:

Int page1 = 0;
String s_page = request. getparameter ("page1 ");
If (s_page! = NULL)
{
Page1 = integer. parseint (s_page );
}

Note the following code in this modification code:

If (page1 = (I/hitsperpage + 1 ))
{
%>
<SPAN class = "current"> <% = page1 %> </span>

...

Page1 is a URL parameter, which indicates the current page number.

<SPAN class = "current"> <% = page1 %> </span> This code identifies the current page in the pagination icon.

Is my modified paging style:

 

 

<4>. Red highlighted keywords in the abstract

In the previous articles, the solution to this solution is to modify the source code and then compile and deploy the solution.

This makes me very confused. Why is it so complicated?

In this regard, my solution is to control the display style through CSS.

For example, I add the following code to the CSS file that controls the style of my results page:

. Highlight {

Color: # ff0000;

}

Save and refresh to see if it has changed to red.

<5>. for more information about the changes, click here. (Note: You can refer to some of the points you have not mentioned in this Article. For the suggestions you have mentioned, refer to this article, because the method I used is simpler and practical)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.