lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Matthew Hall <mh...@informatics.jax.org>
Subject Re: Discard search results based on a doc field comparison
Date Wed, 13 May 2009 12:54:47 GMT
Well, perhaps this is a bit.. simplistic.. but couldn't you simply 
automatically add a clause to your queries based on the detected 
language of the session?

Basically you could make three ready to go BooleanQueries where you have 
something like this (psuedocode)

enClause ="language: en"
frClause = "language: fr"
nlClause = "language: nl"

And then at search time simply convert the user query to a boolean 
query, and add in your new clause, and then pass this modified query to 
the actual search?

-Matt

walki2 wrote:
> Hi,
>
> I have a website in 3 languages. The language management is done with Apache
> Struts MessageResources, so all the text is stored within .properties files.
> These .properties files are indexed and for each doc there is a field called
> language which is set to either en,fr or nl. At the moment if a user starts
> a search, results for all 3 languages are returned.
>
> Based on the session I can retrieve the users current language. I would like
> to discard all search results (docs) which do not match the user's language.
>
> For now, my code looks like this:
>
>
> 	public void search(String keywords) {
> 		
> 		// parse the keywords string 
> 		Query query = null;
> 		try {
> 			query = searcher.getParser().parse(keywords);
> 		} catch (ParseException e) {
> 			// TODO Auto-generated catch block
> 			e.printStackTrace();
> 		}
> 		// allows to display the best results first
> 		collector = new TopDocCollector(hitsPerPage);
> 		// Perform the actual search
> 		try {
> 			searcher.getSearcher().search(query, collector);
> 		} catch (IOException e) {
> 			// TODO Auto-generated catch block
> 			e.printStackTrace();
> 		}
> 		// Save the search results to hits[]
> 		hits = collector.topDocs().scoreDocs;
> 		// Get the number of documents found
> 		numTotalHits = collector.getTotalHits();
> 	}
>
>
> searcher.getSearcher() returns an instance of my own Searcher class which
> contains a StandardAnalyzer, a MultiFieldQueryParser, an IndexReader and an
> IndexSearcher.
>
> Thx,
> walki
>   



---------------------------------------------------------------------
To unsubscribe, e-mail: java-dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-dev-help@lucene.apache.org


Mime
View raw message