`
m2000hsf
  • 浏览: 99336 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

cannot make any changes to the index (it was opened with readOnly = true)

 
阅读更多
   在调用IndexReader.open(final Directory directory)时候,在lucene3.0以上的版本中新增加属性中的readOnly默认为true(readOnly true if no changes (deletions, norms) will be made with this IndexReader),导致在删除索引的时候抛出UnsupportedOperationException。
解决方法为:
1、IndexReader源码中添加方法:
public static IndexReader open(final String path, Boolean readOnly) throws
 CorruptIndexException, IOException {
	    return open(FSDirectory.open(new File(path)), null, null, 
readOnly, DEFAULT_TERMS_INDEX_DIVISOR);
	  }

2、应用代码中传递一参数:
IndexReader indexReader = IndexReader.open(indexDir,false);


源码解释如下:
/** Expert: returns an IndexReader reading the index in
   *  the given Directory, using a specific commit and with
   *  a custom {@link IndexDeletionPolicy}.  You should pass
   *  readOnly=true, since it gives much better concurrent
   *  performance, unless you intend to do write operations
   *  (delete documents or change norms) with the reader.
   * @param commit the specific {@link IndexCommit} to open;
   * see {@link IndexReader#listCommits} to list all commits
   * in a directory
   * @param deletionPolicy a custom deletion policy (only used
   *  if you use this reader to perform deletes or to set
   *  norms); see {@link IndexWriter} for details.
   * @param readOnly true if no changes (deletions, norms) will be made with this IndexReader
   * @param termInfosIndexDivisor Subsamples which indexed
   *  terms are loaded into RAM. This has the same effect as {@link
   *  IndexWriter#setTermIndexInterval} except that setting
   *  must be done at indexing time while this setting can be
   *  set per reader.  When set to N, then one in every
   *  N*termIndexInterval terms in the index is loaded into
   *  memory.  By setting this to a value > 1 you can reduce
   *  memory usage, at the expense of higher latency when
   *  loading a TermInfo.  The default value is 1.  Set this
   *  to -1 to skip loading the terms index entirely. This is only useful in 
   *  advanced situations when you will only .next() through all terms; 
   *  attempts to seek will hit an exception.
   *  
   * @throws CorruptIndexException if the index is corrupt
   * @throws IOException if there is a low-level IO error
   */
  public static IndexReader open(final IndexCommit commit, IndexDeletionPolicy deletionPolicy, boolean readOnly, int termInfosIndexDivisor) throws CorruptIndexException, IOException {
    return open(commit.getDirectory(), deletionPolicy, commit, readOnly, termInfosIndexDivisor);
  }
0
5
分享到:
评论

相关推荐

    .NET中TextBox控件设置ReadOnly=true后台取不到值三种解决方法

    当TextBox设置了ReadOnly=”true” 后,要是在前台为控件添加了值,后台是取不到的,值为“空” 原理没想通,说不清楚微软是出于什么考虑的,不过有时是要我们能通过前台脚本来填充值,并不希望用户修改其控件内容,...

    VclZip pro v3.10.1

    This was due to a problem where it would be freed automatically if there was a problem with the ArchiveStream when trying to open it as a zip file (possibly corrupt). Best practice is that ...

    asp.net TextBox控件设置ReadOnly后,不能回传。

    很奇怪,以前都没有过这样的怪问题,在别人机器上都能正常,想到可能和ASP.NET的版本... 解决的方法: <asp id=”Username” runat=”server” ReadOnly=”True”></asp> 去掉ReadOnly=”True”,改成 <asp:textbox

    个人通讯录管理系统 vfp

    thisform.txt邮政编码.readonly=.f. thisform.txt性别.readonly=.f. thisform.txt手机.readonly=.f. thisform.txt小灵通.readonly=.f. thisform.txt住宅电话.readonly=.f. thisform.txtqq.readonly=.f. thisform....

    DataGridView使用整理

    `DataGridView1.Columns(1).ReadOnly = True` `DataGridView1.Rows(2).ReadOnly = True` `DataGridView1(0, 0).ReadOnly = True` 在 C# 中,我们可以使用以下代码: `DataGridView1.Columns[1].ReadOnly = true;` ...

    FlexGraphics_V_1.79_D4-XE10.2_Downloadly.ir

    Added TFlexFileFormat.StreamSupport property (default True), which difines, is it necessary to open file stream or give the file name only. - FIX: If the TCustomProp.Assign method calls when the ...

    vb.net & C#.net DataGridView使用说明

    DataGridView1.Columns(1).ReadOnly = True DataGridView1.Rows(2).ReadOnly = True DataGridView1(0, 0).ReadOnly = True ``` ```csharp DataGridView1.Columns[1].ReadOnly = true; DataGridView1.Rows[2]....

    QTP处理readonly控件

    ### QTP处理readonly控件 在自动化测试领域中,QTP(Quick Test Professional)是一款非常受欢迎的工具,它主要用于功能测试、回归测试等自动化测试任务。对于某些特定类型的控件,如只读(readonly)控件,QTP提供...

    图书管理系统 vfp

    thisform.txt邮政编码.readonly=.f. thisform.txt性别.readonly=.f. thisform.txt手机.readonly=.f. thisform.txt小灵通.readonly=.f. thisform.txt住宅电话.readonly=.f. thisform.txtqq.readonly=.f. thisform....

    基于jQuery的轻便版日期控件[可精确到分钟]

    input type=text maxlength="10" onfocus="jQuery(this).calendar()" readonly="true"/><br/> 显示日期时间: <input type=text maxlength="16" onfocus="jQuery(this).calendar()" readonly="true"/&gt...

    2009 达内Unix学习笔记

    集合了 所有的 Unix命令大全 ...telnet 192.168.0.23 自己帐号 sd08077-you0 ftp工具 192.168.0.202 tools-toolss ... 各个 shell 可互相切换 ksh:$ sh:$ csh:guangzhou% bash:bash-3.00$ ... 命令和参数之间必需用空格隔...

    Vue隐藏显示、只读实例代码

    <input type="text" class="form-control" v-bind:readonly="isReadOnly" validate="notNull,realname" v-model="user.realname"/> ``` 这里,v-bind:readonly="isReadOnly"会根据isReadOnly的值来决定input元素...

    JS中如何设置readOnly的值

    在网页中我们有时候需要控制文本输入框的...但是在JS中我们则不能食用txt_name.readonly=”readonly”来设置该属性,由于JS是区分大小写的,所以,在调用该属性的时候,我们必须使用txt_name.readOnly=true来设置。 当

    C#datagridview用法

    * Columns[ColumnIndex].ReadOnly:设置指定列是否可编辑。 * Rows[RowIndex].ReadOnly:设置指定行是否可编辑。 * [Row, Column].ReadOnly:设置指定单元格是否可编辑。 例如: dataGridView1.ReadOnly = true; /...

    凭证管理系统(凭证管理系统)

    凭证管理系统 ... ReadOnly = True TabOrder = 1 TitleFont.Charset = DEFAULT_CHARSET TitleFont.Color = clBlue TitleFont.Height = -11 TitleFont.Name = 'MS Sans Serif' TitleFont.Style = []

    The MySQL server is running with the --read-only option so it cannot execute this statement

    MySQL服务器在运行时可能由于配置了`--read-only`选项,导致无法执行写入操作,从而出现"1209 - The MySQL server is running with the --read-only option so it cannot execute this statement"的错误。...

    DataGridView行列操作

    DataGridView1.Columns[1].ReadOnly = true; // 设置第3行整行单元格为只读 DataGridView1.Rows[2].ReadOnly = true; // 设置[0, 0]单元格为只读 DataGridView1[0, 0].ReadOnly = true; ``` - 使用Edit...

    基于C#的WinForm中DataGridView控件操作汇总

    如果希望DataGridView控件内所有单元格都不可编辑,可以设置DataGridView1.ReadOnly = true;这样用户的新增行操作和删除行操作也将被屏蔽。 如果希望DataGridView控件内某个单元格不可编辑,可以使用Columns或Rows...

    基于C_的WinForm中DataGridView控件操作汇总.doc

    若要使整个`DataGridView`变为只读,可以设置`ReadOnly`属性为`true`,如:`DataGridView1.ReadOnly = true;`这不仅阻止用户编辑单元格,还会禁用添加和删除行的功能。 2. 部分单元格或列设置只读: 若要仅使特定...

Global site tag (gtag.js) - Google Analytics