-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 20 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: [Hibernate Search] Where the query matches
PostPosted: Wed Jul 18, 2007 11:46 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Hello,

When I make a query, is it possible to know where field matches ?

For example, I make a search : "field1:house AND field2:house" and I have one result. Could I know if field1 contains "house" or field 2 ?

Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 18, 2007 1:32 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I am not aware of a way to do it.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 18, 2007 1:41 pm 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Hum thank you Emmanuel... and maybe in a future release ?

(Because it's very importante when we did a search to know where the result is ...)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 18, 2007 1:49 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Now that I think about it, I guess you could look at Highlights, but I've never used them.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 3:55 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Yeah ! Very interesting to get a small extract (this is the same in Google).

I founded that :

Code:
IndexSearcher searcher = new IndexSearcher("ramDir");
Hits hits = searcher.search(luceneQuery);
Highlighter highlighter = new Highlighter(this, new QueryScorer(query));
for (int i = 0; i < hits.length(); i++)
{
  String text = hits.doc(i).get("field_name");
  TokenStream tokenStream = analyzer.tokenStream("field_name", new StringReader(text));
  // Get 3 best fragments and seperate with a "..."
  String result = highlighter.getBestFragments(tokenStream, text, 3, "...");
  System.out.println(result);
}


But in Hibernate Search, I have "Hit" but "Highlighter" and "QueryScorer" missed because the package "org.apache.lucene.search.highlight" missed.

Could I add it myself ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 9:39 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
We could think about a nice integration. Do you want to give it a try?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 11:00 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
I don't understand (I'm french), what do you want I try ?
To find the org.apache.lucene.search.highlight Lucene files and try to use Highlighter with Hibernate Search ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 2:07 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
To propose a patch to have access to the Highlights feature from within Hibernate Search from a fullTextQuery

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 3:55 pm 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Hum, I'm in IT training period, I don't know if I have the required skills and enough time.

Is it complicated ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 19, 2007 5:13 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Dunno, as I told you I haven't looked at Highlights in Lucene yet :)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 20, 2007 4:15 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
I made several tests.

I added to my project Lucene class files and org.apache.lucene.search.highlight contribution.

Then I added to a classic HSearch search :

Code:
      try {
         IndexSearcher searcher = new IndexSearcher("/home/fmn/templucene/dao.modele.Entite");
         Hits hits = searcher.search(luceneQuery);
         Highlighter highlighter = new Highlighter(new SimpleHTMLFormatter("<b>","</b>") , new QueryScorer(luceneQuery));

         String fieldName = "documents.pleinTexte";
         for (int i = 0; i < hits.length(); i++) // for each document
         {
                 String fieldText = hits.doc(i).get(fieldName);

                 TokenStream tokenStream = (new StandardAnalyzer()).tokenStream(fieldName, new StringReader(fieldText));
                 // Get 3 best fragments and seperate with a "..."
                 String[] results = highlighter.getBestFragments(tokenStream, fieldText, 3);
                
                 System.out.println("Result fragments :\n");
                 for(String result : results)
                    System.out.println("... "+result+" ...");
         }
      } catch (IOException e) {
         // TODO
         e.printStackTrace();
      }


The result is for example :
Code:
...  grande   première   formation   Turquie   première   proposition   <b>et</b>   première   victoire   en   grand   prix   le   départ   <b>et</b>   mouvementée   à   la   tête   a   été   pour   physique   <b>et</b>   la ...
...  victime   d'   une   crevaison   sain   <b>et</b>   puis   aussi   mais   dans   le   tour   suivant  ...


Here I want 3 index segments (max) found and I want the matched word in bold. It works very well but I think I made a search again when I use
Code:
Hits hits = searcher.search(luceneQuery);

equivalent to
Code:
luceneQuery = parser.parse(requeteLucene);


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 24, 2007 7:19 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Could we insert it in HSearch ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 27, 2007 4:42 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
Am I able to do that easily ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 27, 2007 5:37 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I don't see a reason to add your code snippet anywhere in Hibernate Search. In fact, I don't see why we would move the perfectly working Lucene Highlighter API into a Hibernate Search API.

I'm using FullTextQuery of Hibernate Search and the Highlighter on the query result without any problem or desire to simplify it.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 27, 2007 7:11 am 
Regular
Regular

Joined: Wed Apr 25, 2007 10:29 am
Posts: 110
Location: France
In my example, I made a second query (not Hibernate Search Query) here :

Code:
   IndexSearcher[] searchers = new IndexSearcher[2];
   searchers[0] = new IndexSearcher("indexdir1");
   searchers[1] = new IndexSearcher("indexdir2");
   MultiSearcher searcher = new MultiSearcher(searchers);

   Hits hits = searcher.search(luceneQuery);


Is there a solution to avoid this ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 20 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.