lucene compass

PaodingAnalyzer analyzer = new PaodingAnalyzer();
		String field = "contents";
		QueryParser parser = new QueryParser(field, analyzer);
		Query query2 = parser.parse(queryStr);

		System.out.println("dddddddddddddddddddddd:" + query2);

		String str = query2.toString();
		if (!str.substring(10, str.length() - 1).contains("contents")) {
			if (str.indexOf("\"") > 0) {
				str = str.substring(10, str.length() - 1);

				parser = new QueryParser(field, analyzer);
				query2 = parser.parse(str);
			}
		}
		BooleanQuery query = new BooleanQuery();
		// query.add(query1, Occur.MUST);
		query.add(query2, Occur.MUST);
Compass compass = compassTemplate.getCompass();
		CompassSession session = compass.openSession();

		PaodingAnalyzer analyzer = new PaodingAnalyzer();
		String field = "articleContent";
		QueryParser parser = new QueryParser(field, analyzer);
		Query query2 = parser.parse(keywords);


		String str = query2.toString();
		if (!str.substring(16, str.length() - 1).contains("articleContent")) {
			if (str.indexOf("\"") > 0) {
				str = str.substring(16, str.length() - 1);

				parser = new QueryParser(field, analyzer);
				query2 = parser.parse(str);
			}
		}

		System.out.println("dddddddddddddddddddddd:" + query2.toString());

		CompassQuery compassQuery = session.queryBuilder()
				.queryString(query2.toString()).toQuery();
		CompassHits hits = compassQuery.hits();

相关推荐