当前位置: 编程技术>移动开发
本页文章导读:
▪lucene 排序,过滤,高亮展示 lucene 排序,过滤,高亮显示
package com.nanjing.chaoxing.lucene;
import com.nanjing.chaoxing.lucene.model.Book;
import com.nanjing.chaoxing.lucene.model.BookUtil;
import org.apache.log4j.Logger;
import org.apache.lucene.analysis.standard.Sta.........
▪ IdentifyTask-因素识别 -长按某一点后查询,并将查询结果高亮显示 IdentifyTask--要素识别 ----长按某一点后查询,并将查询结果高亮显示
public class HighlightFeatures extends Activity {
private MapView mapView;
private ArcGISTiledMapServiceLayer tiledMapServiceLayer;
private GraphicsLayer g.........
▪ alertdialog 应用系统选择时改变 默认字体大小 alertdialog 使用系统选择时改变 默认字体大小
ContextThemeWrapper ctw = new ContextThemeWrapper( getActivity(), R.style.AlertDialogCustom );
Builder builder = new AlertDialog.Builder(btw);
<style name="AlertDialogCustom" parent=.........
[1]lucene 排序,过滤,高亮展示
来源: 互联网 发布时间: 2014-02-18
lucene 排序,过滤,高亮显示
package com.nanjing.chaoxing.lucene; import com.nanjing.chaoxing.lucene.model.Book; import com.nanjing.chaoxing.lucene.model.BookUtil; import org.apache.log4j.Logger; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.document.Document; import org.apache.lucene.index.IndexReader; import org.apache.lucene.queryParser.ParseException; import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.search.*; import org.apache.lucene.search.highlight.*; import org.apache.lucene.search.highlight.Scorer; import org.apache.lucene.store.FSDirectory; import org.apache.lucene.util.Version; import org.junit.BeforeClass; import org.junit.Test; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class SortAndFilterAndHighligher { private Logger logger = Logger.getLogger(SortAndFilterAndHighligher.class); @BeforeClass public static void init() throws IOException { BookUtil bookUtil = new BookUtil(); bookUtil.createIndexWriter(); bookUtil.createDocument(); } /** * 排序并过滤 * @throws IOException * @throws ParseException */ @Test public void sort() throws IOException, ParseException { IndexReader indexReader = IndexReader.open(FSDirectory.open(BookUtil.indexFile)); Query query = new QueryParser(Version.LUCENE_36, "bookid", new StandardAnalyzer(Version.LUCENE_36)).parse("6270000~"); IndexSearcher indexSearcher = new IndexSearcher(indexReader); //数字过滤器 NumericRangeFilter numericRangeFilter = NumericRangeFilter.newIntRange("year", 2010, 2012, true, true); //排序 SortField sortField = new SortField("bookid", SortField.STRING); logger.info("sort" + " begin...."); TopDocs topDocs = indexSearcher.search(query, numericRangeFilter, 1000, new Sort(sortField)); ScoreDoc[] scoreDocs = topDocs.scoreDocs; for (int i = 0; i < scoreDocs.length; i++) { ScoreDoc scoreDoc = scoreDocs[i]; int doc = scoreDoc.doc; for (Book book : BookUtil.bookList) { if (indexSearcher.doc(doc).get("bookid").equals(book.getBookid())) { logger.info(book.toString()); } } } logger.info("sort" + " end....\n"); } /** * 高亮显示 * * @throws ParseException * @throws IOException */ // @Test public void highligher() throws ParseException, IOException, InvalidTokenOffsetsException { List<Book> books = new ArrayList<Book>(); IndexReader indexReader = IndexReader.open(FSDirectory.open(BookUtil.indexFile)); Query query = new QueryParser(Version.LUCENE_36, "author", new StandardAnalyzer(Version.LUCENE_36)).parse("jam~"); IndexSearcher indexSearcher = new IndexSearcher(indexReader); SimpleHTMLFormatter simpleHTMLFormatter = new SimpleHTMLFormatter("<font color='red'>", "</font>"); Scorer scorer = new QueryScorer(query); Highlighter highlighter = new Highlighter(simpleHTMLFormatter, scorer); Fragmenter fragmenter = new SimpleFragmenter(100); highlighter.setTextFragmenter(fragmenter); TopDocs topDocs = indexSearcher.search(query, 1000); ScoreDoc[] scoreDocs = topDocs.scoreDocs; System.out.println("高亮显示:"); for (int i = 0; i < scoreDocs.length; i++) { int docid = scoreDocs[i].doc; float score = scoreDocs[i].score;//当前结果的相关度得分 System.out.println("score is : " + score); Document doc = indexSearcher.doc(docid); String author = doc.get("author"); String highterBooid = highlighter.getBestFragment(new StandardAnalyzer(Version.LUCENE_36), "author", author); for (Book book : BookUtil.bookList) { if (book.getBookid().equals(doc.get("bookid"))) { book.setAuthor(highterBooid); System.out.println(book.toString()); } } } } }
[2] IdentifyTask-因素识别 -长按某一点后查询,并将查询结果高亮显示
来源: 互联网 发布时间: 2014-02-18
IdentifyTask--要素识别 ----长按某一点后查询,并将查询结果高亮显示
public class HighlightFeatures extends Activity { private MapView mapView; private ArcGISTiledMapServiceLayer tiledMapServiceLayer; private GraphicsLayer graphicsLayer; private Graphic[] highlightGraphics; private String mapURL = "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/PublicSafety/PublicSafetyBasemap/MapServer"; @SuppressWarnings("serial") public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mapView = (MapView) findViewById(R.id.map); mapView.setOnLongPressListener(new OnLongPressListener() { public void onLongPress(float x, float y) { identifyPoint(x, y); } }); tiledMapServiceLayer = new ArcGISTiledMapServiceLayer(mapURL); graphicsLayer = new GraphicsLayer(); mapView.addLayer(tiledMapServiceLayer); mapView.addLayer(graphicsLayer); } // 要素识别长按点 protected void identifyPoint(float x, float y) { try { graphicsLayer.removeAll(); Point pointClicked = mapView.toMapPoint(x, y); IdentifyParameters params = new IdentifyParameters(); params.setGeometry(pointClicked); params.setLayers(new int[] { 28 }); Envelope env = new Envelope(); mapView.getExtent().queryEnvelope(env); params.setSpatialReference(mapView.getSpatialReference()); params.setMapExtent(env); params.setDPI(96); params.setMapHeight(mapView.getHeight()); params.setMapWidth(mapView.getWidth()); params.setTolerance(10); // 执行查询任务 MyIdentifyTask mIdenitfy = new MyIdentifyTask(); mIdenitfy.execute(params); } catch (Exception ex) { ex.printStackTrace(); } } @Override protected void onPause() { super.onPause(); mapView.pause(); } @Override protected void onResume() { super.onResume(); mapView.unpause(); } private class MyIdentifyTask extends AsyncTask<IdentifyParameters, Void, IdentifyResult[]> { IdentifyTask mIdentifyTask; @Override protected IdentifyResult[] doInBackground(IdentifyParameters... params) { IdentifyResult[] mResult = null; if (params != null && params.length > 0) { IdentifyParameters mParams = params[0]; try { mResult = mIdentifyTask.execute(mParams); } catch (Exception e) { e.printStackTrace(); } } return mResult; } @Override protected void onPostExecute(IdentifyResult[] results) { if (results != null && results.length > 0) { highlightGraphics = new Graphic[results.length]; for (int i = 0; i < results.length; i++) { Geometry geom = results[i].getGeometry();// 得到几何对象 String typeName = geom.getType().name();// 图层类型 lightShow(i, typeName, geom);// 高亮显示 IdentifyResult result = results[i]; Log.i("andli", "图层名称---" + result.getLayerName()); Log.i("andli", "图层id ---" + result.getLayerId()); Log.i("andli", "图层类型---" + typeName); } } else { Toast.makeText(HighlightFeatures.this, "查询结果为空", 3000).show(); } } @Override protected void onPreExecute() { mIdentifyTask = new IdentifyTask(mapURL); } } public void lightShow(int i, String typeName, Geometry geom) { // 高亮显示查询结果 Random r = new Random(); int color = Color.rgb(r.nextInt(255), r.nextInt(255), r.nextInt(255));// 生成随机色 if (typeName.equalsIgnoreCase("point")) { SimpleMarkerSymbol sms = new SimpleMarkerSymbol(color, 20, STYLE.SQUARE); highlightGraphics[i] = new Graphic(geom, sms); } else if (typeName.equalsIgnoreCase("polyline")) { SimpleLineSymbol sls = new SimpleLineSymbol(color, 5); highlightGraphics[i] = new Graphic(geom, sls); } else if (typeName.equalsIgnoreCase("polygon")) { SimpleFillSymbol sfs = new SimpleFillSymbol(color); sfs.setAlpha(75); highlightGraphics[i] = new Graphic(geom, sfs); } graphicsLayer.addGraphic(highlightGraphics[i]); } }
[3] alertdialog 应用系统选择时改变 默认字体大小
来源: 互联网 发布时间: 2014-02-18
alertdialog 使用系统选择时改变 默认字体大小
ContextThemeWrapper ctw = new ContextThemeWrapper( getActivity(), R.style.AlertDialogCustom ); Builder builder = new AlertDialog.Builder(btw); <style name="AlertDialogCustom" parent="@android:style/Theme.Dialog"> <item name="android:textSize">15sp</item> </style>
最新技术文章: