You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@nutch.apache.org by Hal Finkel <ha...@halssoftware.com> on 2007/07/21 19:30:57 UTC

web2 spellcheck problem

Hello,

I have come across an odd problem with the web2 spellcheck plugin. When
there is a spelling suggestion, the value of the "query" parameter in
the form which provides the next button is not set to the original query
but rather the query suggested by the spellcheck plugin.

I have enabled the plugin on a website I'm setting up:
http://utilitysearch.info, so you can observe the behavior yourself. I
am using a trunk checkout from 2007-06-27.

As a quick thought, it seems that even though the spell check controller
is cloning the form object, the original object is still being contaminated:
SearchForm form=(SearchForm)serviceLocator.getSearchForm().clone();

If anyone has any ideas as to what could be causing this problem, I
would appreciate some assistance.

Thank you,
Hal

Re: web2 spellcheck problem - patch

Posted by Dmitry <dm...@hotmail.com>.
Hal,
thanks , its good point, because i did not understand before the strange 
behavier (updated the SearchForm.clone())

thanks,
DT
www.ejinz.com
----- Original Message ----- 
From: "Hal Finkel" <ha...@halssoftware.com>
To: <nu...@lucene.apache.org>
Sent: Saturday, July 21, 2007 6:36 PM
Subject: Re: web2 spellcheck problem - patch


> Hello again,
>
> I finally figured out what the problem is (SearchForm.clone() needs to
> deep copy the KeyValue objects), and so I have attached a patch. The
> patch also fixes a problem with the setValue() method which leads to an
> incorrect proposal URL being generated.
>
> -Hal
>
> Hal Finkel wrote:
>> Hello,
>>
>> I have come across an odd problem with the web2 spellcheck plugin. When
>> there is a spelling suggestion, the value of the "query" parameter in
>> the form which provides the next button is not set to the original query
>> but rather the query suggested by the spellcheck plugin.
>>
>> I have enabled the plugin on a website I'm setting up:
>> http://utilitysearch.info, so you can observe the behavior yourself. I
>> am using a trunk checkout from 2007-06-27.
>>
>> As a quick thought, it seems that even though the spell check controller
>> is cloning the form object, the original object is still being 
>> contaminated:
>> SearchForm form=(SearchForm)serviceLocator.getSearchForm().clone();
>>
>> If anyone has any ideas as to what could be causing this problem, I
>> would appreciate some assistance.
>>
>> Thank you,
>> Hal
>>
>
>


--------------------------------------------------------------------------------


> ---  
> contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchForm.java.orig 
> 2007-06-27 11:17:34.000000000 -0700
> +++ 
> contrib/web2/src/main/java/org/apache/nutch/webapp/common/SearchForm.java 
> 2007-07-21 16:20:14.000000000 -0700
> @@ -126,6 +126,13 @@
>     public String toString() {
>       return value.toString();
>     }
> +
> +    public boolean equals(Object other) {
> +      if (this == other) return true;
> +      if (!(other instanceof KeyValue)) return false;
> +      KeyValue okv = (KeyValue) other;
> +      return this.key.equals(okv.key) && this.value.equals(okv.value);
> +    }
>   }
>
>   /**
> @@ -149,6 +156,9 @@
>    */
>   public void setValue(String key, String value) {
>     if (n_values.containsKey(key)) {
> +      if(active.contains(n_values.get(key)))
> +        active.remove(active.indexOf(n_values.get(key)));
> +
>       ((KeyValue) n_values.get(key)).setValue(value);
>     } else {
>       n_values.put(key, new KeyValue(key, value));
> @@ -303,9 +313,21 @@
>
>   public Object clone(){
>     SearchForm newForm=new SearchForm(new HashMap());
> -    newForm.active.addAll(active);
>     newForm.o_values.putAll(o_values);
> -    newForm.n_values.putAll(n_values);
> +
> +    // make sure we have a deep copy of all KeyValue objects which can be 
> modified
> +    Iterator j = n_values.entrySet().iterator();
> +    while (j.hasNext()) {
> +      KeyValue kv = (KeyValue) ((Map.Entry) j.next()).getValue();
> +      newForm.n_values.put(kv.getKey(), new KeyValue(kv.getKey(), 
> kv.getValue()));
> +    }
> +
> +    Iterator i = active.iterator();
> +    while (i.hasNext()) {
> +      KeyValue kv = (KeyValue) i.next();
> +      newForm.active.add(new KeyValue(kv.getKey(), kv.getValue()));
> +    }
> +
>     return newForm;
>   }
>
> 


Re: web2 spellcheck problem - patch

Posted by Hal Finkel <ha...@halssoftware.com>.
Hello again,

I finally figured out what the problem is (SearchForm.clone() needs to
deep copy the KeyValue objects), and so I have attached a patch. The
patch also fixes a problem with the setValue() method which leads to an
incorrect proposal URL being generated.

 -Hal

Hal Finkel wrote:
> Hello,
>
> I have come across an odd problem with the web2 spellcheck plugin. When
> there is a spelling suggestion, the value of the "query" parameter in
> the form which provides the next button is not set to the original query
> but rather the query suggested by the spellcheck plugin.
>
> I have enabled the plugin on a website I'm setting up:
> http://utilitysearch.info, so you can observe the behavior yourself. I
> am using a trunk checkout from 2007-06-27.
>
> As a quick thought, it seems that even though the spell check controller
> is cloning the form object, the original object is still being contaminated:
> SearchForm form=(SearchForm)serviceLocator.getSearchForm().clone();
>
> If anyone has any ideas as to what could be causing this problem, I
> would appreciate some assistance.
>
> Thank you,
> Hal
>